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

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

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

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

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

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

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

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

sc_asn1_read_tag:
   63|   314k|{
   64|   314k|	const u8 *p = *buf;
   65|   314k|	size_t left = buflen, len;
   66|   314k|	unsigned int cla, tag, i;
   67|       |
   68|   314k|	*buf = NULL;
   69|       |
   70|   314k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (70:6): [True: 2.06k, False: 312k]
  |  Branch (70:19): [True: 0, False: 312k]
  |  Branch (70:25): [True: 0, False: 312k]
  ------------------
   71|  2.06k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  2.06k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   72|   312k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (72:6): [True: 2.10k, False: 310k]
  |  Branch (72:20): [True: 10.3k, False: 300k]
  ------------------
   73|       |		/* end of data reached */
   74|  12.4k|		*cla_out = SC_ASN1_TAG_UNIVERSAL;
  ------------------
  |  |  209|  12.4k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
   75|  12.4k|		*taglen = 0;
   76|  12.4k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  218|  12.4k|#define SC_ASN1_TAG_EOC			0
  ------------------
   77|  12.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  12.4k|#define SC_SUCCESS				0
  ------------------
   78|  12.4k|	}
   79|       |
   80|       |	/* parse tag byte(s)
   81|       |	 * Resulted tag is presented by integer that has not to be
   82|       |	 * confused with the 'tag number' part of ASN.1 tag.
   83|       |	 */
   84|   300k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  208|   300k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  214|   300k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   85|   300k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  215|   300k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   86|   300k|	p++;
   87|   300k|	left--;
   88|   300k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  215|   300k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (88:6): [True: 3.11k, False: 297k]
  ------------------
   89|       |		/* high tag number */
   90|  3.11k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  169|  3.11k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   91|       |		/* search the last tag octet */
   92|  4.63k|		do {
   93|  4.63k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (93:8): [True: 108, False: 4.52k]
  |  Branch (93:21): [True: 240, False: 4.28k]
  ------------------
   94|       |				/* either an invalid tag or it doesn't fit in
   95|       |				 * unsigned int */
   96|    348|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    348|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   97|  4.28k|			tag <<= 8;
   98|  4.28k|			tag |= *p;
   99|  4.28k|			p++;
  100|  4.28k|			left--;
  101|  4.28k|			n--;
  102|  4.28k|		} while (tag & 0x80);
  ------------------
  |  Branch (102:12): [True: 1.51k, False: 2.76k]
  ------------------
  103|  3.11k|	}
  104|       |
  105|       |	/* parse length byte(s) */
  106|   299k|	if (left == 0)
  ------------------
  |  Branch (106:6): [True: 1.69k, False: 298k]
  ------------------
  107|  1.69k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.69k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  108|   298k|	len = *p;
  109|   298k|	p++;
  110|   298k|	left--;
  111|   298k|	if (len & 0x80) {
  ------------------
  |  Branch (111:6): [True: 54.8k, False: 243k]
  ------------------
  112|  54.8k|		len &= 0x7f;
  113|  54.8k|		unsigned int a = 0;
  114|  54.8k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (114:7): [True: 12.1k, False: 42.6k]
  |  Branch (114:25): [True: 821, False: 41.8k]
  ------------------
  115|  12.9k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  12.9k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  116|  77.1k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (116:15): [True: 35.2k, False: 41.8k]
  ------------------
  117|  35.2k|			a <<= 8;
  118|  35.2k|			a |= *p;
  119|  35.2k|			p++;
  120|  35.2k|			left--;
  121|  35.2k|		}
  122|  41.8k|		len = a;
  123|  41.8k|	}
  124|       |
  125|   285k|	*cla_out = cla;
  126|   285k|	*tag_out = tag;
  127|   285k|	*taglen = len;
  128|   285k|	*buf = p;
  129|       |
  130|   285k|	if (len > left)
  ------------------
  |  Branch (130:6): [True: 25.5k, False: 259k]
  ------------------
  131|  25.5k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  25.5k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  132|       |
  133|   259k|	return SC_SUCCESS;
  ------------------
  |  |   28|   259k|#define SC_SUCCESS				0
  ------------------
  134|   285k|}
sc_format_asn1_entry:
  138|   286k|{
  139|   286k|	entry->parm = parm;
  140|   286k|	entry->arg  = arg;
  141|   286k|	if (set_present)
  ------------------
  |  Branch (141:6): [True: 50.1k, False: 236k]
  ------------------
  142|  50.1k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  171|  50.1k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  143|   286k|}
sc_copy_asn1_entry:
  147|   102k|{
  148|   394k|	while (src->name != NULL) {
  ------------------
  |  Branch (148:9): [True: 292k, False: 102k]
  ------------------
  149|   292k|		*dest = *src;
  150|   292k|		dest++;
  151|   292k|		src++;
  152|   292k|	}
  153|       |	dest->name = NULL;
  154|   102k|}
sc_asn1_find_tag:
  486|  57.8k|{
  487|  57.8k|	size_t left = buflen, taglen;
  488|  57.8k|	const u8 *p = buf;
  489|       |
  490|  57.8k|	*taglen_in = 0;
  491|   124k|	while (left >= 2) {
  ------------------
  |  Branch (491:9): [True: 116k, False: 8.63k]
  ------------------
  492|   116k|		unsigned int cla = 0, tag, mask = 0xff00;
  493|       |
  494|   116k|		buf = p;
  495|       |		/* read a tag */
  496|   116k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   232k|#define SC_SUCCESS				0
  ------------------
  |  Branch (496:7): [True: 12.5k, False: 103k]
  ------------------
  497|   103k|				|| p == NULL)
  ------------------
  |  Branch (497:8): [True: 8.09k, False: 95.4k]
  ------------------
  498|  20.6k|			return NULL;
  499|       |
  500|  95.4k|		left -= (p - buf);
  501|       |		/* we need to shift the class byte to the leftmost
  502|       |		 * byte of the tag */
  503|  97.4k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (503:10): [True: 1.91k, False: 95.4k]
  ------------------
  504|  1.91k|			cla  <<= 8;
  505|  1.91k|			mask <<= 8;
  506|  1.91k|		}
  507|       |		/* compare the read tag with the given tag */
  508|  95.4k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (508:7): [True: 28.6k, False: 66.8k]
  ------------------
  509|       |			/* we have a match => return length and value part */
  510|  28.6k|			if (taglen > left)
  ------------------
  |  Branch (510:8): [True: 0, False: 28.6k]
  ------------------
  511|      0|				return NULL;
  512|  28.6k|			*taglen_in = taglen;
  513|  28.6k|			return p;
  514|  28.6k|		}
  515|       |		/* otherwise continue reading tags */
  516|  66.8k|		left -= taglen;
  517|  66.8k|		p += taglen;
  518|  66.8k|	}
  519|  8.63k|	return NULL;
  520|  57.8k|}
sc_asn1_skip_tag:
  524|   125k|{
  525|   125k|	const u8 *p = *buf;
  526|   125k|	size_t len = *buflen, taglen;
  527|   125k|	unsigned int cla = 0, tag;
  528|       |
  529|   125k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   251k|#define SC_SUCCESS				0
  ------------------
  |  Branch (529:6): [True: 24.0k, False: 101k]
  ------------------
  530|   101k|			|| p == NULL)
  ------------------
  |  Branch (530:7): [True: 2.31k, False: 99.3k]
  ------------------
  531|  26.3k|		return NULL;
  532|  99.3k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (532:10): [True: 99.3k, False: 0]
  ------------------
  533|  74.5k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  209|  74.5k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (533:2): [True: 74.5k, False: 24.8k]
  ------------------
  534|  74.5k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  160|  74.5k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  161|  74.5k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (534:7): [True: 8.14k, False: 66.4k]
  ------------------
  535|  8.14k|			return NULL;
  536|  66.4k|		break;
  537|  66.4k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  210|  6.73k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (537:2): [True: 6.73k, False: 92.6k]
  ------------------
  538|  6.73k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  160|  6.73k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  162|  6.73k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (538:7): [True: 732, False: 6.00k]
  ------------------
  539|    732|			return NULL;
  540|  6.00k|		break;
  541|  16.6k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  211|  16.6k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (541:2): [True: 16.6k, False: 82.7k]
  ------------------
  542|  16.6k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  160|  16.6k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  163|  16.6k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (542:7): [True: 2.59k, False: 14.0k]
  ------------------
  543|  2.59k|			return NULL;
  544|  14.0k|		break;
  545|  14.0k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  212|  1.42k|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (545:2): [True: 1.42k, False: 97.9k]
  ------------------
  546|  1.42k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  160|  1.42k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  164|  1.42k|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (546:7): [True: 1.42k, False: 0]
  ------------------
  547|  1.42k|			return NULL;
  548|      0|		break;
  549|  99.3k|	}
  550|  86.4k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  214|  86.4k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (550:6): [True: 49.6k, False: 36.7k]
  ------------------
  551|  49.6k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  165|  49.6k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (551:7): [True: 3.96k, False: 45.7k]
  ------------------
  552|  3.96k|			return NULL;
  553|  49.6k|	} else
  554|  36.7k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  165|  36.7k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (554:7): [True: 2.16k, False: 34.6k]
  ------------------
  555|  2.16k|			return NULL;
  556|  80.3k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  168|  80.3k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (556:6): [True: 10.3k, False: 69.9k]
  ------------------
  557|  10.3k|		return NULL;
  558|  69.9k|	len -= (p - *buf);	/* header size */
  559|  69.9k|	if (taglen > len) {
  ------------------
  |  Branch (559:6): [True: 0, False: 69.9k]
  ------------------
  560|      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__
  |  |  ------------------
  ------------------
  561|      0|				taglen, len);
  562|      0|		return NULL;
  563|      0|	}
  564|  69.9k|	*buflen -= (p - *buf) + taglen;
  565|  69.9k|	*buf = p + taglen;	/* point to next tag */
  566|  69.9k|	*taglen_out = taglen;
  567|  69.9k|	return p;
  568|  69.9k|}
sc_asn1_verify_tag:
  572|  3.73k|{
  573|  3.73k|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  574|  3.73k|}
sc_asn1_decode_integer:
  733|  1.40k|{
  734|  1.40k|	int    a = 0, is_negative = 0;
  735|  1.40k|	size_t i = 0;
  736|       |
  737|  1.40k|	if (inlen == 0) {
  ------------------
  |  Branch (737:6): [True: 5, False: 1.39k]
  ------------------
  738|      5|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      5|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  739|      5|	}
  740|  1.39k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (740:6): [True: 20, False: 1.37k]
  ------------------
  741|     20|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     20|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  742|     20|	}
  743|  1.37k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (743:6): [True: 138, False: 1.24k]
  ------------------
  744|    138|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (744:7): [True: 0, False: 138]
  |  Branch (744:17): [True: 0, False: 0]
  |  Branch (744:30): [True: 0, False: 0]
  |  Branch (744:50): [True: 0, False: 0]
  ------------------
  745|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  746|      0|		}
  747|    138|		is_negative = 1;
  748|    138|		a |= 0xff^(*inbuf++);
  749|    138|		i = 1;
  750|  1.24k|	} else {
  751|  1.24k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (751:7): [True: 0, False: 1.24k]
  |  Branch (751:17): [True: 0, False: 0]
  |  Branch (751:30): [True: 0, False: 0]
  |  Branch (751:50): [True: 0, False: 0]
  ------------------
  752|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  753|      0|		}
  754|  1.24k|	}
  755|  3.08k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (755:9): [True: 1.70k, False: 1.37k]
  ------------------
  756|  1.70k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (756:7): [True: 0, False: 1.70k]
  |  Branch (756:29): [True: 0, False: 1.70k]
  ------------------
  757|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  758|      0|		}
  759|  1.70k|		a <<= 8;
  760|  1.70k|		if (is_negative) {
  ------------------
  |  Branch (760:7): [True: 146, False: 1.55k]
  ------------------
  761|    146|			a |= 0xff^(*inbuf++);
  762|  1.55k|		} else {
  763|  1.55k|			a |= *inbuf++;
  764|  1.55k|		}
  765|  1.70k|	}
  766|  1.37k|	if (is_negative) {
  ------------------
  |  Branch (766:6): [True: 138, False: 1.24k]
  ------------------
  767|       |		/* Calculate Two's complement from previously positive number */
  768|    138|		a = (-1 * a) - 1;
  769|    138|	}
  770|  1.37k|	*out = a;
  771|  1.37k|	return 0;
  772|  1.37k|}
sc_asn1_decode_object_id:
  833|  12.2k|{
  834|  12.2k|	int large_second_octet = 0;
  835|  12.2k|	unsigned int a = 0;
  836|  12.2k|	const u8 *p = inbuf;
  837|  12.2k|	int *octet;
  838|       |
  839|  12.2k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (839:6): [True: 1.13k, False: 11.1k]
  |  Branch (839:20): [True: 2, False: 11.1k]
  |  Branch (839:37): [True: 0, False: 11.1k]
  ------------------
  840|  1.13k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.13k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  841|       |
  842|  11.1k|	sc_init_oid(id);
  843|  11.1k|	octet = id->value;
  844|       |
  845|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  846|  11.1k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   69|  11.1k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 8.08k, False: 3.06k]
  |  |  ------------------
  ------------------
  847|  11.1k|	*octet++ = a;
  848|       |
  849|       |	/* The second octet fits here if the previous was 0 or 1 and second one is smaller than 40.
  850|       |	 * for the value 2 we can go up to 47. Otherwise the first bit needs to be set
  851|       |	 * and we continue reading further */
  852|  11.1k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (852:6): [True: 8.91k, False: 2.24k]
  ------------------
  853|  8.91k|		*octet++ = *p - (a * 40);
  854|  8.91k|		inlen--;
  855|  8.91k|	} else {
  856|  2.24k|		large_second_octet = 1;
  857|  2.24k|	}
  858|       |
  859|  53.0k|	while (inlen) {
  ------------------
  |  Branch (859:9): [True: 44.2k, False: 8.77k]
  ------------------
  860|  44.2k|		if (!large_second_octet)
  ------------------
  |  Branch (860:7): [True: 42.0k, False: 2.24k]
  ------------------
  861|  42.0k|			p++;
  862|       |		/* This signalizes empty most significant bits, which means
  863|       |		 * the unsigned integer encoding is not minimal */
  864|  44.2k|		if (*p == 0x80) {
  ------------------
  |  Branch (864:7): [True: 853, False: 43.4k]
  ------------------
  865|    853|			sc_init_oid(id);
  866|    853|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    853|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  867|    853|		}
  868|       |		/* Use unsigned type here so we can process the whole INT range.
  869|       |		 * Values can not be negative */
  870|  43.4k|		a = *p & 0x7F;
  871|  43.4k|		inlen--;
  872|  67.8k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (872:10): [True: 58.4k, False: 9.34k]
  |  Branch (872:19): [True: 24.6k, False: 33.7k]
  ------------------
  873|       |			/* Limit the OID values to int size and do not overflow */
  874|  24.6k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (874:8): [True: 279, False: 24.4k]
  ------------------
  875|    279|				sc_init_oid(id);
  876|    279|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    279|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  877|    279|			}
  878|  24.4k|			p++;
  879|  24.4k|			a <<= 7;
  880|  24.4k|			a |= *p & 0x7F;
  881|  24.4k|			inlen--;
  882|  24.4k|		}
  883|  43.1k|		if (*p & 0x80) {
  ------------------
  |  Branch (883:7): [True: 789, False: 42.3k]
  ------------------
  884|       |			/* We dropped out from previous cycle on the end of
  885|       |			 * data while still expecting continuation of value */
  886|    789|			sc_init_oid(id);
  887|    789|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    789|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  888|    789|		}
  889|  42.3k|		if (large_second_octet) {
  ------------------
  |  Branch (889:7): [True: 704, False: 41.6k]
  ------------------
  890|    704|			a -= (2 * 40);
  891|    704|		}
  892|  42.3k|		if (a > INT_MAX) {
  ------------------
  |  Branch (892:7): [True: 351, False: 42.0k]
  ------------------
  893|    351|			sc_init_oid(id);
  894|    351|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    351|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  895|    351|		}
  896|  42.0k|		*octet++ = a;
  897|  42.0k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  42.0k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (897:7): [True: 109, False: 41.8k]
  ------------------
  898|    109|			sc_init_oid(id);
  899|    109|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    109|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  900|    109|		}
  901|  41.8k|		large_second_octet = 0;
  902|  41.8k|	}
  903|       |
  904|  8.77k|	return 0;
  905|  11.1k|}
sc_asn1_encode_object_id:
  909|  5.50k|{
  910|  5.50k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  911|  5.50k|	int	i;
  912|       |
  913|  5.50k|	if (!buflen || !id)
  ------------------
  |  Branch (913:6): [True: 0, False: 5.50k]
  |  Branch (913:17): [True: 0, False: 5.50k]
  ------------------
  914|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  915|       |
  916|       |	/* an OID must have at least two components */
  917|  5.50k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (917:6): [True: 0, False: 5.50k]
  |  Branch (917:28): [True: 0, False: 5.50k]
  ------------------
  918|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  919|       |
  920|  40.3k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|  40.3k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (920:14): [True: 40.3k, False: 0]
  ------------------
  921|  40.3k|		unsigned int k, shift;
  922|       |
  923|  40.3k|		if (id->value[i] == -1)
  ------------------
  |  Branch (923:7): [True: 5.50k, False: 34.8k]
  ------------------
  924|  5.50k|			break;
  925|       |
  926|  34.8k|		k = id->value[i];
  927|  34.8k|		switch (i) {
  928|  5.50k|		case 0:
  ------------------
  |  Branch (928:3): [True: 5.50k, False: 29.3k]
  ------------------
  929|  5.50k|			if (k > 2)
  ------------------
  |  Branch (929:8): [True: 0, False: 5.50k]
  ------------------
  930|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  931|  5.50k|			*p = k * 40;
  932|  5.50k|			break;
  933|  5.50k|		case 1:
  ------------------
  |  Branch (933:3): [True: 5.50k, False: 29.3k]
  ------------------
  934|  5.50k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (934:8): [True: 0, False: 5.50k]
  |  Branch (934:18): [True: 0, False: 0]
  ------------------
  935|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  936|      0|			}
  937|       |			/* We can encode larger IDs to multiple bytes
  938|       |			 * similarly as the following IDs */
  939|  5.50k|			k += *p;
  940|       |			/* fall through */
  941|  29.3k|		default:
  ------------------
  |  Branch (941:3): [True: 23.8k, False: 11.0k]
  ------------------
  942|  29.3k|			shift = 28;
  943|   137k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (943:11): [True: 116k, False: 20.7k]
  |  Branch (943:20): [True: 107k, False: 8.65k]
  ------------------
  944|   107k|				shift -= 7;
  945|  39.0k|			while (shift) {
  ------------------
  |  Branch (945:11): [True: 9.70k, False: 29.3k]
  ------------------
  946|  9.70k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  947|  9.70k|				shift -= 7;
  948|  9.70k|			}
  949|  29.3k|			*p++ = k & 0x7F;
  950|  29.3k|			break;
  951|  34.8k|		}
  952|  34.8k|	}
  953|       |
  954|  5.50k|	*buflen = p - temp;
  955|       |
  956|  5.50k|	if (buf)   {
  ------------------
  |  Branch (956:6): [True: 5.50k, False: 0]
  ------------------
  957|  5.50k|		*buf = malloc(*buflen);
  958|  5.50k|		if (!*buf)
  ------------------
  |  Branch (958:7): [True: 0, False: 5.50k]
  ------------------
  959|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  960|  5.50k|		memcpy(*buf, temp, *buflen);
  961|  5.50k|	}
  962|  5.50k|	return 0;
  963|  5.50k|}
sc_asn1_put_tag:
  980|  35.0k|{
  981|  35.0k|	size_t c = 0;
  982|  35.0k|	unsigned int tag_len, ii;
  983|  35.0k|	u8 *p = out;
  984|  35.0k|	u8 tag_char[4] = {0, 0, 0, 0};
  985|       |
  986|       |	/* Check tag */
  987|  35.0k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (987:6): [True: 0, False: 35.0k]
  |  Branch (987:18): [True: 0, False: 35.0k]
  ------------------
  988|       |		/* A tag of 0x00 is not valid and at most 4-byte tag names are supported. */
  989|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  990|      0|	}
  991|  70.0k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (991:20): [True: 35.0k, False: 35.0k]
  ------------------
  992|       |		/* Note: tag char will be reversed order. */
  993|  35.0k|		tag_char[tag_len++] = tag & 0xFF;
  994|  35.0k|	}
  995|       |
  996|  35.0k|	if (tag_len > 1)   {
  ------------------
  |  Branch (996:6): [True: 0, False: 35.0k]
  ------------------
  997|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  215|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  246|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (997:7): [True: 0, False: 0]
  ------------------
  998|       |			/* First byte is not escape marker. */
  999|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1000|      0|		}
 1001|      0|		for (ii = 1; ii < tag_len - 1; ii++) {
  ------------------
  |  Branch (1001:16): [True: 0, False: 0]
  ------------------
 1002|      0|			if ((tag_char[ii] & 0x80) != 0x80) {
  ------------------
  |  Branch (1002:8): [True: 0, False: 0]
  ------------------
 1003|       |				/* MS bit is not 'one'. */
 1004|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1005|      0|			}
 1006|      0|		}
 1007|      0|		if ((tag_char[0] & 0x80) != 0x00) {
  ------------------
  |  Branch (1007:7): [True: 0, False: 0]
  ------------------
 1008|       |			/* MS bit of the last byte is not 'zero'. */
 1009|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1010|      0|		}
 1011|      0|	}
 1012|       |
 1013|       |	/* Calculate the number of additional bytes necessary to encode the length. */
 1014|       |	/* c+1 is the size of the length field. */
 1015|  35.0k|	if (datalen > 127) {
  ------------------
  |  Branch (1015:6): [True: 1.72k, False: 33.2k]
  ------------------
 1016|  1.72k|		c = 1;
 1017|  2.81k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1017:10): [True: 1.09k, False: 1.72k]
  ------------------
 1018|  1.09k|			c++;
 1019|  1.72k|	}
 1020|  35.0k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1020:6): [True: 7.01k, False: 27.9k]
  |  Branch (1020:21): [True: 0, False: 27.9k]
  ------------------
 1021|       |		/* Caller only asks for the length that would be written. */
 1022|  7.01k|		return (int)(tag_len + (c + 1) + datalen);
 1023|  7.01k|	}
 1024|       |	/* We will write the tag, so check the length. */
 1025|  27.9k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1025:6): [True: 69, False: 27.9k]
  ------------------
 1026|     69|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     69|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1027|  55.8k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1027:12): [True: 27.9k, False: 27.9k]
  ------------------
 1028|  27.9k|		*p++ = tag_char[tag_len - ii - 1];
 1029|       |
 1030|  27.9k|	if (c > 0) {
  ------------------
  |  Branch (1030:6): [True: 1.06k, False: 26.8k]
  ------------------
 1031|  1.06k|		*p++ = 0x80 | c;
 1032|  2.75k|		while (c--)
  ------------------
  |  Branch (1032:10): [True: 1.69k, False: 1.06k]
  ------------------
 1033|  1.69k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1034|  1.06k|	}
 1035|  26.8k|	else {
 1036|  26.8k|		*p++ = datalen & 0x7F;
 1037|  26.8k|	}
 1038|  27.9k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1038:5): [True: 21.0k, False: 6.88k]
  |  Branch (1038:13): [True: 19.3k, False: 1.67k]
  ------------------
 1039|  19.3k|		memcpy(p, data, datalen);
 1040|  19.3k|		p += datalen;
 1041|  19.3k|	}
 1042|  27.9k|	if (ptr != NULL)
  ------------------
  |  Branch (1042:6): [True: 27.9k, False: 0]
  ------------------
 1043|  27.9k|		*ptr = p;
 1044|  27.9k|	return 0;
 1045|  27.9k|}
sc_asn1_decode:
 1831|  27.6k|{
 1832|  27.6k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1833|  27.6k|}
sc_asn1_decode_choice:
 1837|  3.26k|{
 1838|  3.26k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1839|  3.26k|}
sc_asn1_encode:
 2099|  23.1k|{
 2100|  23.1k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2101|  23.1k|}
_sc_asn1_encode:
 2105|  5.50k|{
 2106|  5.50k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2107|  5.50k|}
_sc_asn1_decode:
 2113|  5.49k|{
 2114|  5.49k|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2115|  5.49k|}
sc_der_copy:
 2119|  3.67k|{
 2120|  3.67k|	if (!dst || !src)
  ------------------
  |  Branch (2120:6): [True: 0, False: 3.67k]
  |  Branch (2120:14): [True: 0, False: 3.67k]
  ------------------
 2121|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2122|  3.67k|	memset(dst, 0, sizeof(*dst));
 2123|  3.67k|	if (src->len) {
  ------------------
  |  Branch (2123:6): [True: 3.58k, False: 91]
  ------------------
 2124|  3.58k|		if (!src->value)
  ------------------
  |  Branch (2124:7): [True: 0, False: 3.58k]
  ------------------
 2125|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2126|  3.58k|		dst->value = malloc(src->len);
 2127|  3.58k|		if (!dst->value)
  ------------------
  |  Branch (2127:7): [True: 0, False: 3.58k]
  ------------------
 2128|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2129|  3.58k|		dst->len = src->len;
 2130|  3.58k|		memcpy(dst->value, src->value, src->len);
 2131|  3.58k|	}
 2132|  3.67k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.67k|#define SC_SUCCESS				0
  ------------------
 2133|  3.67k|}
sc_encode_oid:
 2138|  3.41k|{
 2139|  3.41k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2140|  3.41k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  183|  3.41k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  224|  3.41k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  173|  3.41k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2141|  3.41k|		{ NULL, 0, 0, 0, NULL, NULL }
 2142|  3.41k|	};
 2143|  3.41k|	struct sc_asn1_entry asn1_object_id[2];
 2144|  3.41k|	int rv;
 2145|       |
 2146|  3.41k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2147|  3.41k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2148|       |
 2149|  3.41k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2150|  3.41k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  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: 0, False: 3.41k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.41k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2151|       |
 2152|  3.41k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.41k|#define SC_SUCCESS				0
  ------------------
 2153|  3.41k|}
sc_asn1_decode_ecdsa_signature:
 2208|      8|{
 2209|      8|	int i, r;
 2210|      8|	const unsigned char *pseq, *pint, *pend;
 2211|      8|	unsigned int cla, tag;
 2212|      8|	size_t seqlen, intlen;
 2213|       |
 2214|      8|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|      8|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      8|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2215|       |
 2216|      8|	if (!data || !out || !(*out) || fieldsize == 0)
  ------------------
  |  Branch (2216:6): [True: 0, False: 8]
  |  Branch (2216:15): [True: 0, False: 8]
  |  Branch (2216:23): [True: 0, False: 8]
  |  Branch (2216:34): [True: 0, False: 8]
  ------------------
 2217|      8|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2218|       |
 2219|      8|	if (outlen < 2 * fieldsize)
  ------------------
  |  Branch (2219:6): [True: 0, False: 8]
  ------------------
 2220|      8|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2221|       |
 2222|      8|	memset(*out, 0, outlen);
 2223|       |
 2224|      8|	pseq = data;
 2225|      8|	r = sc_asn1_read_tag(&pseq, datalen, &cla, &tag, &seqlen);
 2226|      8|	if (pseq == NULL || r < 0 || seqlen == 0 || (cla | tag) != 0x30)
  ------------------
  |  Branch (2226:6): [True: 1, False: 7]
  |  Branch (2226:22): [True: 1, False: 6]
  |  Branch (2226:31): [True: 1, False: 5]
  |  Branch (2226:46): [True: 1, False: 4]
  ------------------
 2227|      8|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x30 tag");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2228|       |
 2229|      4|	pint = pseq;
 2230|      4|	pend = pseq + seqlen;
 2231|      5|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (2231:14): [True: 5, False: 0]
  ------------------
 2232|      5|		r = sc_asn1_read_tag(&pint, (pend - pint), &cla, &tag, &intlen);
 2233|      5|		if (pint == NULL || r < 0 || intlen == 0 || (cla | tag) != 0x02) {
  ------------------
  |  Branch (2233:7): [True: 1, False: 4]
  |  Branch (2233:23): [True: 1, False: 3]
  |  Branch (2233:32): [True: 1, False: 2]
  |  Branch (2233:47): [True: 1, False: 1]
  ------------------
 2234|      4|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2235|      4|			LOG_TEST_GOTO_ERR(ctx, r, "Can not find 0x02");
  ------------------
  |  |  184|      4|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      4|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      4|	int _ret = (r); \
  |  |  |  |  178|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2236|      4|		}
 2237|       |
 2238|      1|		if (intlen == fieldsize + 1) {
  ------------------
  |  Branch (2238:7): [True: 0, False: 1]
  ------------------
 2239|       |			/* drop leading 0x00 (sign byte) if present */
 2240|      0|			if (*pint != 0x00) {
  ------------------
  |  Branch (2240:8): [True: 0, False: 0]
  ------------------
 2241|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2242|      0|				LOG_TEST_GOTO_ERR(ctx, r, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2243|      0|			}
 2244|      0|			pint++;
 2245|      0|			intlen--;
 2246|      0|		}
 2247|      1|		if (intlen > fieldsize) {
  ------------------
  |  Branch (2247:7): [True: 0, False: 1]
  ------------------
 2248|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2249|      0|			LOG_TEST_GOTO_ERR(ctx, r, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2250|      0|		}
 2251|      1|		if (intlen > 0)
  ------------------
  |  Branch (2251:7): [True: 1, False: 0]
  ------------------
 2252|      1|			memcpy(*out + fieldsize * i + fieldsize - intlen, pint, intlen);
 2253|       |
 2254|      1|		pint += intlen; /* next integer */
 2255|      1|	}
 2256|       |
 2257|      0|	sc_log(ctx, "r(%zu): %s", fieldsize, sc_dump_hex(*out, fieldsize));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2258|      0|	sc_log(ctx, "s(%zu): %s", fieldsize, sc_dump_hex(*out + fieldsize, fieldsize));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2259|       |
 2260|      0|	r = (int)(2 * fieldsize);
 2261|      4|err:
 2262|      4|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      4|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      4|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      4|	int _ret = r; \
  |  |  |  |  155|      4|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      4|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      4|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      4|	return _ret; \
  |  |  |  |  163|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2263|      4|}
asn1.c:decode_bit_string:
  578|  3.36k|{
  579|  3.36k|	const u8 *in = inbuf;
  580|  3.36k|	u8 *out = (u8 *) outbuf;
  581|  3.36k|	int i, count = 0;
  582|  3.36k|	int zero_bits;
  583|  3.36k|	size_t octets_left;
  584|       |
  585|  3.36k|	if (inlen < 1)
  ------------------
  |  Branch (585:6): [True: 3, False: 3.35k]
  ------------------
  586|      3|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  587|       |
  588|       |	/* The formatting is only enforced by SHALL keyword so we should accept
  589|       |	 * by default also non-strict values. */
  590|  3.35k|	if (strict) {
  ------------------
  |  Branch (590:6): [True: 0, False: 3.35k]
  ------------------
  591|       |		/* 8.6.2.3 If the bitstring is empty, there shall be no
  592|       |		 * subsequent octets,and the initial octet shall be zero. */
  593|      0|		if (inlen == 1 && *in != 0)
  ------------------
  |  Branch (593:7): [True: 0, False: 0]
  |  Branch (593:21): [True: 0, False: 0]
  ------------------
  594|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  595|       |		/* ITU-T Rec. X.690 8.6.2.2: The number shall be in the range zero to seven. */
  596|      0|		if ((*in & ~0x07) != 0)
  ------------------
  |  Branch (596:7): [True: 0, False: 0]
  ------------------
  597|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  598|      0|	}
  599|       |
  600|  3.35k|	memset(outbuf, 0, outlen);
  601|  3.35k|	zero_bits = *in & 0x07;
  602|  3.35k|	in++;
  603|  3.35k|	octets_left = inlen - 1;
  604|  3.35k|	if (outlen < octets_left)
  ------------------
  |  Branch (604:6): [True: 3, False: 3.35k]
  ------------------
  605|      3|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      3|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  606|       |
  607|   228k|	while (octets_left) {
  ------------------
  |  Branch (607:9): [True: 225k, False: 3.34k]
  ------------------
  608|       |		/* 1st octet of input:  ABCDEFGH, where A is the MSB */
  609|       |		/* 1st octet of output: HGFEDCBA, where A is the LSB */
  610|       |		/* first bit in bit string is the LSB in first resulting octet */
  611|   225k|		int bits_to_go;
  612|       |
  613|   225k|		*out = 0;
  614|   225k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (614:7): [True: 3.31k, False: 221k]
  |  Branch (614:27): [True: 464, False: 2.85k]
  ------------------
  615|    464|			bits_to_go = 8 - zero_bits;
  616|       |			/* Verify the padding is zero bits */
  617|    464|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (617:8): [True: 13, False: 451]
  ------------------
  618|     13|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     13|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  619|     13|			}
  620|    464|		} else
  621|   224k|			bits_to_go = 8;
  622|   225k|		if (invert)
  ------------------
  |  Branch (622:7): [True: 828, False: 224k]
  ------------------
  623|  6.24k|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (623:16): [True: 5.41k, False: 828]
  ------------------
  624|  5.41k|				*out |= ((*in >> (7 - i)) & 1) << i;
  625|  5.41k|			}
  626|   224k|		else {
  627|   224k|			*out = *in;
  628|   224k|		}
  629|   225k|		out++;
  630|   225k|		in++;
  631|   225k|		octets_left--;
  632|   225k|		count++;
  633|   225k|	}
  634|  3.34k|	return (count * 8) - zero_bits;
  635|  3.35k|}
asn1.c:asn1_write_element:
 1055|  36.1k|{
 1056|  36.1k|	unsigned char t;
 1057|  36.1k|	unsigned char *buf, *p;
 1058|  36.1k|	int c = 0;
 1059|  36.1k|	unsigned short_tag;
 1060|  36.1k|	unsigned char tag_char[3] = {0, 0, 0};
 1061|  36.1k|	size_t tag_len, ii;
 1062|       |
 1063|  36.1k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  168|  36.1k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1064|  72.3k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1064:20): [True: 36.1k, False: 36.1k]
  ------------------
 1065|  36.1k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1066|  36.1k|	if (!tag_len)
  ------------------
  |  Branch (1066:6): [True: 0, False: 36.1k]
  ------------------
 1067|      0|		tag_len = 1;
 1068|       |
 1069|  36.1k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1069:6): [True: 0, False: 36.1k]
  ------------------
 1070|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  215|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  246|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (1070:7): [True: 0, False: 0]
  ------------------
 1071|      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]
  |  |  ------------------
  ------------------
 1072|       |
 1073|      0|		for (ii = 1; ii < tag_len - 1; ii++)
  ------------------
  |  Branch (1073:16): [True: 0, False: 0]
  ------------------
 1074|      0|			if (!(tag_char[ii] & 0x80))
  ------------------
  |  Branch (1074:8): [True: 0, False: 0]
  ------------------
 1075|      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]
  |  |  ------------------
  ------------------
 1076|       |
 1077|      0|		if (tag_char[0] & 0x80)
  ------------------
  |  Branch (1077:7): [True: 0, False: 0]
  ------------------
 1078|      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]
  |  |  ------------------
  ------------------
 1079|      0|	}
 1080|       |
 1081|  36.1k|	t = tag_char[tag_len - 1] & 0x1F;
 1082|       |
 1083|  36.1k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  160|  36.1k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1083:10): [True: 36.1k, False: 0]
  ------------------
 1084|  20.6k|	case SC_ASN1_UNI:
  ------------------
  |  |  161|  20.6k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1084:2): [True: 20.6k, False: 15.5k]
  ------------------
 1085|  20.6k|		break;
 1086|  15.5k|	case SC_ASN1_APP:
  ------------------
  |  |  162|  15.5k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1086:2): [True: 15.5k, False: 20.6k]
  ------------------
 1087|  15.5k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  210|  15.5k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1088|  15.5k|		break;
 1089|      0|	case SC_ASN1_CTX:
  ------------------
  |  |  163|      0|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1089:2): [True: 0, False: 36.1k]
  ------------------
 1090|      0|		t |= SC_ASN1_TAG_CONTEXT;
  ------------------
  |  |  211|      0|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
 1091|      0|		break;
 1092|      0|	case SC_ASN1_PRV:
  ------------------
  |  |  164|      0|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (1092:2): [True: 0, False: 36.1k]
  ------------------
 1093|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  212|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1094|      0|		break;
 1095|  36.1k|	}
 1096|  36.1k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  165|  36.1k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1096:6): [True: 7.88k, False: 28.3k]
  ------------------
 1097|  7.88k|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  214|  7.88k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1098|  36.1k|	if (datalen > 127) {
  ------------------
  |  Branch (1098:6): [True: 4.28k, False: 31.9k]
  ------------------
 1099|  4.28k|		c = 1;
 1100|  4.31k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1100:10): [True: 30, False: 4.28k]
  ------------------
 1101|     30|			c++;
 1102|  4.28k|	}
 1103|       |
 1104|  36.1k|	*outlen = tag_len + 1 + c + datalen;
 1105|  36.1k|	buf = malloc(*outlen);
 1106|  36.1k|	if (buf == NULL)
  ------------------
  |  Branch (1106:6): [True: 0, False: 36.1k]
  ------------------
 1107|      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]
  |  |  ------------------
  ------------------
 1108|       |
 1109|  36.1k|	*out = p = buf;
 1110|  36.1k|	*p++ = t;
 1111|  36.1k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1111:12): [True: 0, False: 36.1k]
  ------------------
 1112|      0|		*p++ = tag_char[tag_len - ii - 1];
 1113|       |
 1114|  36.1k|	if (c) {
  ------------------
  |  Branch (1114:6): [True: 4.28k, False: 31.9k]
  ------------------
 1115|  4.28k|		*p++ = 0x80 | c;
 1116|  8.60k|		while (c--)
  ------------------
  |  Branch (1116:10): [True: 4.31k, False: 4.28k]
  ------------------
 1117|  4.31k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1118|  4.28k|	}
 1119|  31.9k|	else   {
 1120|  31.9k|		*p++ = datalen & 0x7F;
 1121|  31.9k|	}
 1122|  36.1k|	if (datalen && data) {
  ------------------
  |  Branch (1122:6): [True: 35.1k, False: 1.08k]
  |  Branch (1122:17): [True: 35.1k, False: 0]
  ------------------
 1123|  35.1k|		memcpy(p, data, datalen);
 1124|  35.1k|	}
 1125|       |
 1126|  36.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  36.1k|#define SC_SUCCESS				0
  ------------------
 1127|  36.1k|}
asn1.c:asn1_decode:
 1740|  48.1k|{
 1741|  48.1k|	int r, idx = 0;
 1742|  48.1k|	const u8 *p = in, *obj;
 1743|  48.1k|	struct sc_asn1_entry *entry = asn1;
 1744|  48.1k|	size_t left = len, objlen;
 1745|       |
 1746|  48.1k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*s""called, left=%zu, depth %d%s",
  ------------------
  |  |   70|  96.2k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 3.28k, False: 44.8k]
  |  |  ------------------
  ------------------
 1747|  48.1k|			depth, depth, "", left, depth, choice ? ", choice" : "");
 1748|       |
 1749|  48.1k|	if (!p)
  ------------------
  |  Branch (1749:6): [True: 1, False: 48.1k]
  ------------------
 1750|      1|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      1|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1751|  48.1k|	if (left < 2) {
  ------------------
  |  Branch (1751:6): [True: 2.06k, False: 46.0k]
  ------------------
 1752|  4.79k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  172|  3.63k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1752:10): [True: 3.63k, False: 1.15k]
  |  Branch (1752:24): [True: 2.72k, False: 908]
  ------------------
 1753|  2.72k|			asn1++;
 1754|       |		/* If all elements were optional, there's nothing
 1755|       |		 * to complain about */
 1756|  2.06k|		if (asn1->name == NULL)
  ------------------
  |  Branch (1756:7): [True: 1.15k, False: 908]
  ------------------
 1757|  1.15k|			return 0;
 1758|    908|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|    908|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1759|    908|			      "non-optional field \"%s\" not found\n",
 1760|    908|			      asn1->name);
 1761|    908|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    908|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1762|  2.06k|	}
 1763|  46.0k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1763:6): [True: 1.43k, False: 44.6k]
  |  Branch (1763:19): [True: 524, False: 44.0k]
  |  Branch (1763:35): [True: 0, False: 44.0k]
  ------------------
 1764|  1.95k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  1.95k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1765|       |
 1766|   150k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1766:16): [True: 114k, False: 35.2k]
  ------------------
 1767|   114k|		entry = &asn1[idx];
 1768|       |
 1769|   114k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|   114k|#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)
  |  |  ------------------
  |  |  |  | 1770|   114k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1771|   114k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  172|   114k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1770|   114k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1771|   114k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1772|       |
 1773|       |		/* Special case CHOICE has no tag */
 1774|   114k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  194|   114k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1774:7): [True: 18, False: 114k]
  ------------------
 1775|     18|			r = asn1_decode(ctx,
 1776|     18|				(struct sc_asn1_entry *) entry->parm,
 1777|     18|				p, left, &p, &left, 1, depth + 1);
 1778|       |			/* When the inner call fails it returns before writing
 1779|       |			 * back to *newp and *len_left, so the caller's p/left are
 1780|       |			 * unchanged.  Swallowing the error for an optional
 1781|       |			 * CHOICE is therefore safe: the next field will be
 1782|       |			 * attempted at the same position. */
 1783|     18|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  172|     17|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1783:8): [True: 1, False: 17]
  |  Branch (1783:18): [True: 1, False: 16]
  ------------------
 1784|      2|				r = 0;
 1785|     18|			goto decode_ok;
 1786|     18|		}
 1787|       |
 1788|   114k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1789|   114k|		if (obj == NULL) {
  ------------------
  |  Branch (1789:7): [True: 53.4k, False: 61.4k]
  ------------------
 1790|  53.4k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  53.4k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1791|  53.4k|			if (choice)
  ------------------
  |  Branch (1791:8): [True: 5.47k, False: 47.9k]
  ------------------
 1792|  5.47k|				continue;
 1793|  47.9k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  172|  47.9k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1793:8): [True: 43.7k, False: 4.20k]
  ------------------
 1794|  43.7k|				continue;
 1795|  4.20k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  4.20k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1796|  4.20k|			if (left) {
  ------------------
  |  Branch (1796:8): [True: 4.15k, False: 56]
  ------------------
 1797|  4.15k|				u8 line[128], *linep = line;
 1798|  4.15k|				size_t i;
 1799|       |
 1800|  4.15k|				line[0] = 0;
 1801|  39.2k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1801:17): [True: 36.0k, False: 3.22k]
  |  Branch (1801:27): [True: 35.0k, False: 931]
  ------------------
 1802|  35.0k|					sprintf((char *) linep, "%02X ", p[i]);
 1803|  35.0k|					linep += 3;
 1804|  35.0k|				}
 1805|  4.15k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  4.15k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1806|  4.15k|			}
 1807|  4.20k|			sc_free_entry(asn1);
 1808|  4.20k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  4.20k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  4.20k|	int _ret = r; \
  |  |  155|  4.20k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4.20k, False: 0]
  |  |  ------------------
  |  |  156|  4.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  4.20k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.20k, False: 0]
  |  |  ------------------
  |  |  157|  4.20k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  4.20k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  4.20k|	return _ret; \
  |  |  163|  4.20k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1809|  4.20k|		}
 1810|  61.4k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1811|       |
 1812|  61.4k|decode_ok:
 1813|  61.4k|		if (r)
  ------------------
  |  Branch (1813:7): [True: 1.51k, False: 59.9k]
  ------------------
 1814|  1.51k|			return r;
 1815|  59.9k|		if (choice)
  ------------------
  |  Branch (1815:7): [True: 3.07k, False: 56.8k]
  ------------------
 1816|  3.07k|			break;
 1817|  59.9k| 	}
 1818|  38.3k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1818:7): [True: 3.13k, False: 35.2k]
  |  Branch (1818:17): [True: 60, False: 3.07k]
  ------------------
 1819|     60|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|     60|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     60|	int _ret = r; \
  |  |  155|     60|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 60, False: 0]
  |  |  ------------------
  |  |  156|     60|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     60|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 60, False: 0]
  |  |  ------------------
  |  |  157|     60|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     60|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     60|	return _ret; \
  |  |  163|     60|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1820|  38.3k| 	if (newp != NULL)
  ------------------
  |  Branch (1820:7): [True: 7.85k, False: 30.4k]
  ------------------
 1821|  7.85k|		*newp = p;
 1822|  38.3k| 	if (len_left != NULL)
  ------------------
  |  Branch (1822:7): [True: 7.85k, False: 30.4k]
  ------------------
 1823|  7.85k|		*len_left = left;
 1824|  38.3k|	if (choice)
  ------------------
  |  Branch (1824:6): [True: 3.07k, False: 35.2k]
  ------------------
 1825|  3.07k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  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: 162, False: 2.91k]
  |  |  ------------------
  |  |  156|    162|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 162]
  |  |  ------------------
  |  |  157|    162|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.91k|	} else { \
  |  |  159|  2.91k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  2.91k|			"returning with: %d\n", _ret); \
  |  |  161|  2.91k|	} \
  |  |  162|  3.07k|	return _ret; \
  |  |  163|  3.07k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1826|  35.2k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  153|  35.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  35.2k|	int _ret = r; \
  |  |  155|  35.2k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 35.2k, False: 0]
  |  |  ------------------
  |  |  156|  35.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 35.2k]
  |  |  ------------------
  |  |  157|  35.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  35.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|  35.2k|	return _ret; \
  |  |  163|  35.2k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1827|  35.2k|}
asn1.c:sc_free_entry:
 1705|  15.2k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1706|  15.2k|	int idx = 0;
 1707|  15.2k|	struct sc_asn1_entry *entry = asn1;
 1708|       |
 1709|  15.2k|	if (!asn1)
  ------------------
  |  Branch (1709:6): [True: 740, False: 14.4k]
  ------------------
 1710|    740|		return;
 1711|       |
 1712|  69.6k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1712:16): [True: 55.1k, False: 14.4k]
  ------------------
 1713|  55.1k|		entry = &asn1[idx];
 1714|  55.1k|		switch (entry->type) {
 1715|  3.86k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  194|  3.86k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1715:3): [True: 3.86k, False: 51.3k]
  ------------------
 1716|  11.0k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  193|  11.0k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1716:3): [True: 7.14k, False: 48.0k]
  ------------------
 1717|  11.0k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1718|  11.0k|			break;
 1719|  12.0k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  181|  12.0k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1719:3): [True: 12.0k, False: 43.1k]
  ------------------
 1720|  12.1k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  180|  12.1k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1720:3): [True: 59, False: 55.1k]
  ------------------
 1721|  12.2k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  179|  12.2k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1721:3): [True: 97, False: 55.0k]
  ------------------
 1722|  12.4k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  190|  12.4k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1722:3): [True: 240, False: 54.9k]
  ------------------
 1723|  12.7k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  188|  12.7k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1723:3): [True: 287, False: 54.8k]
  ------------------
 1724|  14.5k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  185|  14.5k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1724:3): [True: 1.82k, False: 53.3k]
  ------------------
 1725|  14.5k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  173|  14.5k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  171|  1.43k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1725:8): [True: 1.43k, False: 13.1k]
  |  Branch (1725:42): [True: 539, False: 898]
  ------------------
 1726|    539|				u8 **buf = (u8 **)entry->parm;
 1727|    539|				free(*buf);
 1728|    539|				*buf = NULL;
 1729|    539|			}
 1730|  14.5k|			break;
 1731|  29.5k|		default:
  ------------------
  |  Branch (1731:3): [True: 29.5k, False: 25.5k]
  ------------------
 1732|  29.5k|			break;
 1733|  55.1k|		}
 1734|  55.1k|	}
 1735|  14.4k|}
asn1.c:asn1_decode_entry:
 1490|  61.4k|{
 1491|  61.4k|	void *parm = entry->parm;
 1492|  61.4k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1493|  61.4k|			     size_t nobjlen, int ndepth);
 1494|  61.4k|	size_t *len = (size_t *) entry->arg;
 1495|  61.4k|	int r = 0;
 1496|       |
 1497|  61.4k|	callback_func = parm;
 1498|       |
 1499|  61.4k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|   245k|#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: 21.6k, False: 39.8k]
  |  |  |  Branch (70:115): [True: 21.6k, False: 39.8k]
  |  |  ------------------
  ------------------
 1500|  61.4k|		depth, depth, "", entry->name,
 1501|  61.4k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1502|  61.4k|		objlen > 16 ? "..." : "");
 1503|       |
 1504|  61.4k|	switch (entry->type) {
 1505|  15.7k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  193|  15.7k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1505:2): [True: 15.7k, False: 45.7k]
  ------------------
 1506|  15.7k|		if (parm != NULL)
  ------------------
  |  Branch (1506:7): [True: 9.54k, False: 6.16k]
  ------------------
 1507|  9.54k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1508|  9.54k|				       objlen, NULL, NULL, 0, depth + 1);
 1509|  15.7k|		break;
 1510|  2.22k|	case SC_ASN1_NULL:
  ------------------
  |  |  182|  2.22k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1510:2): [True: 2.22k, False: 59.2k]
  ------------------
 1511|  2.22k|		break;
 1512|     40|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  177|     40|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1512:2): [True: 40, False: 61.4k]
  ------------------
 1513|     40|		if (parm != NULL) {
  ------------------
  |  Branch (1513:7): [True: 40, False: 0]
  ------------------
 1514|     40|			if (objlen != 1) {
  ------------------
  |  Branch (1514:8): [True: 6, False: 34]
  ------------------
 1515|      6|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "invalid ASN.1 object length: %zu", objlen);
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1516|      6|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1517|      6|			} else
 1518|     34|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1518:23): [True: 28, False: 6]
  ------------------
 1519|     40|		}
 1520|     40|		break;
 1521|  1.40k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  178|  1.40k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1521:2): [True: 1.40k, False: 60.0k]
  ------------------
 1522|  1.40k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  184|  1.40k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1522:2): [True: 0, False: 61.4k]
  ------------------
 1523|  1.40k|		if (parm != NULL) {
  ------------------
  |  Branch (1523:7): [True: 1.40k, False: 0]
  ------------------
 1524|  1.40k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1525|  1.40k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.40k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1525:8): [True: 1.37k, False: 25]
  ------------------
 1526|  1.37k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  1.37k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1527|  1.37k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1528|  1.37k|			}
 1529|  1.40k|		}
 1530|  1.40k|		break;
 1531|  2.84k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  180|  2.84k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1531:2): [True: 2.84k, False: 58.6k]
  ------------------
 1532|  5.32k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  179|  5.32k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1532:2): [True: 2.48k, False: 58.9k]
  ------------------
 1533|  5.32k|		if (parm != NULL) {
  ------------------
  |  Branch (1533:7): [True: 2.84k, False: 2.48k]
  ------------------
 1534|  2.84k|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  179|  2.84k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1534:17): [True: 0, False: 2.84k]
  ------------------
 1535|  2.84k|			if (len == NULL)
  ------------------
  |  Branch (1535:8): [True: 0, False: 2.84k]
  ------------------
 1536|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1537|  2.84k|			if (objlen < 1) {
  ------------------
  |  Branch (1537:8): [True: 12, False: 2.82k]
  ------------------
 1538|     12|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     12|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1539|     12|				break;
 1540|     12|			}
 1541|  2.82k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  173|  2.82k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1541:8): [True: 2.82k, False: 0]
  ------------------
 1542|  2.82k|				u8 **buf = (u8 **) parm;
 1543|  2.82k|				if (objlen > 1) {
  ------------------
  |  Branch (1543:9): [True: 2.81k, False: 16]
  ------------------
 1544|  2.81k|					*buf = malloc(objlen-1);
 1545|  2.81k|					if (*buf == NULL) {
  ------------------
  |  Branch (1545:10): [True: 0, False: 2.81k]
  ------------------
 1546|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1547|      0|						break;
 1548|      0|					}
 1549|  2.81k|				} else {
 1550|     16|					*buf = NULL;
 1551|     16|				}
 1552|  2.82k|				*len = objlen-1;
 1553|  2.82k|				parm = *buf;
 1554|  2.82k|			}
 1555|  2.82k|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1556|  2.82k|			if (r >= 0) {
  ------------------
  |  Branch (1556:8): [True: 2.81k, False: 13]
  ------------------
 1557|  2.81k|				*len = r;
 1558|  2.81k|				r = 0;
 1559|  2.81k|			}
 1560|  2.82k|		}
 1561|  5.30k|		break;
 1562|  5.30k|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  195|    531|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1562:2): [True: 531, False: 60.9k]
  ------------------
 1563|    531|		if (parm != NULL)
  ------------------
  |  Branch (1563:7): [True: 531, False: 0]
  ------------------
 1564|    531|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1565|    531|		break;
 1566|  18.6k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  181|  18.6k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1566:2): [True: 18.6k, False: 42.8k]
  ------------------
 1567|  18.6k|		if (parm != NULL) {
  ------------------
  |  Branch (1567:7): [True: 18.6k, False: 34]
  ------------------
 1568|  18.6k|			size_t c;
 1569|  18.6k|			if (len == NULL)
  ------------------
  |  Branch (1569:8): [True: 0, False: 18.6k]
  ------------------
 1570|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1571|       |
 1572|       |			/* Strip off padding zero */
 1573|  18.6k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  174|  18.6k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1573:8): [True: 4.94k, False: 13.6k]
  ------------------
 1574|  4.94k|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1574:9): [True: 4.47k, False: 465]
  |  Branch (1574:23): [True: 2.78k, False: 1.69k]
  ------------------
 1575|  2.78k|				objlen--;
 1576|  2.78k|				obj++;
 1577|  2.78k|			}
 1578|       |
 1579|       |			/* Allocate buffer if needed */
 1580|  18.6k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  173|  18.6k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1580:8): [True: 14.8k, False: 3.76k]
  ------------------
 1581|  14.8k|				u8 **buf = (u8 **) parm;
 1582|  14.8k|				if (objlen > 0) {
  ------------------
  |  Branch (1582:9): [True: 10.3k, False: 4.47k]
  ------------------
 1583|  10.3k|					*buf = malloc(objlen);
 1584|  10.3k|					if (*buf == NULL) {
  ------------------
  |  Branch (1584:10): [True: 0, False: 10.3k]
  ------------------
 1585|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1586|      0|						break;
 1587|      0|					}
 1588|  10.3k|				} else {
 1589|  4.47k|					*buf = NULL;
 1590|  4.47k|				}
 1591|  14.8k|				c = *len = objlen;
 1592|  14.8k|				parm = *buf;
 1593|  14.8k|			} else
 1594|  3.76k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1594:9): [True: 249, False: 3.51k]
  ------------------
 1595|       |
 1596|  18.6k|			if (c > 0)
  ------------------
  |  Branch (1596:8): [True: 13.6k, False: 4.99k]
  ------------------
 1597|  13.6k|				memcpy(parm, obj, c);
 1598|  18.6k|			*len = c;
 1599|  18.6k|		}
 1600|  18.6k|		break;
 1601|  18.6k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  190|     40|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1601:2): [True: 40, False: 61.4k]
  ------------------
 1602|     40|		if (parm != NULL) {
  ------------------
  |  Branch (1602:7): [True: 40, False: 0]
  ------------------
 1603|     40|			size_t c;
 1604|     40|			if (len == NULL)
  ------------------
  |  Branch (1604:8): [True: 0, False: 40]
  ------------------
 1605|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1606|     40|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  173|     40|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1606:8): [True: 0, False: 40]
  ------------------
 1607|      0|				u8 **buf = (u8 **) parm;
 1608|      0|				if (objlen > 0) {
  ------------------
  |  Branch (1608:9): [True: 0, False: 0]
  ------------------
 1609|      0|					*buf = malloc(objlen);
 1610|      0|					if (*buf == NULL) {
  ------------------
  |  Branch (1610:10): [True: 0, False: 0]
  ------------------
 1611|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1612|      0|						break;
 1613|      0|					}
 1614|      0|				} else {
 1615|      0|					*buf = NULL;
 1616|      0|				}
 1617|      0|				c = *len = objlen;
 1618|      0|				parm = *buf;
 1619|      0|			} else
 1620|     40|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1620:9): [True: 1, False: 39]
  ------------------
 1621|       |
 1622|     40|			if (c > 0)
  ------------------
  |  Branch (1622:8): [True: 36, False: 4]
  ------------------
 1623|     36|				memcpy(parm, obj, c);
 1624|     40|			*len = c;
 1625|     40|		}
 1626|     40|		break;
 1627|  6.68k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  183|  6.68k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1627:2): [True: 6.68k, False: 54.7k]
  ------------------
 1628|  6.68k|		if (parm != NULL) {
  ------------------
  |  Branch (1628:7): [True: 6.67k, False: 5]
  ------------------
 1629|  6.67k|			if (objlen == 0) {
  ------------------
  |  Branch (1629:8): [True: 15, False: 6.66k]
  ------------------
 1630|     15|				if (entry->flags & SC_ASN1_OPTIONAL) {
  ------------------
  |  |  172|     15|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1630:9): [True: 3, False: 12]
  ------------------
 1631|      3|					sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding ASN.1 object '%s' with len=0 as invalid OID", entry->name);
  ------------------
  |  |   70|      3|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1632|      3|					sc_init_oid((struct sc_object_id *)parm);
 1633|      3|					return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 1634|     12|				} else {
 1635|     12|					sc_debug(ctx, SC_LOG_DEBUG_ASN1, "ignoring ASN.1 object '%s' with len=0 as invalid OID", entry->name);
  ------------------
  |  |   70|     12|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1636|     12|				}
 1637|  6.66k|			} else {
 1638|  6.66k|				r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *)parm);
 1639|  6.66k|			}
 1640|  6.67k|		}
 1641|  6.67k|		break;
 1642|  6.67k|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  188|      5|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1642:2): [True: 5, False: 61.4k]
  ------------------
 1643|    273|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  185|    273|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1643:2): [True: 268, False: 61.1k]
  ------------------
 1644|    273|		if (parm != NULL) {
  ------------------
  |  Branch (1644:7): [True: 270, False: 3]
  ------------------
 1645|    270|			if (len == NULL)
  ------------------
  |  Branch (1645:8): [True: 0, False: 270]
  ------------------
 1646|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1647|    270|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  173|    270|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1647:8): [True: 0, False: 270]
  ------------------
 1648|      0|				u8 **buf = (u8 **) parm;
 1649|      0|				*buf = malloc(objlen+1);
 1650|      0|				if (*buf == NULL) {
  ------------------
  |  Branch (1650:9): [True: 0, False: 0]
  ------------------
 1651|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1652|      0|					break;
 1653|      0|				}
 1654|      0|				*len = objlen+1;
 1655|      0|				parm = *buf;
 1656|      0|			}
 1657|    270|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1658|    270|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  173|    270|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1658:8): [True: 0, False: 270]
  ------------------
 1659|      0|				*len -= 1;
 1660|      0|			}
 1661|    270|		}
 1662|    273|		break;
 1663|  2.08k|	case SC_ASN1_PATH:
  ------------------
  |  |  198|  2.08k|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1663:2): [True: 2.08k, False: 59.3k]
  ------------------
 1664|  2.08k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1664:7): [True: 2.07k, False: 4]
  ------------------
 1665|  2.07k|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1666|  2.08k|		break;
 1667|      4|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  199|      4|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1667:2): [True: 4, False: 61.4k]
  ------------------
 1668|      4|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1668:7): [True: 4, False: 0]
  ------------------
 1669|      4|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1670|      4|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1670:15): [True: 0, False: 4]
  ------------------
 1671|       |
 1672|      4|			memcpy(id->value, obj, c);
 1673|      4|			id->len = c;
 1674|      4|		}
 1675|      4|		break;
 1676|     30|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  200|     30|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1676:2): [True: 30, False: 61.4k]
  ------------------
 1677|     30|		if (entry->parm != NULL)
  ------------------
  |  Branch (1677:7): [True: 29, False: 1]
  ------------------
 1678|     29|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1679|     30|		break;
 1680|  5.47k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  201|  5.47k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1680:2): [True: 5.47k, False: 55.9k]
  ------------------
 1681|  5.47k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1681:7): [True: 5.47k, False: 0]
  ------------------
 1682|  5.47k|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1683|  5.47k|		break;
 1684|     35|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  202|     35|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1684:2): [True: 35, False: 61.4k]
  ------------------
 1685|     35|		if (entry->parm != NULL)
  ------------------
  |  Branch (1685:7): [True: 35, False: 0]
  ------------------
 1686|     35|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1687|     35|		break;
 1688|  2.98k|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  205|  2.98k|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1688:2): [True: 2.98k, False: 58.4k]
  ------------------
 1689|  2.98k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1689:7): [True: 2.98k, False: 0]
  ------------------
 1690|  2.98k|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1691|  2.98k|		break;
 1692|      0|	default:
  ------------------
  |  Branch (1692:2): [True: 0, False: 61.4k]
  ------------------
 1693|      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__
  |  |  ------------------
  ------------------
 1694|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1695|  61.4k|	}
 1696|  61.4k|	if (r) {
  ------------------
  |  Branch (1696:6): [True: 1.49k, False: 59.9k]
  ------------------
 1697|  1.49k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|  1.49k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1698|  1.49k|		      sc_strerror(r));
 1699|  1.49k|		return r;
 1700|  1.49k|	}
 1701|  59.9k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  171|  59.9k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1702|  59.9k|	return 0;
 1703|  61.4k|}
asn1.c:decode_bit_field:
  691|    531|{
  692|    531|	u8		data[sizeof(unsigned int)];
  693|    531|	unsigned int	field = 0;
  694|    531|	int		i, n;
  695|       |
  696|    531|	if (outlen != sizeof(data))
  ------------------
  |  Branch (696:6): [True: 0, False: 531]
  ------------------
  697|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  698|       |
  699|    531|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  700|    531|	if (n < 0)
  ------------------
  |  Branch (700:6): [True: 32, False: 499]
  ------------------
  701|     32|		return n;
  702|       |
  703|  1.32k|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (703:14): [True: 825, False: 499]
  ------------------
  704|    825|		field |= ((unsigned int) data[i/8] << i);
  705|    825|	}
  706|    499|	memcpy(outbuf, &field, outlen);
  707|    499|	return 0;
  708|    531|}
asn1.c:sc_asn1_decode_utf8string:
  967|    270|{
  968|    270|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (968:6): [True: 0, False: 270]
  ------------------
  969|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  970|    270|	*outlen = inlen+1;
  971|    270|	memcpy(out, inbuf, inlen);
  972|    270|	out[inlen] = 0;
  973|    270|	return 0;
  974|    270|}
asn1.c:asn1_decode_path:
 1149|  2.07k|{
 1150|  2.07k|	int idx, count, r;
 1151|  2.07k|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1152|  2.07k|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1153|  2.07k|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1154|       |
 1155|  2.07k|	memset(path, 0, sizeof(struct sc_path));
 1156|       |
 1157|  2.07k|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1158|  2.07k|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1159|       |
 1160|  2.07k|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1161|  2.07k|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1162|       |
 1163|  2.07k|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1164|  2.07k|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1165|  2.07k|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1166|  2.07k|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1167|       |
 1168|  2.07k|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1169|  2.07k|	if (r)
  ------------------
  |  Branch (1169:6): [True: 30, False: 2.04k]
  ------------------
 1170|     30|		return r;
 1171|       |
 1172|  2.04k|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|  2.04k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1172:6): [True: 0, False: 2.04k]
  ------------------
 1173|       |		/* extended path present: set 'path' and 'aid' */
 1174|      0|		memcpy(path->aid.value, aid_value, aid_len);
 1175|      0|		path->aid.len = aid_len;
 1176|       |
 1177|      0|		memcpy(path->value, path_value, path_len);
 1178|      0|		path->len = path_len;
 1179|      0|	}
 1180|  2.04k|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|  2.04k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1180:11): [True: 2.04k, False: 5]
  ------------------
 1181|       |		/* path present: set 'path' */
 1182|  2.04k|		memcpy(path->value, path_value, path_len);
 1183|  2.04k|		path->len = path_len;
 1184|  2.04k|	}
 1185|      5|	else   {
 1186|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1187|      5|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      5|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1188|      5|	}
 1189|       |
 1190|  2.04k|	if (path->len == 2)
  ------------------
  |  Branch (1190:6): [True: 1.75k, False: 287]
  ------------------
 1191|  1.75k|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  1.75k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1192|    287|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1192:13): [True: 0, False: 287]
  |  Branch (1192:30): [True: 0, False: 0]
  ------------------
 1193|      0|		path->type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 1194|    287|	else
 1195|    287|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    287|#define SC_PATH_TYPE_PATH		2
  ------------------
 1196|       |
 1197|  2.04k|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  171|  2.04k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  171|     12|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1197:6): [True: 12, False: 2.02k]
  |  Branch (1197:48): [True: 3, False: 9]
  ------------------
 1198|      3|		path->index = idx;
 1199|      3|		path->count = count;
 1200|      3|	}
 1201|  2.03k|	else {
 1202|  2.03k|		path->index = 0;
 1203|  2.03k|		path->count = -1;
 1204|  2.03k|	}
 1205|       |
 1206|  2.04k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.04k|#define SC_SUCCESS				0
  ------------------
 1207|  2.04k|}
asn1.c:asn1_decode_p15_object:
 1395|     29|{
 1396|     29|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1397|     29|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1398|     29|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1399|     29|	size_t flags_len = sizeof(p15_obj->flags);
 1400|     29|	size_t label_len = sizeof(p15_obj->label);
 1401|     29|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1402|     29|	int r, ii;
 1403|       |
 1404|    261|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|    261|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1404:13): [True: 232, False: 29]
  ------------------
 1405|    232|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1406|     29|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1407|       |
 1408|       |
 1409|     29|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1410|     29|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1411|     29|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1412|     29|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1413|     29|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1414|     29|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1415|       |
 1416|    261|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|    261|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1416:13): [True: 232, False: 29]
  ------------------
 1417|    232|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1418|    232|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1419|    232|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1420|    232|	}
 1421|     29|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1422|       |
 1423|     29|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1424|     29|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1425|     29|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1426|     29|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1427|       |
 1428|     29|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1429|     29|	return r;
 1430|     29|}
asn1.c:asn1_decode_se_info:
 1243|     35|{
 1244|     35|	struct sc_pkcs15_sec_env_info **ses;
 1245|     35|	const unsigned char *ptr = obj;
 1246|     35|	size_t idx, ptrlen = objlen;
 1247|     35|	int ret;
 1248|       |
 1249|     35|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     35|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     35|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     35|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     35|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1250|       |
 1251|     35|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|     35|#define SC_MAX_SE_NUM			8
  ------------------
 1252|     35|	if (ses == NULL) {
  ------------------
  |  Branch (1252:6): [True: 0, False: 35]
  ------------------
 1253|      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]
  |  |  ------------------
  ------------------
 1254|      0|	}
 1255|       |
 1256|     59|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|    118|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1256:14): [True: 59, False: 0]
  |  Branch (1256:37): [True: 33, False: 26]
  ------------------
 1257|     33|		struct sc_asn1_entry asn1_se[2];
 1258|     33|		struct sc_asn1_entry asn1_se_info[4];
 1259|     33|		struct sc_pkcs15_sec_env_info si;
 1260|       |
 1261|     33|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1262|     33|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1263|       |
 1264|     33|		si.aid.len = sizeof(si.aid.value);
 1265|     33|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1266|     33|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1267|     33|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1268|     33|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1269|       |
 1270|     33|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1271|     33|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     33|#define SC_SUCCESS				0
  ------------------
  |  Branch (1271:7): [True: 9, False: 24]
  ------------------
 1272|      9|			goto err;
 1273|     24|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  171|     24|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1273:7): [True: 17, False: 7]
  ------------------
 1274|     17|			sc_init_oid(&si.owner);
 1275|       |
 1276|     24|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1277|     24|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1277:7): [True: 0, False: 24]
  ------------------
 1278|      0|			ret = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1279|      0|			goto err;
 1280|      0|		}
 1281|       |
 1282|     24|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1283|     24|		idx++;
 1284|     24|	}
 1285|       |
 1286|     26|	*se  = ses;
 1287|     26|	*num = idx;
 1288|     26|	ret = SC_SUCCESS;
  ------------------
  |  |   28|     26|#define SC_SUCCESS				0
  ------------------
 1289|     35|err:
 1290|     35|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|     35|#define SC_SUCCESS				0
  ------------------
  |  Branch (1290:6): [True: 9, False: 26]
  ------------------
 1291|      9|		size_t i;
 1292|     19|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1292:15): [True: 10, False: 9]
  ------------------
 1293|     10|			if (ses[i])
  ------------------
  |  Branch (1293:8): [True: 10, False: 0]
  ------------------
 1294|     10|				free(ses[i]);
 1295|      9|		free(ses);
 1296|      9|	}
 1297|       |
 1298|     35|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  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|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 9, False: 26]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1299|     35|}
asn1.c:asn1_encode:
 2056|  31.9k|{
 2057|  31.9k|	int r, idx = 0;
 2058|  31.9k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2059|  31.9k|	size_t total = 0, objsize;
 2060|       |
 2061|  31.9k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2061:6): [True: 0, False: 31.9k]
  ------------------
 2062|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2063|      0|	}
 2064|       |
 2065|  84.7k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2065:16): [True: 52.8k, False: 31.8k]
  ------------------
 2066|  52.8k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2067|  52.8k|		if (r) {
  ------------------
  |  Branch (2067:7): [True: 62, False: 52.7k]
  ------------------
 2068|     62|			if (obj)
  ------------------
  |  Branch (2068:8): [True: 0, False: 62]
  ------------------
 2069|      0|				free(obj);
 2070|     62|			if (buf)
  ------------------
  |  Branch (2070:8): [True: 19, False: 43]
  ------------------
 2071|     19|				free(buf);
 2072|     62|			return r;
 2073|     62|		}
 2074|       |		/* in case of an empty (optional) element continue with
 2075|       |		 * the next asn1 element */
 2076|  52.7k|		if (!objsize)
  ------------------
  |  Branch (2076:7): [True: 16.5k, False: 36.1k]
  ------------------
 2077|  16.5k|			continue;
 2078|  36.1k|		tmp = (u8 *) realloc(buf, total + objsize);
 2079|  36.1k|		if (!tmp) {
  ------------------
  |  Branch (2079:7): [True: 0, False: 36.1k]
  ------------------
 2080|      0|			if (obj)
  ------------------
  |  Branch (2080:8): [True: 0, False: 0]
  ------------------
 2081|      0|				free(obj);
 2082|      0|			if (buf)
  ------------------
  |  Branch (2082:8): [True: 0, False: 0]
  ------------------
 2083|      0|				free(buf);
 2084|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2085|      0|		}
 2086|  36.1k|		buf = tmp;
 2087|  36.1k|		memcpy(buf + total, obj, objsize);
 2088|  36.1k|		free(obj);
 2089|  36.1k|		obj = NULL;
 2090|  36.1k|		total += objsize;
 2091|  36.1k|	}
 2092|  31.8k|	*ptr = buf;
 2093|  31.8k|	*size = total;
 2094|  31.8k|	return 0;
 2095|  31.9k|}
asn1.c:asn1_encode_entry:
 1843|  52.8k|{
 1844|  52.8k|	void *parm = entry->parm;
 1845|  52.8k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1846|  52.8k|			     size_t *nobjlen, int ndepth);
 1847|  52.8k|	const size_t *len = (const size_t *) entry->arg;
 1848|  52.8k|	int r = 0;
 1849|  52.8k|	u8 * buf = NULL;
 1850|  52.8k|	size_t buflen = 0;
 1851|       |
 1852|  52.8k|	callback_func = parm;
 1853|       |
 1854|  52.8k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|  52.8k|#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)
  |  |  ------------------
  |  |  |  | 1855|  52.8k|	       	depth, depth, "", entry->name,
  |  |  |  | 1856|  52.8k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  171|  52.8k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1855|  52.8k|	       	depth, depth, "", entry->name,
 1856|  52.8k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1857|  52.8k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  171|  52.8k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1857:6): [True: 16.5k, False: 36.2k]
  ------------------
 1858|  16.5k|		goto no_object;
 1859|  36.2k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*stype=%d, tag=0x%02x, parm=%p, len=%zu",
  ------------------
  |  |   70|  72.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 24.3k, False: 11.9k]
  |  |  ------------------
  ------------------
 1860|  36.2k|			depth, depth, "", entry->type, entry->tag, parm, len ? *len : 0);
 1861|       |
 1862|  36.2k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  194|  36.2k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1862:6): [True: 0, False: 36.2k]
  ------------------
 1863|      0|		const struct sc_asn1_entry *list, *choice = NULL;
 1864|       |
 1865|      0|		list = (const struct sc_asn1_entry *) parm;
 1866|      0|		while (list->name != NULL) {
  ------------------
  |  Branch (1866:10): [True: 0, False: 0]
  ------------------
 1867|      0|			if (list->flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1867:8): [True: 0, False: 0]
  ------------------
 1868|      0|				if (choice) {
  ------------------
  |  Branch (1868:9): [True: 0, False: 0]
  ------------------
 1869|      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__
  |  |  ------------------
  ------------------
 1870|      0|						"ASN.1 problem: more than "
 1871|      0|						"one CHOICE when encoding %s: "
 1872|      0|						"%s and %s both present\n",
 1873|      0|						entry->name,
 1874|      0|						choice->name,
 1875|      0|						list->name);
 1876|      0|					return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1877|      0|				}
 1878|      0|				choice = list;
 1879|      0|			}
 1880|      0|			list++;
 1881|      0|		}
 1882|      0|		if (choice == NULL)
  ------------------
  |  Branch (1882:7): [True: 0, False: 0]
  ------------------
 1883|      0|			goto no_object;
 1884|      0|		return asn1_encode_entry(ctx, choice, obj, objlen, depth + 1);
 1885|      0|	}
 1886|       |
 1887|  36.2k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  182|  72.5k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1887:6): [True: 35.1k, False: 1.08k]
  |  Branch (1887:37): [True: 26, False: 35.1k]
  ------------------
 1888|     26|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "unexpected parm == NULL\n");
  ------------------
  |  |   70|     26|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1889|     26|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     26|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1890|     26|	}
 1891|       |
 1892|  36.2k|	switch (entry->type) {
 1893|  3.24k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  193|  3.24k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1893:2): [True: 3.24k, False: 32.9k]
  ------------------
 1894|  3.24k|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1895|  3.24k|				&buflen, depth + 1);
 1896|  3.24k|		break;
 1897|  1.08k|	case SC_ASN1_NULL:
  ------------------
  |  |  182|  1.08k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1897:2): [True: 1.08k, False: 35.1k]
  ------------------
 1898|  1.08k|		buf = NULL;
 1899|  1.08k|		buflen = 0;
 1900|  1.08k|		break;
 1901|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  177|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1901:2): [True: 0, False: 36.2k]
  ------------------
 1902|      0|		buf = malloc(1);
 1903|      0|		if (buf == NULL) {
  ------------------
  |  Branch (1903:7): [True: 0, False: 0]
  ------------------
 1904|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1905|      0|			break;
 1906|      0|		}
 1907|      0|		buf[0] = *((int *) parm) ? 0xFF : 0;
  ------------------
  |  Branch (1907:12): [True: 0, False: 0]
  ------------------
 1908|      0|		buflen = 1;
 1909|      0|		break;
 1910|      0|	case SC_ASN1_INTEGER:
  ------------------
  |  |  178|      0|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1910:2): [True: 0, False: 36.2k]
  ------------------
 1911|      0|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  184|      0|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1911:2): [True: 0, False: 36.2k]
  ------------------
 1912|      0|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1913|      0|		break;
 1914|  2.08k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  180|  2.08k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1914:2): [True: 2.08k, False: 34.1k]
  ------------------
 1915|  2.08k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  179|  2.08k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1915:2): [True: 0, False: 36.2k]
  ------------------
 1916|  2.08k|		if (len != NULL) {
  ------------------
  |  Branch (1916:7): [True: 2.08k, False: 0]
  ------------------
 1917|  2.08k|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  179|  2.08k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1917:8): [True: 0, False: 2.08k]
  ------------------
 1918|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1919|  2.08k|			else
 1920|  2.08k|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1921|  2.08k|		} else {
 1922|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1923|      0|		}
 1924|  2.08k|		break;
 1925|      0|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  195|      0|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1925:2): [True: 0, False: 36.2k]
  ------------------
 1926|      0|		if (len != NULL) {
  ------------------
  |  Branch (1926:7): [True: 0, False: 0]
  ------------------
 1927|      0|			r = encode_bit_field((const u8 *) parm, *len, &buf, &buflen);
 1928|      0|		} else {
 1929|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1930|      0|		}
 1931|      0|		break;
 1932|      0|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  188|      0|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1932:2): [True: 0, False: 36.2k]
  ------------------
 1933|  22.2k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  181|  22.2k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1933:2): [True: 22.2k, False: 14.0k]
  ------------------
 1934|  22.2k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  185|  22.2k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1934:2): [True: 0, False: 36.2k]
  ------------------
 1935|  22.2k|		if (len != NULL) {
  ------------------
  |  Branch (1935:7): [True: 22.2k, False: 0]
  ------------------
 1936|  22.2k|			buf = malloc(*len + 1);
 1937|  22.2k|			if (buf == NULL) {
  ------------------
  |  Branch (1937:8): [True: 0, False: 22.2k]
  ------------------
 1938|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1939|      0|				break;
 1940|      0|			}
 1941|  22.2k|			buflen = 0;
 1942|       |			/* If the integer is supposed to be unsigned, insert
 1943|       |			 * a padding byte if the MSB is one */
 1944|  22.2k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  174|  22.2k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1944:8): [True: 2.27k, False: 19.9k]
  ------------------
 1945|  2.27k|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1945:9): [True: 492, False: 1.78k]
  ------------------
 1946|    492|				buf[buflen++] = 0x00;
 1947|    492|			}
 1948|  22.2k|			memcpy(buf + buflen, parm, *len);
 1949|  22.2k|			buflen += *len;
 1950|  22.2k|		} else {
 1951|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1952|      0|		}
 1953|  22.2k|		break;
 1954|  22.2k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  190|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1954:2): [True: 0, False: 36.2k]
  ------------------
 1955|      0|		if (len != NULL) {
  ------------------
  |  Branch (1955:7): [True: 0, False: 0]
  ------------------
 1956|      0|			buf = malloc(*len);
 1957|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1957:8): [True: 0, False: 0]
  ------------------
 1958|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1959|      0|				break;
 1960|      0|			}
 1961|      0|			memcpy(buf, parm, *len);
 1962|      0|			buflen = *len;
 1963|      0|		} else {
 1964|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1965|      0|		}
 1966|      0|		break;
 1967|  5.50k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  183|  5.50k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1967:2): [True: 5.50k, False: 30.7k]
  ------------------
 1968|  5.50k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1969|  5.50k|		break;
 1970|      0|	case SC_ASN1_PATH:
  ------------------
  |  |  198|      0|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1970:2): [True: 0, False: 36.2k]
  ------------------
 1971|      0|		r = asn1_encode_path(ctx, (const sc_path_t *) parm, &buf, &buflen, depth, entry->flags);
 1972|      0|		break;
 1973|      0|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  199|      0|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1973:2): [True: 0, False: 36.2k]
  ------------------
 1974|      0|		{
 1975|      0|			const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm;
 1976|       |
 1977|      0|			buf = malloc(id->len);
 1978|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1978:8): [True: 0, False: 0]
  ------------------
 1979|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1980|      0|				break;
 1981|      0|			}
 1982|      0|			memcpy(buf, id->value, id->len);
 1983|      0|			buflen = id->len;
 1984|      0|		}
 1985|      0|		break;
 1986|      0|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  200|      0|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1986:2): [True: 0, False: 36.2k]
  ------------------
 1987|      0|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1988|      0|		break;
 1989|  2.08k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  201|  2.08k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1989:2): [True: 2.08k, False: 34.1k]
  ------------------
 1990|  2.08k|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1991|  2.08k|		break;
 1992|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  202|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1992:2): [True: 0, False: 36.2k]
  ------------------
 1993|      0|		if (!len)
  ------------------
  |  Branch (1993:7): [True: 0, False: 0]
  ------------------
 1994|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1995|      0|		r = asn1_encode_se_info(ctx, (struct sc_pkcs15_sec_env_info **)parm, *len, &buf, &buflen, depth);
 1996|      0|		break;
 1997|      0|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  205|      0|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1997:2): [True: 0, False: 36.2k]
  ------------------
 1998|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1999|      0|		break;
 2000|      0|	default:
  ------------------
  |  Branch (2000:2): [True: 0, False: 36.2k]
  ------------------
 2001|      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__
  |  |  ------------------
  ------------------
 2002|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2003|  36.2k|	}
 2004|  36.2k|	if (r) {
  ------------------
  |  Branch (2004:6): [True: 31, False: 36.1k]
  ------------------
 2005|     31|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|     31|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2006|     31|		      sc_strerror(r));
 2007|     31|		if (buf)
  ------------------
  |  Branch (2007:7): [True: 0, False: 31]
  ------------------
 2008|      0|			free(buf);
 2009|     31|		return r;
 2010|     31|	}
 2011|       |
 2012|       |	/* Treatment of OPTIONAL elements:
 2013|       |	 *  -	if the encoding has 0 length, and the element is OPTIONAL,
 2014|       |	 *	we don't write anything (unless it's an ASN1 NULL and the
 2015|       |	 *      SC_ASN1_PRESENT flag is set).
 2016|       |	 *  -	if the encoding has 0 length, but the element is non-OPTIONAL,
 2017|       |	 *	constructed, we write a empty element (e.g. a SEQUENCE of
 2018|       |	 *      length 0). In case of an ASN1 NULL just write the tag and
 2019|       |	 *      length (i.e. 0x05,0x00).
 2020|       |	 *  -	any other empty objects are considered bogus
 2021|       |	 */
 2022|  52.7k|no_object:
 2023|  52.7k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  172|  70.4k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  171|  17.6k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2023:6): [True: 17.6k, False: 35.1k]
  |  Branch (2023:17): [True: 17.6k, False: 5]
  |  Branch (2023:52): [True: 16.5k, False: 1.08k]
  ------------------
 2024|       |		/* This happens when we try to encode e.g. the
 2025|       |		 * subClassAttributes, which may be empty */
 2026|  16.5k|		*obj = NULL;
 2027|  16.5k|		*objlen = 0;
 2028|  16.5k|		r = 0;
 2029|  36.1k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  175|  1.08k|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2029:13): [True: 1.08k, False: 35.1k]
  |  Branch (2029:24): [True: 0, False: 1.08k]
  ------------------
 2030|      0|		*obj = NULL;
 2031|      0|		*objlen = 0;
 2032|      0|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2033|      0|		if (r)
  ------------------
  |  Branch (2033:7): [True: 0, False: 0]
  ------------------
 2034|      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__
  |  |  ------------------
  ------------------
 2035|  36.1k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  182|  37.2k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  165|      5|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2035:13): [True: 35.1k, False: 1.08k]
  |  Branch (2035:23): [True: 1.08k, False: 5]
  |  Branch (2035:54): [True: 0, False: 5]
  ------------------
 2036|  36.1k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2037|  36.1k|		if (r)
  ------------------
  |  Branch (2037:7): [True: 0, False: 36.1k]
  ------------------
 2038|      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__
  |  |  ------------------
  ------------------
 2039|  36.1k|					sc_strerror(r));
 2040|  36.1k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  171|      5|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2040:13): [True: 0, False: 5]
  ------------------
 2041|      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__
  |  |  ------------------
  ------------------
 2042|      0|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2043|      5|	} else {
 2044|      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__
  |  |  ------------------
  ------------------
 2045|      5|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      5|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2046|      5|	}
 2047|  52.7k|	if (buf)
  ------------------
  |  Branch (2047:6): [True: 35.1k, False: 17.6k]
  ------------------
 2048|  35.1k|		free(buf);
 2049|  52.7k|	if (r >= 0)
  ------------------
  |  Branch (2049:6): [True: 52.7k, False: 5]
  ------------------
 2050|  52.7k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*slength of encoded item=%zu", depth, depth, "", *objlen);
  ------------------
  |  |   70|  52.7k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2051|  52.7k|	return r;
 2052|  36.2k|}
asn1.c:encode_bit_string:
  651|  2.08k|{
  652|  2.08k|	const u8 *in = inbuf;
  653|  2.08k|	u8 *out;
  654|  2.08k|	size_t bytes, skipped = 0;
  655|       |
  656|  2.08k|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  145|  2.08k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  657|  2.08k|	*outbuf = out = malloc(bytes);
  658|  2.08k|	if (out == NULL)
  ------------------
  |  Branch (658:6): [True: 0, False: 2.08k]
  ------------------
  659|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  660|  2.08k|	*outlen = bytes;
  661|  2.08k|	out += 1;
  662|   153k|	while (bits_left) {
  ------------------
  |  Branch (662:9): [True: 151k, False: 2.08k]
  ------------------
  663|   151k|		size_t i, bits_to_go = 8;
  664|       |
  665|   151k|		*out = 0;
  666|   151k|		if (bits_left < 8) {
  ------------------
  |  Branch (666:7): [True: 0, False: 151k]
  ------------------
  667|      0|			bits_to_go = bits_left;
  668|      0|			skipped = 8 - bits_left;
  669|      0|		}
  670|   151k|		if (invert) {
  ------------------
  |  Branch (670:7): [True: 0, False: 151k]
  ------------------
  671|      0|			for (i = 0; i < bits_to_go; i++)
  ------------------
  |  Branch (671:16): [True: 0, False: 0]
  ------------------
  672|      0|				*out |= ((*in >> i) & 1) << (7 - i);
  673|   151k|		} else {
  674|   151k|			*out = *in;
  675|   151k|			if (bits_left < 8)
  ------------------
  |  Branch (675:8): [True: 0, False: 151k]
  ------------------
  676|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  677|   151k|		}
  678|   151k|		bits_left -= bits_to_go;
  679|   151k|		out++, in++;
  680|   151k|	}
  681|  2.08k|	out = *outbuf;
  682|  2.08k|	out[0] = skipped;
  683|  2.08k|	return 0;
  684|  2.08k|}

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

sc_get_atrust_acos_driver:
  845|  16.1k|{
  846|  16.1k|	return sc_get_driver();
  847|  16.1k|}
card-atrust-acos.c:sc_get_driver:
  820|  16.1k|{
  821|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  822|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (822:6): [True: 1, False: 16.1k]
  ------------------
  823|      1|		iso_ops = iso_drv->ops;
  824|       |
  825|  16.1k|	atrust_acos_ops = *iso_drv->ops;
  826|  16.1k|	atrust_acos_ops.match_card = atrust_acos_match_card;
  827|  16.1k|	atrust_acos_ops.init   = atrust_acos_init;
  828|  16.1k|	atrust_acos_ops.finish = atrust_acos_finish;
  829|  16.1k|	atrust_acos_ops.select_file = atrust_acos_select_file;
  830|  16.1k|	atrust_acos_ops.check_sw    = atrust_acos_check_sw;
  831|  16.1k|	atrust_acos_ops.create_file = NULL;
  832|  16.1k|	atrust_acos_ops.delete_file = NULL;
  833|  16.1k|	atrust_acos_ops.set_security_env  = atrust_acos_set_security_env;
  834|  16.1k|	atrust_acos_ops.compute_signature = atrust_acos_compute_signature;
  835|  16.1k|	atrust_acos_ops.decipher    = atrust_acos_decipher;
  836|  16.1k|	atrust_acos_ops.card_ctl    = atrust_acos_card_ctl;
  837|  16.1k|	atrust_acos_ops.logout      = atrust_acos_logout;
  838|       |
  839|  16.1k|	return &atrust_acos_drv;
  840|  16.1k|}
card-atrust-acos.c:atrust_acos_match_card:
   76|  15.9k|{
   77|  15.9k|	int		i, match = 0;
   78|       |
   79|       |
   80|  79.2k|	for (i = 0; atrust_acos_atrs[i] != NULL; i++)
  ------------------
  |  Branch (80:14): [True: 63.5k, False: 15.7k]
  ------------------
   81|  63.5k|	{
   82|  63.5k|		u8 defatr[SC_MAX_ATR_SIZE];
   83|  63.5k|		size_t len = sizeof(defatr);
   84|  63.5k|		const char *atrp = atrust_acos_atrs[i];
   85|       |
   86|  63.5k|		if (sc_hex_to_bin(atrp, defatr, &len))
  ------------------
  |  Branch (86:7): [True: 0, False: 63.5k]
  ------------------
   87|      0|			continue;
   88|       |		/* we may only verify part of ATR since */
   89|       |		/* part of the hist chars is variable */
   90|  63.5k|		if (len > card->atr.len)
  ------------------
  |  Branch (90:7): [True: 17.4k, False: 46.0k]
  ------------------
   91|  17.4k|			continue;
   92|  46.0k|		if (memcmp(card->atr.value, defatr, len) != 0)
  ------------------
  |  Branch (92:7): [True: 45.7k, False: 254]
  ------------------
   93|  45.7k|			continue;
   94|       |
   95|    254|		match = 1;
   96|    254|		card->name = atrust_acos_names[i];
   97|       |
   98|    254|		break;
   99|  46.0k|    }
  100|  15.9k|	return match;
  101|  15.9k|}
card-atrust-acos.c:atrust_acos_init:
  106|    254|{
  107|    254|	unsigned int flags;
  108|    254|	atrust_acos_ex_data *ex_data;
  109|       |
  110|    254|	ex_data = calloc(1, sizeof(atrust_acos_ex_data));
  111|    254|	if (ex_data == NULL)
  ------------------
  |  Branch (111:6): [True: 0, False: 254]
  ------------------
  112|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  113|       |
  114|    254|	card->cla  = 0x00;
  115|    254|	card->drv_data = (void *)ex_data;
  116|       |
  117|       |	/* set the supported algorithm */
  118|       |
  119|    254|	flags = SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|    254|#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|    254|#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|    254|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  120|    254|		| SC_ALGORITHM_RSA_HASH_NONE
  ------------------
  |  |  133|    254|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  121|    254|		| SC_ALGORITHM_RSA_HASH_SHA1
  ------------------
  |  |  134|    254|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  122|    254|		| SC_ALGORITHM_RSA_HASH_MD5
  ------------------
  |  |  135|    254|#define SC_ALGORITHM_RSA_HASH_MD5	0x00000400
  ------------------
  123|    254|		| SC_ALGORITHM_RSA_HASH_RIPEMD160
  ------------------
  |  |  137|    254|#define SC_ALGORITHM_RSA_HASH_RIPEMD160	0x00001000
  ------------------
  124|    254|		| SC_ALGORITHM_RSA_HASH_MD5_SHA1;
  ------------------
  |  |  136|    254|#define SC_ALGORITHM_RSA_HASH_MD5_SHA1	0x00000800
  ------------------
  125|       |
  126|    254|	if (card->name != NULL && !strcmp(card->name, ACOS_EMV_A05))
  ------------------
  |  |   37|    254|#define ACOS_EMV_A05		"A-TRUST ACOS A05"
  ------------------
  |  Branch (126:6): [True: 254, False: 0]
  |  Branch (126:28): [True: 150, False: 104]
  ------------------
  127|    150|		flags |= SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  138|    150|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  128|       |
  129|    254|	_sc_card_add_rsa_alg(card, 1536, flags, 0x10001);
  130|       |
  131|       |	/* we need read_binary&friends with max 128 bytes per read */
  132|    254|	card->max_send_size = 128;
  133|    254|	card->max_recv_size = 128;
  134|       |
  135|    254|	return 0;
  136|    254|}
card-atrust-acos.c:atrust_acos_finish:
  141|    254|{
  142|    254|	if (card->drv_data) {
  ------------------
  |  Branch (142:6): [True: 254, False: 0]
  ------------------
  143|    254|		free((atrust_acos_ex_data *)card->drv_data);
  144|       |		card->drv_data = NULL;
  145|    254|	}
  146|    254|	return 0;
  147|    254|}
card-atrust-acos.c:atrust_acos_select_file:
  370|  1.28k|{
  371|  1.28k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  372|  1.28k|	int    r;
  373|  1.28k|	size_t i, pathlen;
  374|       |
  375|  1.28k|	if (in_path == NULL || in_path->len == 0 || in_path->len > sizeof(pathbuf))
  ------------------
  |  Branch (375:6): [True: 0, False: 1.28k]
  |  Branch (375:25): [True: 0, False: 1.28k]
  |  Branch (375:46): [True: 0, False: 1.28k]
  ------------------
  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|       |
  378|  1.28k|	memcpy(path, in_path->value, in_path->len);
  379|  1.28k|	pathlen = in_path->len;
  380|       |
  381|  1.28k|	if (in_path->type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  1.28k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (381:6): [True: 0, False: 1.28k]
  ------------------
  382|       |		/* SELECT EF/DF with ID */
  383|       |		/* Select with 2byte File-ID */
  384|      0|		if (pathlen != 2)
  ------------------
  |  Branch (384:7): [True: 0, False: 0]
  ------------------
  385|      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]
  |  |  ------------------
  ------------------
  386|      0|		return atrust_acos_select_fid(card, path[0], path[1], file_out);
  387|  1.28k|	} else if (in_path->type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  1.28k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (387:13): [True: 503, False: 782]
  ------------------
  388|       |		/* SELECT DF with AID */
  389|       |		/* Select with 1-16byte Application-ID */
  390|    503|		return atrust_acos_select_aid(card, pathbuf, pathlen, file_out);
  391|    782|	} else if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|    782|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (391:13): [True: 782, False: 0]
  ------------------
  392|    782|		u8 n_pathbuf[SC_MAX_PATH_SIZE];
  393|       |
  394|       |		/* Select with path (sequence of File-IDs) */
  395|       |		/* ACOS only supports one
  396|       |		 * level of subdirectories, therefore a path is
  397|       |		 * at most 3 FID long (the last one being the FID
  398|       |		 * of a EF) => pathlen must be even and less than 6
  399|       |		 */
  400|    782|		if (pathlen%2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (400:7): [True: 0, False: 782]
  |  Branch (400:25): [True: 1, False: 781]
  |  Branch (400:40): [True: 0, False: 781]
  ------------------
  401|      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]
  |  |  ------------------
  ------------------
  402|       |		/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  403|    781|		if (pathlen == 6 && ( path[0] != 0x3f || path[1] != 0x00 ))
  ------------------
  |  Branch (403:7): [True: 20, False: 761]
  |  Branch (403:25): [True: 2, False: 18]
  |  Branch (403:44): [True: 1, False: 17]
  ------------------
  404|      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]
  |  |  ------------------
  ------------------
  405|       |
  406|       |		/* unify path (the first FID should be MF) */
  407|    778|		if (path[0] != 0x3f || path[1] != 0x00)
  ------------------
  |  Branch (407:7): [True: 21, False: 757]
  |  Branch (407:26): [True: 1, False: 756]
  ------------------
  408|     22|		{
  409|     22|			n_pathbuf[0] = 0x3f;
  410|     22|			n_pathbuf[1] = 0x00;
  411|     22|			memcpy(n_pathbuf+2, path, pathlen);
  412|     22|			path = n_pathbuf;
  413|     22|			pathlen += 2;
  414|     22|		}
  415|       |
  416|    995|		for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (416:15): [True: 788, False: 207]
  ------------------
  417|    788|			r = atrust_acos_select_fid(card, path[i], path[i + 1], NULL);
  418|    788|			LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) 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: 571, False: 217]
  |  |  |  |  ------------------
  |  |  |  |  169|    571|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    571|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    571|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    571|		return _ret; \
  |  |  |  |  172|    571|	} \
  |  |  |  |  173|    788|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 217]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  419|    788|		}
  420|    207|		return atrust_acos_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
  421|    778|	} else
  422|      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]
  |  |  ------------------
  ------------------
  423|  1.28k|}
card-atrust-acos.c:atrust_acos_select_fid:
  288|    995|{
  289|    995|	sc_apdu_t apdu;
  290|    995|	u8 data[] = {id_hi & 0xff, id_lo & 0xff};
  291|    995|	u8 resp[SC_MAX_APDU_BUFFER_SIZE];
  292|    995|	int bIsDF = 0, r;
  293|       |
  294|       |	/* request FCI to distinguish between EFs and DFs */
  295|    995|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|    995|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  296|    995|	apdu.resp = (u8*)resp;
  297|    995|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    995|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  298|    995|	apdu.le = 256;
  299|    995|	apdu.lc = 2;
  300|    995|	apdu.data = (u8*)data;
  301|    995|	apdu.datalen = 2;
  302|       |
  303|    995|	r = sc_transmit_apdu(card, &apdu);
  304|    995|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    995|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    995|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    995|	int _ret = (r); \
  |  |  |  |  168|    995|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 975]
  |  |  |  |  ------------------
  |  |  |  |  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|    995|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 975]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  305|       |
  306|    975|	if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
  ------------------
  |  Branch (306:6): [True: 975, False: 0]
  |  Branch (306:25): [True: 56, False: 919]
  |  Branch (306:45): [True: 40, False: 16]
  ------------------
  307|       |		/* no FCI => we have a DF (see comment in process_fci()) */
  308|     40|		bIsDF = 1;
  309|     40|		apdu.p2 = 0x0C;
  310|     40|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     40|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  311|     40|		apdu.resplen = 0;
  312|     40|		apdu.le = 0;
  313|     40|		r = sc_transmit_apdu(card, &apdu);
  314|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  315|    935|    	} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)) {
  ------------------
  |  Branch (315:17): [True: 0, False: 935]
  |  Branch (315:38): [True: 408, False: 527]
  |  Branch (315:58): [True: 380, False: 28]
  ------------------
  316|       |		/* SELECT returned some data (possible FCI) =>
  317|       |		 * try a READ BINARY to see if a EF is selected */
  318|    380|		sc_apdu_t apdu2;
  319|    380|		u8 resp2[2];
  320|    380|		sc_format_apdu(card, &apdu2, SC_APDU_CASE_2_SHORT, 0xB0, 0, 0);
  ------------------
  |  |  292|    380|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  321|    380|		apdu2.resp = (u8*)resp2;
  322|    380|		apdu2.resplen = 2;
  323|    380|		apdu2.le = 1;
  324|    380|		apdu2.lc = 0;
  325|    380|		r = sc_transmit_apdu(card, &apdu2);
  326|    380|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    380|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    380|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    380|	int _ret = (r); \
  |  |  |  |  168|    380|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 370]
  |  |  |  |  ------------------
  |  |  |  |  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|    380|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 370]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|    370|		if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86)
  ------------------
  |  Branch (327:7): [True: 39, False: 331]
  |  Branch (327:28): [True: 25, False: 14]
  ------------------
  328|       |			/* no current EF is selected => we have a DF */
  329|     25|			bIsDF = 1;
  330|    370|	}
  331|       |
  332|    955|	if (apdu.sw1 != 0x61 && (apdu.sw1 != 0x90 || apdu.sw2 != 0x00))
  ------------------
  |  Branch (332:6): [True: 955, False: 0]
  |  Branch (332:27): [True: 542, False: 413]
  |  Branch (332:47): [True: 28, False: 385]
  ------------------
  333|    570|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|    570|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    570|	int _ret = r; \
  |  |  155|    570|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 570, False: 0]
  |  |  ------------------
  |  |  156|    570|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    570|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 570, False: 0]
  |  |  ------------------
  |  |  157|    570|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    570|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    570|	return _ret; \
  |  |  163|    570|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  334|       |
  335|    385|	if (file_out) {
  ------------------
  |  Branch (335:6): [True: 156, False: 229]
  ------------------
  336|    156|		sc_file_t *file = sc_file_new();
  337|    156|		if (!file)
  ------------------
  |  Branch (337:7): [True: 0, False: 156]
  ------------------
  338|    156|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  339|    156|		file->id = (id_hi << 8) + id_lo;
  340|       |
  341|    156|		if (bIsDF) {
  ------------------
  |  Branch (341:7): [True: 11, False: 145]
  ------------------
  342|       |			/* we have a DF */
  343|     11|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     11|#define SC_FILE_TYPE_DF			0x04
  ------------------
  344|     11|			file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     11|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  345|     11|			file->size = 0;
  346|     11|			file->namelen = 0;
  347|     11|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|     11|#define SC_FILE_MAGIC			0x14426950
  ------------------
  348|     11|			*file_out = file;
  349|    145|		} else {
  350|       |			/* ok, assume we have a EF */
  351|    145|			r = process_fci(card->ctx, file, apdu.resp,
  352|    145|					apdu.resplen);
  353|    145|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    145|#define SC_SUCCESS				0
  ------------------
  |  Branch (353:8): [True: 33, False: 112]
  ------------------
  354|     33|				sc_file_free(file);
  355|     33|				return r;
  356|     33|			}
  357|       |
  358|    112|			*file_out = file;
  359|    112|		}
  360|    156|	}
  361|       |
  362|    352|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    352|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    352|	int _ret = r; \
  |  |  155|    352|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 352, False: 0]
  |  |  ------------------
  |  |  156|    352|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 352]
  |  |  ------------------
  |  |  157|    352|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    352|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    352|	return _ret; \
  |  |  163|    352|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  363|    352|}
card-atrust-acos.c:process_fci:
  153|    145|{
  154|       |
  155|    145|	size_t taglen, len = buflen;
  156|    145|	const u8 *tag = NULL, *p;
  157|       |
  158|    145|	sc_log(ctx,  "processing FCI bytes\n");
  ------------------
  |  |   71|    145|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  159|       |
  160|    145|	if (buflen < 2)
  ------------------
  |  Branch (160:6): [True: 16, False: 129]
  ------------------
  161|     16|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     16|#define SC_ERROR_INTERNAL			-1400
  ------------------
  162|    129|	if (buf[0] != 0x6f)					/* FCI template */
  ------------------
  |  Branch (162:6): [True: 10, False: 119]
  ------------------
  163|     10|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     10|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  164|    119|	len = (size_t)buf[1];
  165|    119|	if (buflen - 2 < len)
  ------------------
  |  Branch (165:6): [True: 7, False: 112]
  ------------------
  166|      7|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      7|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  167|    112|	p = buf + 2;
  168|       |
  169|       |	/* defaults */
  170|    112|	file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    112|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  171|    112|	file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|    112|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  172|    112|	file->shareable = 0;
  173|    112|	file->record_length = 0;
  174|    112|	file->size = 0;
  175|       |
  176|       |	/* get file size */
  177|    112|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
  178|    112|	if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (178:6): [True: 23, False: 89]
  |  Branch (178:21): [True: 15, False: 8]
  ------------------
  179|     15|		int bytes = (tag[0] << 8) + tag[1];
  180|     15|		sc_log(ctx,  "  bytes in file: %d\n", bytes);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  181|     15|		file->size = bytes;
  182|     15|	}
  183|       |
  184|       |	/* get file type */
  185|    112|  	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
  186|    112|	if (tag != NULL) {
  ------------------
  |  Branch (186:6): [True: 41, False: 71]
  ------------------
  187|     41|		const char *type = "unknown";
  188|     41|		const char *structure = "unknown";
  189|       |
  190|     41|		if (taglen == 1 && tag[0] == 0x01) {
  ------------------
  |  Branch (190:7): [True: 25, False: 16]
  |  Branch (190:22): [True: 6, False: 19]
  ------------------
  191|       |			/* transparent EF */
  192|      6|			type = "working EF";
  193|      6|			structure = "transparent";
  194|      6|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      6|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  195|      6|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|      6|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  196|     35|		} else if (taglen == 1 && tag[0] == 0x11) {
  ------------------
  |  Branch (196:14): [True: 19, False: 16]
  |  Branch (196:29): [True: 6, False: 13]
  ------------------
  197|       |			/* object EF */
  198|      6|			type = "working EF";
  199|      6|			structure = "object";
  200|      6|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      6|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  201|      6|			file->ef_structure = SC_FILE_EF_TRANSPARENT; /* TODO */
  ------------------
  |  |  221|      6|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  202|     29|		} else if (taglen == 3 && tag[1] == 0x21) {
  ------------------
  |  Branch (202:14): [True: 7, False: 22]
  |  Branch (202:29): [True: 4, False: 3]
  ------------------
  203|      4|			type = "working EF";
  204|      4|			file->record_length = tag[2];
  205|      4|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      4|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  206|       |			/* linear fixed, cyclic or compute */
  207|      4|			switch ( tag[0] )
  208|      4|			{
  209|      1|				case 0x02:
  ------------------
  |  Branch (209:5): [True: 1, False: 3]
  ------------------
  210|      1|					structure = "linear fixed";
  211|      1|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|      1|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  212|      1|					break;
  213|      1|				case 0x07:
  ------------------
  |  Branch (213:5): [True: 1, False: 3]
  ------------------
  214|      1|					structure = "cyclic";
  215|      1|					file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|      1|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  216|      1|					break;
  217|      1|				case 0x17:
  ------------------
  |  Branch (217:5): [True: 1, False: 3]
  ------------------
  218|      1|					structure = "compute";
  219|      1|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      1|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  220|      1|					break;
  221|      1|				default:
  ------------------
  |  Branch (221:5): [True: 1, False: 3]
  ------------------
  222|      1|					structure = "unknown";
  223|      1|					file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      1|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  224|      1|					file->record_length = 0;
  225|      1|					break;
  226|      4|			}
  227|      4|		}
  228|       |
  229|     41|	 	sc_log(ctx,  "  type: %s\n", type);
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  230|     41|		sc_log(ctx,  "  EF structure: %s\n", structure);
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|     41|	}
  232|    112|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    112|#define SC_FILE_MAGIC			0x14426950
  ------------------
  233|       |
  234|    112|	return SC_SUCCESS;
  ------------------
  |  |   28|    112|#define SC_SUCCESS				0
  ------------------
  235|    112|}
card-atrust-acos.c:atrust_acos_select_aid:
  243|    503|{
  244|    503|	sc_apdu_t apdu;
  245|    503|	int r;
  246|    503|	size_t i = 0;
  247|       |
  248|    503|	if (aid == NULL || len == 0 || len > 16)
  ------------------
  |  Branch (248:6): [True: 0, False: 503]
  |  Branch (248:21): [True: 0, False: 503]
  |  Branch (248:33): [True: 0, False: 503]
  ------------------
  249|      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]
  |  |  ------------------
  ------------------
  250|       |
  251|    503|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x04, 0x0C);
  ------------------
  |  |  293|    503|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  252|    503|	apdu.lc = (u8)len;
  253|    503|	apdu.data = (u8*)aid;
  254|    503|	apdu.datalen = len;
  255|    503|	apdu.resplen = 0;
  256|    503|	apdu.le = 0;
  257|    503|	r = sc_transmit_apdu(card, &apdu);
  258|    503|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 9, False: 494]
  |  |  |  |  ------------------
  |  |  |  |  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|    503|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 494]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|       |
  260|       |	/* check return value */
  261|    494|	if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61)
  ------------------
  |  Branch (261:8): [True: 66, False: 428]
  |  Branch (261:28): [True: 59, False: 7]
  |  Branch (261:49): [True: 435, False: 0]
  ------------------
  262|    435|    		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|    435|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 435, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  263|       |
  264|     59|	if (file_out) {
  ------------------
  |  Branch (264:6): [True: 0, False: 59]
  ------------------
  265|      0|		sc_file_t *file = sc_file_new();
  266|      0|		if (!file)
  ------------------
  |  Branch (266:7): [True: 0, False: 0]
  ------------------
  267|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  269|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  270|      0|		file->path.len = 0;
  271|      0|		file->size = 0;
  272|       |		/* AID */
  273|      0|		for (i = 0; i < len; i++)
  ------------------
  |  Branch (273:15): [True: 0, False: 0]
  ------------------
  274|      0|			file->name[i] = aid[i];
  275|      0|		file->namelen = len;
  276|      0|		file->id = 0x0000;
  277|      0|		file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  278|      0|		*file_out = file;
  279|      0|	}
  280|     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]
  |  |  ------------------
  ------------------
  281|     59|}
card-atrust-acos.c:atrust_acos_check_sw:
  724|  1.63k|{
  725|       |
  726|  1.63k|	sc_log(card->ctx,  "sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  ------------------
  |  |   71|  1.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  727|       |
  728|  1.63k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (728:6): [True: 480, False: 1.15k]
  |  Branch (728:21): [True: 419, False: 61]
  ------------------
  729|    419|		return SC_SUCCESS;
  ------------------
  |  |   28|    419|#define SC_SUCCESS				0
  ------------------
  730|  1.21k|	if (sw1 == 0x63 && (sw2 & ~0x0fU) == 0xc0 )
  ------------------
  |  Branch (730:6): [True: 23, False: 1.18k]
  |  Branch (730:21): [True: 10, False: 13]
  ------------------
  731|     10|	{
  732|     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__
  |  |  ------------------
  ------------------
  733|     10|		(sw2 & 0x0f));
  734|     10|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     10|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  735|     10|	}
  736|       |
  737|       |	/* iso error */
  738|  1.20k|	return iso_ops->check_sw(card, sw1, sw2);
  739|  1.21k|}
card-atrust-acos.c:atrust_acos_card_ctl:
  779|     19|{
  780|       |
  781|     19|	switch (cmd)
  782|     19|	{
  783|     19|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (783:2): [True: 19, False: 0]
  ------------------
  784|     19|		return acos_get_serialnr(card, (sc_serial_number_t *)ptr);
  785|      0|	default:
  ------------------
  |  Branch (785:2): [True: 0, False: 19]
  ------------------
  786|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  787|     19|	}
  788|     19|}
card-atrust-acos.c:acos_get_serialnr:
  744|     19|{
  745|     19|	int r;
  746|     19|	u8  rbuf[SC_MAX_APDU_BUFFER_SIZE];
  747|     19|	sc_apdu_t apdu;
  748|       |
  749|     19|	if (!serial)
  ------------------
  |  Branch (749:6): [True: 0, False: 19]
  ------------------
  750|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  751|       |	/* see if we have cached serial number */
  752|     19|	if (card->serialnr.len) {
  ------------------
  |  Branch (752:6): [True: 0, False: 19]
  ------------------
  753|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  754|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  755|      0|	}
  756|       |	/* get serial number via GET CARD DATA */
  757|     19|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xf6, 0x00, 0x00);
  ------------------
  |  |  292|     19|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  758|     19|	apdu.cla |= 0x80;
  759|     19|	apdu.resp = rbuf;
  760|     19|	apdu.resplen = sizeof(rbuf);
  761|     19|	apdu.le   = 256;
  762|     19|	apdu.lc   = 0;
  763|     19|	apdu.datalen = 0;
  764|     19|        r = sc_transmit_apdu(card, &apdu);
  765|     19|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  766|     17|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (766:6): [True: 8, False: 9]
  |  Branch (766:26): [True: 1, False: 8]
  ------------------
  767|      9|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      9|#define SC_ERROR_INTERNAL			-1400
  ------------------
  768|       |	/* cache serial number */
  769|      8|	memcpy(card->serialnr.value, apdu.resp, MIN(apdu.resplen, SC_MAX_SERIALNR));
  ------------------
  |  |   69|      8|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 7, False: 1]
  |  |  ------------------
  ------------------
  770|      8|	card->serialnr.len = MIN(apdu.resplen, SC_MAX_SERIALNR);
  ------------------
  |  |   69|      8|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 7, False: 1]
  |  |  ------------------
  ------------------
  771|       |	/* copy and return serial number */
  772|      8|	memcpy(serial, &card->serialnr, sizeof(*serial));
  773|      8|	return SC_SUCCESS;
  ------------------
  |  |   28|      8|#define SC_SUCCESS				0
  ------------------
  774|     17|}

sc_get_authentic_driver:
 2183|  16.1k|{
 2184|  16.1k|	return sc_get_driver();
 2185|  16.1k|}
card-authentic.c:sc_get_driver:
 2148|  16.1k|{
 2149|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2150|       |
 2151|  16.1k|	if (!iso_ops)
  ------------------
  |  Branch (2151:6): [True: 1, False: 16.1k]
  ------------------
 2152|      1|		iso_ops = iso_drv->ops;
 2153|       |
 2154|  16.1k|	authentic_ops = *iso_ops;
 2155|       |
 2156|  16.1k|	authentic_ops.match_card = authentic_match_card;
 2157|  16.1k|	authentic_ops.init = authentic_init;
 2158|  16.1k|	authentic_ops.finish = authentic_finish;
 2159|  16.1k|	authentic_ops.read_binary = authentic_read_binary;
 2160|  16.1k|	authentic_ops.write_binary = authentic_write_binary;
 2161|  16.1k|	authentic_ops.update_binary = authentic_update_binary;
 2162|  16.1k|	authentic_ops.erase_binary = authentic_erase_binary;
 2163|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2164|  16.1k|	authentic_ops.select_file = authentic_select_file;
 2165|       |	/* get_response: Untested */
 2166|  16.1k|	authentic_ops.get_challenge = authentic_get_challenge;
 2167|  16.1k|	authentic_ops.set_security_env = authentic_set_security_env;
 2168|       |	/* decipher: Untested */
 2169|  16.1k|	authentic_ops.decipher = authentic_decipher;
 2170|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2171|  16.1k|	authentic_ops.create_file = authentic_create_file;
 2172|  16.1k|	authentic_ops.delete_file = authentic_delete_file;
 2173|  16.1k|	authentic_ops.card_ctl = authentic_card_ctl;
 2174|  16.1k|	authentic_ops.process_fci = authentic_process_fci;
 2175|  16.1k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2176|  16.1k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2177|       |
 2178|  16.1k|	return &authentic_drv;
 2179|  16.1k|}
card-authentic.c:authentic_match_card:
  396|  11.0k|{
  397|  11.0k|	struct sc_context *ctx = card->ctx;
  398|  11.0k|	int i;
  399|       |
  400|  11.0k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  11.0k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  11.0k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  401|  11.0k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  402|  11.0k|	if (i < 0)   {
  ------------------
  |  Branch (402:6): [True: 10.6k, False: 334]
  ------------------
  403|  10.6k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
  404|  10.6k|		return 0;
  405|  10.6k|	}
  406|       |
  407|    334|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  408|    334|	return 1;
  409|  11.0k|}
card-authentic.c:authentic_init:
  448|    334|{
  449|    334|	struct sc_context *ctx = card->ctx;
  450|    334|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    334|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  451|       |
  452|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|    334|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (453:11): [True: 334, False: 0]
  ------------------
  454|    334|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (454:7): [True: 334, False: 0]
  ------------------
  455|    334|			card->name = authentic_known_atrs[ii].name;
  456|    334|			card->flags = authentic_known_atrs[ii].flags;
  457|    334|			break;
  458|    334|		}
  459|    334|	}
  460|       |
  461|    334|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (461:6): [True: 0, False: 334]
  ------------------
  462|    334|		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|    334|	card->cla  = 0x00;
  465|    334|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  466|    334|	if (!card->drv_data)
  ------------------
  |  Branch (466:6): [True: 0, False: 334]
  ------------------
  467|    334|		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|    334|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (469:6): [True: 334, False: 0]
  ------------------
  470|    334|		rv = authentic_init_oberthur_authentic_3_2(card);
  471|       |
  472|    334|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    334|#define SC_SUCCESS				0
  ------------------
  |  Branch (472:6): [True: 161, False: 173]
  ------------------
  473|    161|		rv = authentic_get_serialnr(card, NULL);
  474|       |
  475|    334|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    334|#define SC_SUCCESS				0
  ------------------
  |  Branch (475:6): [True: 33, False: 301]
  ------------------
  476|     33|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     33|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  477|       |
  478|       |	/* Free private data on error */
  479|    334|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    334|#define SC_SUCCESS				0
  ------------------
  |  Branch (479:6): [True: 33, False: 301]
  ------------------
  480|     33|		free(card->drv_data);
  481|     33|		card->drv_data = NULL;
  482|     33|	}
  483|    334|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    334|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    334|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    334|	int _ret = r; \
  |  |  |  |  155|    334|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 334, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    334|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 301]
  |  |  |  |  ------------------
  |  |  |  |  157|    334|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    334|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    334|	return _ret; \
  |  |  |  |  163|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|    334|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  414|    334|{
  415|    334|	struct sc_context *ctx = card->ctx;
  416|    334|	unsigned int flags;
  417|    334|	int rv = 0;
  418|       |
  419|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|       |
  421|    334|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    334|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    334|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    334|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    334|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    334|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    334|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    334|#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|    334|#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|    334|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    334|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    334|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    334|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    334|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    334|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    334|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  422|       |
  423|    334|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    334|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  424|    334|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    334|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  425|    334|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    334|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  426|       |
  427|    334|#ifdef ENABLE_SM
  428|    334|	card->sm_ctx.ops.open = authentic_sm_open;
  429|    334|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  430|    334|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  431|    334|#endif
  432|       |
  433|    334|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  434|    334|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  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: 144, False: 190]
  |  |  |  |  ------------------
  |  |  |  |  169|    144|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    144|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    144|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    144|		return _ret; \
  |  |  |  |  172|    144|	} \
  |  |  |  |  173|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 190]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  435|       |
  436|    190|	rv = authentic_select_mf(card, NULL);
  437|    190|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    190|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    190|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    190|	int _ret = (r); \
  |  |  |  |  168|    190|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  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|    190|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 173]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|       |
  439|    173|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  440|    173|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  441|       |
  442|    173|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    173|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    173|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    173|	int _ret = r; \
  |  |  |  |  155|    173|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 173, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    173|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  157|    173|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    173|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    173|	return _ret; \
  |  |  |  |  163|    173|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  443|    173|}
card-authentic.c:authentic_select_mf:
  550|    190|{
  551|    190|	struct sc_context *ctx = card->ctx;
  552|    190|	struct sc_path mfpath;
  553|    190|	int rv;
  554|       |
  555|    190|	struct sc_apdu apdu;
  556|    190|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  557|       |
  558|    190|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    190|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    190|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    190|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    190|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 190]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|       |
  560|    190|	sc_format_path("3F00", &mfpath);
  561|    190|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    190|#define SC_PATH_TYPE_PATH		2
  ------------------
  562|       |
  563|    190|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|    190|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  564|       |
  565|    190|	apdu.resp = rbuf;
  566|    190|	apdu.resplen = sizeof(rbuf);
  567|       |
  568|    190|	rv = sc_transmit_apdu(card, &apdu);
  569|    190|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    190|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    190|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    190|	int _ret = (r); \
  |  |  |  |  168|    190|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 188]
  |  |  |  |  ------------------
  |  |  |  |  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|    190|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 188]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  570|    188|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  571|    188|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|    188|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    188|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    188|	int _ret = (r); \
  |  |  |  |  168|    188|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 184]
  |  |  |  |  ------------------
  |  |  |  |  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|    188|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 184]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  572|       |
  573|    184|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  574|    184|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    184|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    184|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    184|	int _ret = (r); \
  |  |  |  |  168|    184|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  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|    184|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 173]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  575|       |
  576|    173|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    173|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    173|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    173|	int _ret = r; \
  |  |  |  |  155|    173|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 173, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    173|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 173]
  |  |  |  |  ------------------
  |  |  |  |  157|    173|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    173|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    173|	return _ret; \
  |  |  |  |  163|    173|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  577|    173|}
card-authentic.c:authentic_set_current_files:
  511|    896|{
  512|    896|	struct sc_context *ctx = card->ctx;
  513|    896|	struct sc_file *file = NULL;
  514|    896|	int rv;
  515|       |
  516|    896|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    896|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    896|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    896|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    896|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 896]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  517|    896|	if (resplen)   {
  ------------------
  |  Branch (517:6): [True: 320, False: 576]
  ------------------
  518|    320|		switch (resp[0]) {
  519|     60|		case 0x62:
  ------------------
  |  Branch (519:3): [True: 60, False: 260]
  ------------------
  520|    227|		case 0x6F:
  ------------------
  |  Branch (520:3): [True: 167, False: 153]
  ------------------
  521|    227|			file = sc_file_new();
  522|    227|			if (file == NULL)
  ------------------
  |  Branch (522:8): [True: 0, False: 227]
  ------------------
  523|    227|				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|    227|			if (path)
  ------------------
  |  Branch (524:8): [True: 227, False: 0]
  ------------------
  525|    227|				file->path = *path;
  526|       |
  527|    227|			rv = authentic_process_fci(card, file, resp, resplen);
  528|    227|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    227|#define SC_SUCCESS				0
  ------------------
  |  Branch (528:8): [True: 32, False: 195]
  ------------------
  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|    195|			break;
  534|    195|		default:
  ------------------
  |  Branch (534:3): [True: 93, False: 227]
  ------------------
  535|     93|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     93|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     93|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     93|	int _ret = r; \
  |  |  |  |  155|     93|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 93, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     93|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     93|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 93, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     93|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     93|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     93|	return _ret; \
  |  |  |  |  163|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    320|		}
  537|       |
  538|    195|		if (file_out)
  ------------------
  |  Branch (538:7): [True: 78, False: 117]
  ------------------
  539|     78|			*file_out = file;
  540|    117|		else
  541|    117|			sc_file_free(file);
  542|    195|	}
  543|       |
  544|    771|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    771|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    771|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    771|	int _ret = r; \
  |  |  |  |  155|    771|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 771, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    771|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 771]
  |  |  |  |  ------------------
  |  |  |  |  157|    771|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    771|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    771|	return _ret; \
  |  |  |  |  163|    771|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  545|    771|}
card-authentic.c:authentic_get_serialnr:
 1473|    337|{
 1474|    337|	struct sc_context *ctx = card->ctx;
 1475|    337|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1476|    337|	int rv;
 1477|       |
 1478|    337|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    337|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    337|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    337|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    337|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 337]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1479|    337|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1479:6): [True: 244, False: 93]
  ------------------
 1480|    244|		rv = authentic_get_cplc(card);
 1481|    244|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  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: 94, False: 150]
  |  |  |  |  ------------------
  |  |  |  |  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|    244|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1482|       |
 1483|    150|		card->serialnr.len = 4;
 1484|    150|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1485|       |
 1486|    150|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   71|    150|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1487|    150|				card->serialnr.value[0], card->serialnr.value[1],
 1488|    150|				card->serialnr.value[2], card->serialnr.value[3]);
 1489|    150|	}
 1490|       |
 1491|    243|	if (serial)
  ------------------
  |  Branch (1491:6): [True: 115, False: 128]
  ------------------
 1492|    115|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1493|       |
 1494|    243|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    243|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    243|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    243|	int _ret = r; \
  |  |  |  |  155|    243|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 243, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    243|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 243]
  |  |  |  |  ------------------
  |  |  |  |  157|    243|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    243|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    243|	return _ret; \
  |  |  |  |  163|    243|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1495|    243|}
card-authentic.c:authentic_get_cplc:
  366|    244|{
  367|    244|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  368|    244|	struct sc_apdu apdu;
  369|    244|	int rv, ii;
  370|    244|	unsigned char p1, p2;
  371|       |
  372|    244|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  346|    244|#define SC_CPLC_TAG		0x9F7F
  ------------------
  373|    244|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  346|    244|#define SC_CPLC_TAG		0x9F7F
  ------------------
  374|    244|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    244|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  375|    247|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (375:12): [True: 246, False: 1]
  ------------------
  376|    246|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  347|    246|#define SC_CPLC_DER_SIZE	45
  ------------------
  377|    246|		apdu.resplen = sizeof(prv_data->cplc.value);
  378|    246|		apdu.resp = prv_data->cplc.value;
  379|       |
  380|    246|		rv = sc_transmit_apdu(card, &apdu);
  381|    246|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    246|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    246|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    246|	int _ret = (r); \
  |  |  |  |  168|    246|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 13, False: 233]
  |  |  |  |  ------------------
  |  |  |  |  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|    246|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 233]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|    233|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  383|    233|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    233|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (383:7): [True: 230, False: 3]
  ------------------
  384|    230|			break;
  385|       |
  386|      3|		apdu.cla = 0x80;
  387|      3|	}
  388|    231|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    231|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    231|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    231|	int _ret = (r); \
  |  |  |  |  168|    231|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 150]
  |  |  |  |  ------------------
  |  |  |  |  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|    231|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  389|       |
  390|    150|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  347|    150|#define SC_CPLC_DER_SIZE	45
  ------------------
  391|    150|	return SC_SUCCESS;
  ------------------
  |  |   28|    150|#define SC_SUCCESS				0
  ------------------
  392|    231|}
card-authentic.c:authentic_finish:
 1881|    301|{
 1882|    301|	struct sc_context *ctx = card->ctx;
 1883|       |
 1884|    301|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    301|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    301|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    301|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    301|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 301]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1885|       |
 1886|    301|#ifdef ENABLE_SM
 1887|    301|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1887:6): [True: 0, False: 301]
  ------------------
 1888|      0|		card->sm_ctx.ops.close(card);
 1889|    301|#endif
 1890|       |
 1891|    301|	if (card->drv_data)
  ------------------
  |  Branch (1891:6): [True: 301, False: 0]
  ------------------
 1892|    301|		free(card->drv_data);
 1893|    301|	card->drv_data = NULL;
 1894|    301|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    301|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    301|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    301|	int _ret = r; \
  |  |  |  |  155|    301|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 301, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    301|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 301]
  |  |  |  |  ------------------
  |  |  |  |  157|    301|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    301|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    301|	return _ret; \
  |  |  |  |  163|    301|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1895|    301|}
card-authentic.c:authentic_read_binary:
  649|    240|{
  650|    240|	struct sc_context *ctx = card->ctx;
  651|    240|	struct sc_apdu apdu;
  652|    240|	size_t sz, rest, ret_count = 0;
  653|    240|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    240|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  654|       |
  655|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  656|    240|	sc_log(ctx, "offs:%i,count:%zu,max_recv_size:%zu", idx, count, card->max_recv_size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  657|       |
  658|    240|	rest = count;
  659|  2.44k|	while(rest)   {
  ------------------
  |  Branch (659:8): [True: 2.21k, False: 234]
  ------------------
  660|  2.21k|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (660:8): [True: 1.98k, False: 234]
  ------------------
  661|  2.21k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|  2.21k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  662|  2.21k|		apdu.le = sz;
  663|  2.21k|		apdu.resplen = sz;
  664|  2.21k|		apdu.resp = (buf + ret_count);
  665|       |
  666|  2.21k|		rv = sc_transmit_apdu(card, &apdu);
  667|  2.21k|		if(!rv)
  ------------------
  |  Branch (667:6): [True: 2.20k, False: 6]
  ------------------
  668|  2.20k|			ret_count += apdu.resplen;
  669|      6|		else
  670|      6|			break;
  671|       |
  672|  2.20k|		idx += sz;
  673|  2.20k|		rest -= sz;
  674|  2.20k|	}
  675|       |
  676|    240|	if (rv)   {
  ------------------
  |  Branch (676:6): [True: 6, False: 234]
  ------------------
  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|    234|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  682|    234|	if (!rv)
  ------------------
  |  Branch (682:6): [True: 205, False: 29]
  ------------------
  683|    205|		count = ret_count;
  684|       |
  685|    234|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    234|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    234|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    234|	int _ret = (r); \
  |  |  |  |  168|    234|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 205]
  |  |  |  |  ------------------
  |  |  |  |  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|    234|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 205]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  686|    205|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  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: 7, False: 198]
  |  |  |  |  ------------------
  |  |  |  |  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|    198|	} else { \
  |  |  |  |  159|    198|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    198|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    198|	} \
  |  |  |  |  162|    205|	return _ret; \
  |  |  |  |  163|    205|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  687|    205|}
card-authentic.c:authentic_select_file:
  582|  1.91k|{
  583|  1.91k|	struct sc_context *ctx = card->ctx;
  584|  1.91k|	struct sc_apdu apdu;
  585|  1.91k|	struct sc_path lpath;
  586|  1.91k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  587|  1.91k|	size_t pathlen;
  588|  1.91k|	int rv;
  589|       |
  590|  1.91k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.91k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.91k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.91k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.91k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.91k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  591|       |
  592|  1.91k|	memcpy(&lpath, path, sizeof(struct sc_path));
  593|       |
  594|  1.91k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  3.83k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (594:6): [True: 1.15k, False: 768]
  |  Branch (594:41): [True: 243, False: 907]
  ------------------
  595|    243|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    243|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  596|       |
  597|  1.91k|	pathlen = lpath.len;
  598|  1.91k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.91k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  599|       |
  600|  1.91k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (600:6): [True: 0, False: 1.91k]
  ------------------
  601|  1.91k|		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.91k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  1.91k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (603:6): [True: 243, False: 1.67k]
  ------------------
  604|    243|		apdu.p1 = 0x00;
  605|    243|	}
  606|  1.67k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.67k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (606:11): [True: 907, False: 768]
  ------------------
  607|    907|		apdu.p1 = 0x08;
  608|    907|	}
  609|    768|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    768|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (609:11): [True: 0, False: 768]
  ------------------
  610|      0|		apdu.p1 = 0x09;
  611|      0|	}
  612|    768|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    768|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (612:11): [True: 768, False: 0]
  ------------------
  613|    768|		apdu.p1 = 4;
  614|    768|	}
  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.91k|	apdu.lc = pathlen;
  626|  1.91k|	apdu.data = lpath.value;
  627|  1.91k|	apdu.datalen = pathlen;
  628|       |
  629|  1.91k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  3.83k|#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.91k, False: 0]
  |  Branch (629:42): [True: 0, False: 0]
  ------------------
  630|  1.91k|		apdu.resp = rbuf;
  631|  1.91k|		apdu.resplen = sizeof(rbuf);
  632|  1.91k|		apdu.le = 256;
  633|  1.91k|	}
  634|       |
  635|  1.91k|	rv = sc_transmit_apdu(card, &apdu);
  636|  1.91k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.91k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.91k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.91k|	int _ret = (r); \
  |  |  |  |  168|  1.91k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 1.89k]
  |  |  |  |  ------------------
  |  |  |  |  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.91k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.89k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  637|  1.89k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  638|  1.89k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  1.89k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.89k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.89k|	int _ret = (r); \
  |  |  |  |  168|  1.89k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.17k, False: 712]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.17k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.17k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.17k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.17k|		return _ret; \
  |  |  |  |  172|  1.17k|	} \
  |  |  |  |  173|  1.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 712]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  639|       |
  640|    712|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  641|    712|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    712|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    712|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    712|	int _ret = (r); \
  |  |  |  |  168|    712|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 114, False: 598]
  |  |  |  |  ------------------
  |  |  |  |  169|    114|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    114|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    114|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    114|		return _ret; \
  |  |  |  |  172|    114|	} \
  |  |  |  |  173|    712|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 598]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  642|       |
  643|    598|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    598|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    598|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    598|	int _ret = r; \
  |  |  |  |  155|    598|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 598, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    598|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 598]
  |  |  |  |  ------------------
  |  |  |  |  157|    598|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    598|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    598|	return _ret; \
  |  |  |  |  163|    598|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|    598|}
card-authentic.c:authentic_set_security_env:
 1799|    404|{
 1800|    404|	struct sc_context *ctx = card->ctx;
 1801|    404|	struct sc_apdu apdu;
 1802|    404|	unsigned char cse_crt_dst[] = {
 1803|    404|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|    404|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1804|    404|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|    404|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1805|    404|	};
 1806|    404|	unsigned char cse_crt_ct[] = {
 1807|    404|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|    404|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1808|    404|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|    404|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1809|    404|	};
 1810|    404|	int rv;
 1811|       |
 1812|    404|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    404|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    404|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    404|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    404|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 404]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1813|    404|	sc_log(ctx, "set SE#%i(op:0x%X,algo:0x%lX,algo_ref:0x%lX,flags:0x%lX), key_ref:0x%X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1814|    404|			se_num, env->operation, env->algorithm, env->algorithm_ref, env->algorithm_flags, env->key_ref[0]);
 1815|    404|	switch (env->operation)  {
 1816|    340|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    340|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1816:2): [True: 340, False: 64]
  ------------------
 1817|    340|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_DST);
  ------------------
  |  |  293|    340|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_DST);
  ------------------
  |  |  109|    340|#define AUTHENTIC_TAG_CRT_DST	0xB6
  ------------------
 1818|    340|		apdu.data = cse_crt_dst;
 1819|    340|		apdu.datalen = sizeof(cse_crt_dst);
 1820|    340|		apdu.lc = sizeof(cse_crt_dst);
 1821|    340|		break;
 1822|     64|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     64|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1822:2): [True: 64, False: 340]
  ------------------
 1823|     64|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  293|     64|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  110|     64|#define AUTHENTIC_TAG_CRT_CT	0xB8
  ------------------
 1824|     64|		apdu.data = cse_crt_ct;
 1825|     64|		apdu.datalen = sizeof(cse_crt_ct);
 1826|     64|		apdu.lc = sizeof(cse_crt_ct);
 1827|     64|		break;
 1828|      0|	default:
  ------------------
  |  Branch (1828:2): [True: 0, False: 404]
  ------------------
 1829|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1830|    404|	}
 1831|       |
 1832|    404|	rv = sc_transmit_apdu(card, &apdu);
 1833|    404|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  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: 20, False: 384]
  |  |  |  |  ------------------
  |  |  |  |  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|    404|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 384]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1834|    384|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1835|    384|	LOG_TEST_RET(ctx, rv, "MSE restore error");
  ------------------
  |  |  174|    384|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    384|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    384|	int _ret = (r); \
  |  |  |  |  168|    384|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 232, False: 152]
  |  |  |  |  ------------------
  |  |  |  |  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|    384|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 152]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1836|       |
 1837|    152|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    152|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    152|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    152|	int _ret = r; \
  |  |  |  |  155|    152|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 152, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    152|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 152]
  |  |  |  |  ------------------
  |  |  |  |  157|    152|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    152|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    152|	return _ret; \
  |  |  |  |  163|    152|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1838|    152|}
card-authentic.c:authentic_decipher:
 1844|     34|{
 1845|     34|	struct sc_context *ctx = card->ctx;
 1846|     34|	struct sc_apdu apdu;
 1847|     34|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1848|     34|	int rv;
 1849|       |
 1850|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|     34|	sc_log(ctx, "crgram_len %zu;  outlen %zu", in_len, out_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1852|     34|	if (!out || !out_len || in_len > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|     34|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1852:6): [True: 0, False: 34]
  |  Branch (1852:14): [True: 0, False: 34]
  |  Branch (1852:26): [True: 3, False: 31]
  ------------------
 1853|     34|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1854|       |
 1855|     31|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     31|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1856|     31|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     31|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1857|     31|	apdu.data = in;
 1858|     31|	apdu.datalen = in_len;
 1859|     31|	apdu.lc = in_len;
 1860|     31|	apdu.resp = resp;
 1861|     31|	apdu.resplen = sizeof(resp);
 1862|     31|	apdu.le = 256;
 1863|       |
 1864|     31|	rv = sc_transmit_apdu(card, &apdu);
 1865|     31|	LOG_TEST_RET(ctx, rv, "APDU transmit 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: 3, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  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|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1866|     28|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1867|     28|	LOG_TEST_RET(ctx, rv, "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: 8, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  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|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1868|       |
 1869|     20|	if (out_len > apdu.resplen)
  ------------------
  |  Branch (1869:6): [True: 20, False: 0]
  ------------------
 1870|     20|		out_len = apdu.resplen;
 1871|       |
 1872|     20|	memcpy(out, apdu.resp, out_len);
 1873|     20|	rv = (int)out_len;
 1874|       |
 1875|     20|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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: 11, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|      9|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      9|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      9|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1876|     20|}
card-authentic.c:authentic_card_ctl:
 1772|    176|{
 1773|    176|	struct sc_context *ctx = card->ctx;
 1774|    176|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1775|       |
 1776|    176|	switch (cmd) {
  ------------------
  |  Branch (1776:10): [True: 176, False: 0]
  ------------------
 1777|    176|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1777:2): [True: 176, False: 0]
  ------------------
 1778|    176|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1779|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1779:2): [True: 0, False: 176]
  ------------------
 1780|      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__
  |  |  ------------------
  ------------------
 1781|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1782|      0|	case SC_CARDCTL_AUTHENTIC_SDO_DELETE:
  ------------------
  |  Branch (1782:2): [True: 0, False: 176]
  ------------------
 1783|      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__
  |  |  ------------------
  ------------------
 1784|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1785|      0|	case SC_CARDCTL_AUTHENTIC_SDO_STORE:
  ------------------
  |  Branch (1785:2): [True: 0, False: 176]
  ------------------
 1786|      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__
  |  |  ------------------
  ------------------
 1787|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1788|      0|	case SC_CARDCTL_AUTHENTIC_SDO_GENERATE:
  ------------------
  |  Branch (1788:2): [True: 0, False: 176]
  ------------------
 1789|      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__
  |  |  ------------------
  ------------------
 1790|      0|		return authentic_manage_sdo_generate(card, (struct sc_authentic_sdo *) ptr);
 1791|    176|	}
 1792|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1793|    176|}
card-authentic.c:authentic_get_tagged_data:
  177|    727|{
  178|    727|	size_t size_len, tag_len, offs, size;
  179|    727|	int rv;
  180|    727|	unsigned tag;
  181|       |
  182|    727|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 727]
  |  Branch (182:14): [True: 0, False: 727]
  ------------------
  183|    727|		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|  5.18k|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 5.02k, False: 153]
  ------------------
  186|  5.02k|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 1.34k, False: 3.68k]
  |  Branch (186:33): [True: 275, False: 3.41k]
  ------------------
  187|  1.61k|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 3, False: 1.61k]
  ------------------
  188|  1.61k|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|  1.61k|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|  1.61k|			tag_len = 2;
  191|  1.61k|		}
  192|  3.41k|		else   {
  193|  3.41k|			tag = *(in + offs);
  194|  3.41k|			tag_len = 1;
  195|  3.41k|		}
  196|       |
  197|  5.02k|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 28, False: 4.99k]
  ------------------
  198|  5.02k|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     28|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     28|		return _ret; \
  |  |  |  |  172|     28|	} \
  |  |  |  |  173|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|  4.99k|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|  4.99k|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|  4.99k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.99k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.99k|	int _ret = (r); \
  |  |  |  |  168|  4.99k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 82, False: 4.91k]
  |  |  |  |  ------------------
  |  |  |  |  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|  4.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.91k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|  4.91k|		size_len = rv;
  203|       |
  204|  4.91k|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 461, False: 4.45k]
  ------------------
  205|    461|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 3, False: 458]
  ------------------
  206|    461|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|    458|			*out = in + offs + tag_len + size_len;
  209|    458|			*out_len = size;
  210|       |
  211|    458|			return SC_SUCCESS;
  ------------------
  |  |   28|    458|#define SC_SUCCESS				0
  ------------------
  212|    461|		}
  213|       |
  214|  4.45k|		offs += tag_len + size_len + size;
  215|  4.45k|	}
  216|       |
  217|    153|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    153|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    727|}
card-authentic.c:authentic_parse_size:
  149|  4.99k|{
  150|  4.99k|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 4.99k]
  |  Branch (150:13): [True: 0, False: 4.99k]
  |  Branch (150:21): [True: 0, False: 4.99k]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|  4.99k|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 3.47k, False: 1.52k]
  ------------------
  154|  3.47k|		*out = *in;
  155|  3.47k|		return 1;
  156|  3.47k|	}
  157|  1.52k|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 1.35k, False: 172]
  ------------------
  158|  1.35k|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 2, False: 1.34k]
  ------------------
  159|      2|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|  1.34k|		*out = *(in + 1);
  161|  1.34k|		return 2;
  162|  1.35k|	}
  163|    172|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 96, False: 76]
  ------------------
  164|     96|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 4, False: 92]
  ------------------
  165|      4|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|     92|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|     92|		return 3;
  168|     96|	}
  169|       |
  170|     76|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     76|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|  4.99k|}
card-authentic.c:authentic_process_fci:
  775|    227|{
  776|    227|	struct sc_context *ctx = card->ctx;
  777|    227|	size_t taglen;
  778|    227|	int rv;
  779|    227|	unsigned ii;
  780|    227|	const unsigned char *tag = NULL;
  781|    227|	unsigned char ops_DF[8] = {
  782|    227|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    227|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    227|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    227|#define SC_AC_OP_CRYPTO			7
  ------------------
  783|    227|	};
  784|    227|	unsigned char ops_EF[8] = {
  785|    227|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    227|#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|    227|#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|    227|#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|    227|#define SC_AC_OP_RESIZE			25
  ------------------
  786|    227|	};
  787|       |
  788|    227|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    227|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    227|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    227|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    227|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 227]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|       |
  790|    227|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  791|    227|	if (tag != NULL) {
  ------------------
  |  Branch (791:6): [True: 162, False: 65]
  ------------------
  792|    162|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  793|    162|		buf = tag;
  794|    162|		buflen = taglen;
  795|    162|	}
  796|       |
  797|    227|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  798|    227|	if (tag != NULL) {
  ------------------
  |  Branch (798:6): [True: 48, False: 179]
  ------------------
  799|     48|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|     48|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  800|     48|		buf = tag;
  801|     48|		buflen = taglen;
  802|     48|	}
  803|       |
  804|    227|	rv = iso_ops->process_fci(card, file, buf, buflen);
  805|    227|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    227|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    227|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    227|	int _ret = (r); \
  |  |  |  |  168|    227|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 227]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    227|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 227]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  806|       |
  807|    227|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (807:6): [True: 128, False: 99]
  ------------------
  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|    120|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (810:7): [True: 8, False: 120]
  |  Branch (810:50): [True: 88, 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|    195|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    195|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    195|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  819|    710|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (819:15): [True: 541, False: 169]
  |  Branch (819:46): [True: 515, False: 26]
  ------------------
  820|    515|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    515|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (820:22): [True: 68, False: 447]
  ------------------
  821|    515|		unsigned char acl = *(file->sec_attr + ii*2);
  822|    515|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  823|    515|		unsigned sc = acl * 0x100 + cred_id;
  824|       |
  825|    515|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    515|#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|    515|		if (op == 0xFF)
  ------------------
  |  Branch (826:7): [True: 167, False: 348]
  ------------------
  827|    167|			;
  828|    348|		else if (!acl && !cred_id)
  ------------------
  |  Branch (828:12): [True: 114, False: 234]
  |  Branch (828:20): [True: 56, False: 58]
  ------------------
  829|     56|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     56|#define SC_AC_NONE			0x00000000
  ------------------
  830|    292|		else if (acl == 0xFF)
  ------------------
  |  Branch (830:12): [True: 64, False: 228]
  ------------------
  831|     64|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     64|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    228|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    228|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (832:12): [True: 110, False: 118]
  ------------------
  833|    110|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|    110|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  834|    118|		else if (cred_id)
  ------------------
  |  Branch (834:12): [True: 89, False: 29]
  ------------------
  835|     89|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|     89|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  836|     29|		else
  837|     29|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     29|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  838|    515|	}
  839|       |
  840|    195|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    195|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    195|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    195|	int _ret = r; \
  |  |  |  |  155|    195|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 195, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    195|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 195]
  |  |  |  |  ------------------
  |  |  |  |  157|    195|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    195|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    195|	return _ret; \
  |  |  |  |  163|    195|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|    195|}
card-authentic.c:authentic_pin_cmd:
 1441|    457|{
 1442|    457|	struct sc_context *ctx = card->ctx;
 1443|    457|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    457|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1444|       |
 1445|    457|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    457|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    457|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    457|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    457|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 457]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1446|    457|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   71|    457|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1447|    457|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   71|    457|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1448|    457|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   71|    457|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1449|       |
 1450|    457|	switch (data->cmd)   {
 1451|     42|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     42|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1451:2): [True: 42, False: 415]
  ------------------
 1452|     42|		rv = authentic_pin_verify(card, data);
 1453|     42|		break;
 1454|     39|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     39|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1454:2): [True: 39, False: 418]
  ------------------
 1455|     39|		rv = authentic_pin_change(card, data);
 1456|     39|		break;
 1457|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1457:2): [True: 0, False: 457]
  ------------------
 1458|      0|		rv = authentic_pin_reset(card, data);
 1459|      0|		break;
 1460|    376|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    376|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1460:2): [True: 376, False: 81]
  ------------------
 1461|    376|		rv = authentic_pin_get_policy(card, data, NULL);
 1462|    376|		break;
 1463|      0|	default:
  ------------------
  |  Branch (1463:2): [True: 0, False: 457]
  ------------------
 1464|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1465|    457|	}
 1466|       |
 1467|    457|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    457|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    457|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    457|	int _ret = r; \
  |  |  |  |  155|    457|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 457, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    457|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    351|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 351, False: 106]
  |  |  |  |  ------------------
  |  |  |  |  157|    457|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    457|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    457|	return _ret; \
  |  |  |  |  163|    457|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1468|    457|}
card-authentic.c:authentic_pin_verify:
 1106|     42|{
 1107|     42|	struct sc_context *ctx = card->ctx;
 1108|     42|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1109|     42|	unsigned char pin_sha1[SHA_DIGEST_LENGTH];
 1110|     42|	int rv;
 1111|       |
 1112|     42|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     42|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     42|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     42|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     42|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1113|     42|	sc_log(ctx, "PIN(type:%X,reference:%X,data:%p,length:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1114|     42|			pin_cmd->pin_type, pin_cmd->pin_reference, pin_cmd->pin1.data, pin_cmd->pin1.len);
 1115|       |
 1116|     42|	if (pin_cmd->pin_reference < 0 || pin_cmd->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|     42|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1116:6): [True: 0, False: 42]
  |  Branch (1116:36): [True: 0, False: 42]
  ------------------
 1117|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1118|      0|	}
 1119|       |
 1120|     42|	if (pin_cmd->pin1.data && !pin_cmd->pin1.len)   {
  ------------------
  |  Branch (1120:6): [True: 42, False: 0]
  |  Branch (1120:28): [True: 0, False: 42]
  ------------------
 1121|      0|		pin_cmd->pin1.tries_left = -1;
 1122|      0|		rv = authentic_pin_is_verified(card, pin_cmd);
 1123|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1124|      0|	}
 1125|       |
 1126|     42|	if (pin_cmd->pin1.data)
  ------------------
  |  Branch (1126:6): [True: 42, False: 0]
  ------------------
 1127|     42|		SHA1(pin_cmd->pin1.data, pin_cmd->pin1.len, pin_sha1);
 1128|      0|	else
 1129|      0|		SHA1((unsigned char *)"", 0, pin_sha1);
 1130|       |
 1131|     42|	if (!memcmp(pin_sha1, prv_data->pins_sha1[pin_cmd->pin_reference], SHA_DIGEST_LENGTH))   {
  ------------------
  |  Branch (1131:6): [True: 0, False: 42]
  ------------------
 1132|      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__
  |  |  ------------------
  ------------------
 1133|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1134|      0|	}
 1135|       |
 1136|     42|	memset(prv_data->pins_sha1[pin_cmd->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1137|       |
 1138|     42|	rv = authentic_pin_get_policy(card, pin_cmd, NULL);
 1139|     42|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  174|     42|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     42|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     42|	int _ret = (r); \
  |  |  |  |  168|     42|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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|     42|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1140|       |
 1141|     15|	if (pin_cmd->pin1.len > pin_cmd->pin1.max_length)
  ------------------
  |  Branch (1141:6): [True: 0, False: 15]
  ------------------
 1142|     15|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1143|       |
 1144|     15|	pin_cmd->pin1.tries_left = -1;
 1145|     15|	rv = authentic_chv_verify(card, pin_cmd);
 1146|     15|	LOG_TEST_RET(ctx, rv, "PIN CHV verification 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: 10, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|       |
 1148|      5|	memcpy(prv_data->pins_sha1[pin_cmd->pin_reference], pin_sha1, SHA_DIGEST_LENGTH);
 1149|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|      5|}
card-authentic.c:authentic_chv_verify:
 1023|     15|{
 1024|     15|	struct sc_context *ctx = card->ctx;
 1025|     15|	struct sc_apdu apdu;
 1026|     15|	struct sc_pin_cmd_pin *pin1 = &pin_cmd->pin1;
 1027|     15|	unsigned char pin_buff[SC_MAX_APDU_BUFFER_SIZE];
 1028|     15|	size_t pin_len;
 1029|     15|	int rv;
 1030|       |
 1031|     15|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1032|     15|	sc_log(ctx, "CHV PIN reference %i, pin1(%p,len:%zu)", pin_cmd->pin_reference, pin1->data, pin1->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__
  |  |  ------------------
  ------------------
 1033|       |
 1034|     15|	if (pin1->data && !pin1->len)   {
  ------------------
  |  Branch (1034:6): [True: 15, False: 0]
  |  Branch (1034:20): [True: 0, False: 15]
  ------------------
 1035|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1036|      0|	}
 1037|     15|	else if (pin1->data && pin1->len)   {
  ------------------
  |  Branch (1037:11): [True: 15, False: 0]
  |  Branch (1037:25): [True: 15, False: 0]
  ------------------
 1038|     15|		if (pin1->len > sizeof(pin_buff)) {
  ------------------
  |  Branch (1038:7): [True: 0, False: 15]
  ------------------
 1039|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1040|      0|		}
 1041|     15|		memcpy(pin_buff, pin1->data, pin1->len);
 1042|     15|		pin_len = pin1->len;
 1043|       |
 1044|     15|		if (pin1->pad_length && pin_cmd->flags & SC_PIN_CMD_NEED_PADDING)   {
  ------------------
  |  |  422|     15|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1044:7): [True: 15, False: 0]
  |  Branch (1044:27): [True: 15, False: 0]
  ------------------
 1045|     15|			if (pin1->len > pin1->pad_length || pin1->pad_length > sizeof(pin_buff)) {
  ------------------
  |  Branch (1045:8): [True: 0, False: 15]
  |  Branch (1045:40): [True: 0, False: 15]
  ------------------
 1046|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1047|      0|			}
 1048|     15|			if (pin1->len < sizeof(pin_buff)) {
  ------------------
  |  Branch (1048:8): [True: 15, False: 0]
  ------------------
 1049|     15|				memset(pin_buff + pin1->len, pin1->pad_char,
 1050|     15|						pin1->pad_length - pin1->len);
 1051|     15|			}
 1052|     15|			pin_len = pin1->pad_length;
 1053|     15|		}
 1054|       |
 1055|     15|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  293|     15|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1056|     15|		apdu.data = pin_buff;
 1057|     15|		apdu.datalen = pin_len;
 1058|     15|		apdu.lc = pin_len;
 1059|     15|	}
 1060|      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 (1060:11): [True: 0, False: 0]
  |  Branch (1060:67): [True: 0, False: 0]
  |  Branch (1060:82): [True: 0, False: 0]
  ------------------
 1061|      0|		rv = authentic_chv_verify_pinpad(card, pin_cmd);
 1062|      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__
  |  |  ------------------
  ------------------
 1063|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1064|      0|	}
 1065|      0|	else   {
 1066|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1067|      0|	}
 1068|       |
 1069|     15|	rv = sc_transmit_apdu(card, &apdu);
 1070|     15|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1071|       |
 1072|     14|	if (apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)   {
  ------------------
  |  Branch (1072:6): [True: 5, False: 9]
  |  Branch (1072:26): [True: 1, False: 4]
  ------------------
 1073|      1|		pin1->tries_left = apdu.sw2 & 0x0F;
 1074|      1|	}
 1075|       |
 1076|     14|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1077|       |
 1078|     14|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      9|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|     14|}
card-authentic.c:authentic_pin_change:
 1201|     39|{
 1202|     39|	struct sc_context *ctx = card->ctx;
 1203|     39|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1204|     39|	struct sc_apdu apdu;
 1205|     39|	unsigned char pin_data[SC_MAX_APDU_BUFFER_SIZE];
 1206|     39|	size_t offs;
 1207|     39|	int rv;
 1208|       |
 1209|     39|	rv = authentic_pin_get_policy(card, data, NULL);
 1210|     39|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  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: 35, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1211|       |
 1212|      4|	if (data->pin_reference < 0 || data->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|      4|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1212:6): [True: 0, False: 4]
  |  Branch (1212:33): [True: 0, False: 4]
  ------------------
 1213|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1214|      0|	}
 1215|       |
 1216|      4|	memset(prv_data->pins_sha1[data->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1217|       |
 1218|      4|	if (!data->pin1.data && !data->pin1.len && !data->pin2.data && !data->pin2.len)   {
  ------------------
  |  Branch (1218:6): [True: 0, False: 4]
  |  Branch (1218:26): [True: 0, False: 0]
  |  Branch (1218:45): [True: 0, False: 0]
  |  Branch (1218:65): [True: 0, False: 0]
  ------------------
 1219|      0|		if (!(card->reader->capabilities & SC_READER_CAP_PIN_PAD))
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1219:7): [True: 0, False: 0]
  ------------------
 1220|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1221|      0|		rv = authentic_pin_change_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1222|      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__
  |  |  ------------------
  ------------------
 1223|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1224|      0|	}
 1225|       |
 1226|      4|	if (card->max_send_size && (data->pin1.len + data->pin2.len > card->max_send_size))
  ------------------
  |  Branch (1226:6): [True: 4, False: 0]
  |  Branch (1226:29): [True: 0, False: 4]
  ------------------
 1227|      4|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1228|       |
 1229|      4|	memset(pin_data, data->pin1.pad_char, sizeof(pin_data));
 1230|      4|	offs = 0;
 1231|      4|	if (data->pin1.data && data->pin1.len)   {
  ------------------
  |  Branch (1231:6): [True: 4, False: 0]
  |  Branch (1231:25): [True: 4, False: 0]
  ------------------
 1232|      4|		if (data->pin1.pad_length > sizeof(pin_data) || data->pin1.len > sizeof(pin_data)) {
  ------------------
  |  Branch (1232:7): [True: 0, False: 4]
  |  Branch (1232:51): [True: 0, False: 4]
  ------------------
 1233|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1234|      0|		}
 1235|      4|		memcpy(pin_data, data->pin1.data, data->pin1.len);
 1236|      4|		offs += data->pin1.pad_length;
 1237|      4|	}
 1238|      4|	if (data->pin2.data && data->pin2.len) {
  ------------------
  |  Branch (1238:6): [True: 4, False: 0]
  |  Branch (1238:25): [True: 4, False: 0]
  ------------------
 1239|      4|		if (data->pin2.len + offs > sizeof(pin_data)) {
  ------------------
  |  Branch (1239:7): [True: 0, False: 4]
  ------------------
 1240|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1241|      0|		}
 1242|      4|		memcpy(pin_data + offs, data->pin2.data, data->pin2.len);
 1243|      4|	}
 1244|       |
 1245|      4|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, offs ? 0x00 : 0x01, data->pin_reference);
  ------------------
  |  |  293|      4|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1245:58): [True: 4, False: 0]
  ------------------
 1246|      4|	apdu.data = pin_data;
 1247|      4|	apdu.datalen = offs + data->pin1.pad_length;
 1248|      4|	apdu.lc = offs + data->pin1.pad_length;
 1249|       |
 1250|      4|	rv = sc_transmit_apdu(card, &apdu);
 1251|      4|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1252|      3|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1253|       |
 1254|      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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1255|      3|}
card-authentic.c:authentic_pin_get_policy:
 1302|    457|{
 1303|    457|	struct sc_context *ctx = card->ctx;
 1304|    457|	struct sc_apdu apdu;
 1305|    457|	unsigned char rbuf[0x100];
 1306|    457|	int ii, rv;
 1307|       |
 1308|    457|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    457|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    457|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    457|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    457|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 457]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1309|    457|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   71|    457|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1310|       |
 1311|    457|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|    457|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1312|    460|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1312:12): [True: 459, False: 1]
  ------------------
 1313|    459|		apdu.le = sizeof(rbuf);
 1314|    459|		apdu.resp = rbuf;
 1315|    459|		apdu.resplen = sizeof(rbuf);
 1316|       |
 1317|    459|		rv = sc_transmit_apdu(card, &apdu);
 1318|    459|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    459|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    459|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    459|	int _ret = (r); \
  |  |  |  |  168|    459|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 445]
  |  |  |  |  ------------------
  |  |  |  |  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|    459|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 445]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1319|    445|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1320|       |
 1321|    445|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    445|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1321:7): [True: 442, False: 3]
  ------------------
 1322|    442|			break;
 1323|       |
 1324|      3|		apdu.cla = 0x80;
 1325|      3|	}
 1326|    443|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  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: 155, False: 288]
  |  |  |  |  ------------------
  |  |  |  |  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|    443|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 288]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1327|       |
 1328|    288|	data->pin1.tries_left = -1;
 1329|       |
 1330|    288|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1331|    288|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  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: 168, False: 120]
  |  |  |  |  ------------------
  |  |  |  |  169|    168|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    168|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    168|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    168|		return _ret; \
  |  |  |  |  172|    168|	} \
  |  |  |  |  173|    288|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 120]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1332|       |
 1333|    120|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    120|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1334|    120|	data->pin1.offset = 5;
 1335|    120|	data->pin1.pad_char = 0xFF;
 1336|    120|	data->pin1.pad_length = data->pin1.max_length;
 1337|    120|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    120|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1338|       |
 1339|    120|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    120|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1340|       |
 1341|    120|	sc_log(ctx, "PIN policy: size max/min/pad %zu/%zu/%zu, tries max/left %i/%i",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1342|    120|			data->pin1.max_length, data->pin1.min_length, data->pin1.pad_length,
 1343|    120|			data->pin1.max_tries, data->pin1.tries_left);
 1344|       |
 1345|    120|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    120|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    120|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    120|	int _ret = r; \
  |  |  |  |  155|    120|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 120, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    120|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 120]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|    120|}
card-authentic.c:authentic_parse_credential_data:
  286|    288|{
  287|    288|	unsigned char *data;
  288|    288|	size_t data_len;
  289|    288|	int rv, ii;
  290|    288|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|    288|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|    288|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|    288|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  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: 130, False: 158]
  |  |  |  |  ------------------
  |  |  |  |  169|    130|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    130|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    130|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    130|		return _ret; \
  |  |  |  |  172|    130|	} \
  |  |  |  |  173|    288|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 158]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|    158|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|    158|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|    158|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  174|    158|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    158|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    158|	int _ret = (r); \
  |  |  |  |  168|    158|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 151]
  |  |  |  |  ------------------
  |  |  |  |  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|    158|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 151]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|    151|	if (data_len < 1)
  ------------------
  |  Branch (297:6): [True: 3, False: 148]
  ------------------
  298|    151|		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|    148|	pin_cmd->pin1.max_tries = *data;
  300|       |
  301|    148|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|    148|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  302|    148|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|    148|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    148|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    148|	int _ret = (r); \
  |  |  |  |  168|    148|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 141]
  |  |  |  |  ------------------
  |  |  |  |  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|    148|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 141]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|    141|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (303:6): [True: 136, False: 5]
  |  Branch (303:22): [True: 6, False: 130]
  ------------------
  304|      6|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      6|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  305|    135|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (305:11): [True: 130, False: 5]
  |  Branch (305:27): [True: 127, False: 3]
  |  Branch (305:41): [True: 120, False: 7]
  ------------------
  306|    120|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|    120|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  307|     15|	else
  308|     15|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|       |
  310|       |	/* Parse optional ACLs when requested */
  311|    126|	if (acls) {
  ------------------
  |  Branch (311:6): [True: 0, False: 126]
  ------------------
  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|    126|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|    126|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  343|    126|	if (!rv)   {
  ------------------
  |  Branch (343:6): [True: 6, False: 120]
  ------------------
  344|      6|		blob = data;
  345|      6|		blob_len = data_len;
  346|       |
  347|      6|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH, &data, &data_len);
  ------------------
  |  |   97|      6|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH	0x83
  ------------------
  348|      6|		LOG_TEST_RET(ctx, rv, "failed to get PIN max.length value");
  ------------------
  |  |  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: 4, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|      2|		if (data_len < 1)
  ------------------
  |  Branch (349:7): [True: 1, False: 1]
  ------------------
  350|      2|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "invalid 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      1|		pin_cmd->pin1.max_length = *data;
  352|       |
  353|      1|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH, &data, &data_len);
  ------------------
  |  |   98|      1|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH	0x84
  ------------------
  354|      1|		LOG_TEST_RET(ctx, rv, "failed to get PIN min.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    120|	return SC_SUCCESS;
  ------------------
  |  |   28|    120|#define SC_SUCCESS				0
  ------------------
  361|    126|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1899|  1.67k|{
 1900|  1.67k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.67k|#define SC_SUCCESS				0
  ------------------
 1901|       |
 1902|  1.67k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1903|       |
 1904|  1.67k|	if (was_reset > 0
  ------------------
  |  Branch (1904:6): [True: 0, False: 1.67k]
  ------------------
 1905|      0|			&& card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
  ------------------
  |  Branch (1905:7): [True: 0, False: 0]
  ------------------
 1906|      0|		r = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
 1907|      0|	}
 1908|       |
 1909|  1.67k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.67k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.67k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.67k|	int _ret = r; \
  |  |  |  |  155|  1.67k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.67k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.67k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.67k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.67k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.67k|	} else { \
  |  |  |  |  159|      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.67k|	return _ret; \
  |  |  |  |  163|  1.67k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1910|  1.67k|}

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

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

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

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

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

card-cedulauy.c:cedulauy_read_mrz_cache:
   84|      1|{
   85|      1|	char path[PATH_MAX];
   86|      1|	FILE *f;
   87|      1|	size_t got;
   88|       |
   89|      1|	if (cedulauy_mrz_cache_path(ctx, path, sizeof path) < 0)
  ------------------
  |  Branch (89:6): [True: 0, False: 1]
  ------------------
   90|      0|		return 0;
   91|       |
   92|      1|	f = fopen(path, "rb");
   93|      1|	if (f == NULL)
  ------------------
  |  Branch (93:6): [True: 1, False: 0]
  ------------------
   94|      1|		return 0;
   95|       |
   96|      0|	got = fread(mrz, 1, CEDULAUY_MRZ_LEN, f);
  ------------------
  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  ------------------
   97|      0|	fclose(f);
   98|       |
   99|      0|	if (got != CEDULAUY_MRZ_LEN) {
  ------------------
  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  ------------------
  |  Branch (99:6): [True: 0, False: 0]
  ------------------
  100|      0|		sc_log(ctx, "Ignoring %s, it is not %d characters long", path, CEDULAUY_MRZ_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__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  100|      0|		sc_log(ctx, "Ignoring %s, it is not %d characters long", path, CEDULAUY_MRZ_LEN);
  |  |  |  |  ------------------
  |  |  |  |  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  101|      0|		return 0;
  102|      0|	}
  103|       |
  104|      0|	return 1;
  105|      0|}
card-cedulauy.c:cedulauy_mrz_cache_path:
   44|      1|{
   45|      1|	int r = sc_get_cache_dir(ctx, buf, buflen);
   46|      1|	if (r < 0)
  ------------------
  |  Branch (46:6): [True: 0, False: 1]
  ------------------
   47|      0|		return r;
   48|       |
   49|      1|	if (strlcat(buf, "/" CEDULAUY_MRZ_CACHE_FILE, buflen) >= buflen)
  ------------------
  |  |   40|      1|#define CEDULAUY_MRZ_CACHE_FILE "cedulauy_mrz"
  ------------------
  |  Branch (49:6): [True: 0, False: 1]
  ------------------
   50|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   51|       |
   52|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
   53|      1|}

sc_get_cedulauy_driver:
  511|  16.1k|{
  512|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  513|       |
  514|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (514:6): [True: 1, False: 16.1k]
  ------------------
  515|      1|		iso_ops = iso_drv->ops;
  516|       |
  517|  16.1k|	cedulauy_ops = *iso_ops;
  518|  16.1k|	cedulauy_ops.match_card = cedulauy_match_card;
  519|  16.1k|	cedulauy_ops.init = cedulauy_init;
  520|  16.1k|	cedulauy_ops.finish = cedulauy_finish;
  521|  16.1k|	cedulauy_ops.select_file = cedulauy_select_file;
  522|  16.1k|	cedulauy_ops.set_security_env = cedulauy_set_security_env;
  523|  16.1k|	cedulauy_ops.compute_signature = cedulauy_compute_signature;
  524|  16.1k|	cedulauy_ops.decipher = NULL;
  525|  16.1k|	cedulauy_ops.get_challenge = cedulauy_get_challenge;
  526|  16.1k|	cedulauy_ops.logout = cedulauy_logout;
  527|  16.1k|	cedulauy_ops.card_reader_lock_obtained = cedulauy_card_reader_lock_obtained;
  528|       |
  529|  16.1k|	return &cedulauy_drv;
  530|  16.1k|}
card-cedulauy.c:cedulauy_match_card:
  273|  2.43k|{
  274|  2.43k|	int type = 0;
  275|  2.43k|	int i = _sc_match_atr(card, cedulauy_atrs, &type);
  276|       |
  277|  2.43k|	if (i < 0)
  ------------------
  |  Branch (277:6): [True: 2.37k, False: 64]
  ------------------
  278|  2.37k|		return 0;
  279|       |
  280|     64|	if (type == SC_CARD_TYPE_CEDULAUY_CONTACTLESS) {
  ------------------
  |  Branch (280:6): [True: 15, False: 49]
  ------------------
  281|     15|#ifdef CEDULAUY_HAS_PACE
  282|     15|		if (!cedulauy_match_contactless(card))
  ------------------
  |  Branch (282:7): [True: 15, False: 0]
  ------------------
  283|     15|			return 0;
  284|       |#else
  285|       |		sc_log(card->ctx, "Built without PACE support, ignoring the contactless interface");
  286|       |		return 0;
  287|       |#endif
  288|     15|	}
  289|       |
  290|     49|	card->type = type;
  291|     49|	card->name = cedulauy_atrs[i].name;
  292|     49|	return 1;
  293|     64|}
card-cedulauy.c:cedulauy_match_contactless:
  220|     15|{
  221|     15|	unsigned char buf[sizeof cedulauy_ef_cardaccess + 1];
  222|     15|	unsigned char mrz[CEDULAUY_MRZ_LEN];
  223|     15|	struct sc_apdu apdu;
  224|     15|	int r;
  225|       |
  226|     15|	if (cedulauy_select_mf(card) < 0)
  ------------------
  |  Branch (226:6): [True: 4, False: 11]
  ------------------
  227|      4|		return 0;
  228|       |
  229|       |	/* EF.CardAccess is the only file readable before PACE */
  230|     11|	sc_format_apdu_ex(&apdu, 0x00, 0xB0, 0x80 | SFID_EF_CARDACCESS, 0x00,
  ------------------
  |  |   85|     11|#define SFID_EF_CARDACCESS   0x1C
  ------------------
  231|     11|			NULL, 0, buf, sizeof buf);
  232|       |
  233|     11|	if (sc_transmit_apdu(card, &apdu) < 0 ||
  ------------------
  |  Branch (233:6): [True: 1, False: 10]
  ------------------
  234|     10|			apdu.resplen != sizeof cedulauy_ef_cardaccess ||
  ------------------
  |  Branch (234:4): [True: 2, False: 8]
  ------------------
  235|     10|			0 != memcmp(buf, cedulauy_ef_cardaccess, sizeof cedulauy_ef_cardaccess)) {
  ------------------
  |  Branch (235:4): [True: 7, False: 1]
  ------------------
  236|     10|		sc_log(card->ctx, "Unexpected EF.CardAccess, not a cedula");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  237|     10|		return 0;
  238|     10|	}
  239|       |
  240|      1|	if (!cedulauy_get_mrz(card->ctx, mrz)) {
  ------------------
  |  Branch (240:6): [True: 1, False: 0]
  ------------------
  241|      1|		sc_log(card->ctx, "Possibly a cedula, run cedulauy-tool to store its MRZ");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  242|      1|		return 0;
  243|      1|	}
  244|       |
  245|      0|	card->max_send_size = CEDULAUY_SM_MAX_SIZE;
  ------------------
  |  |   99|      0|#define CEDULAUY_SM_MAX_SIZE 0xC0
  ------------------
  246|      0|	card->max_recv_size = CEDULAUY_SM_MAX_SIZE;
  ------------------
  |  |   99|      0|#define CEDULAUY_SM_MAX_SIZE 0xC0
  ------------------
  247|       |
  248|      0|	r = cedulauy_perform_pace(card, mrz);
  249|      0|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (249:6): [True: 0, False: 0]
  ------------------
  250|      0|		r = cedulauy_select_app(card);
  251|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (251:6): [True: 0, False: 0]
  ------------------
  252|      0|		card->drv_data = calloc(1, sizeof(struct cedulauy_drv_data));
  253|      0|		if (card->drv_data == NULL)
  ------------------
  |  Branch (253:7): [True: 0, False: 0]
  ------------------
  254|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  255|      0|		else
  256|      0|			memcpy(DRVDATA(card)->mrz, mrz, CEDULAUY_MRZ_LEN);
  ------------------
  |  |  115|      0|#define DRVDATA(card) ((struct cedulauy_drv_data *)((card)->drv_data))
  ------------------
              			memcpy(DRVDATA(card)->mrz, mrz, CEDULAUY_MRZ_LEN);
  ------------------
  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  ------------------
  257|      0|	}
  258|      0|	sc_mem_clear(mrz, sizeof mrz);
  259|       |
  260|      0|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (260:6): [True: 0, False: 0]
  ------------------
  261|      0|		sc_sm_stop(card);
  262|      0|		sc_log(card->ctx, "PACE with the stored MRZ failed, not a cedula or not this one");
  ------------------
  |  |   71|      0|#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|      0|		return 0;
  264|      0|	}
  265|       |
  266|      0|	return 1;
  267|      0|}
card-cedulauy.c:cedulauy_select_mf:
  152|     15|{
  153|     15|	static const unsigned char mf[] = {0x3F, 0x00};
  154|     15|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  155|     15|	struct sc_apdu apdu;
  156|     15|	int r;
  157|       |
  158|     15|	sc_format_apdu_ex(&apdu, 0x00, 0xA4, 0x00, 0x0C, mf, sizeof mf, NULL, 0);
  159|     15|	r = sc_transmit_apdu(card, &apdu);
  160|     15|	if (r < 0)
  ------------------
  |  Branch (160:6): [True: 1, False: 14]
  ------------------
  161|      1|		return r;
  162|     14|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (162:6): [True: 11, False: 3]
  |  Branch (162:26): [True: 10, False: 1]
  ------------------
  163|     10|		return SC_SUCCESS;
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  164|       |
  165|       |	/* any other SW is intentionally ignored: retry asking for the FCI,
  166|       |	 * and let that SELECT's SW decide the result */
  167|      4|	sc_format_apdu_ex(&apdu, 0x00, 0xA4, 0x00, 0x00, mf, sizeof mf, resp, sizeof resp);
  168|      4|	r = sc_transmit_apdu(card, &apdu);
  169|      4|	if (r < 0)
  ------------------
  |  Branch (169:6): [True: 1, False: 3]
  ------------------
  170|      1|		return r;
  171|       |
  172|      3|	return sc_check_sw(card, apdu.sw1, apdu.sw2);
  173|      4|}
card-cedulauy.c:cedulauy_get_mrz:
  178|      1|{
  179|      1|	const char *env = getenv("CEDULAUY_MRZ");
  180|       |
  181|      1|	if (env != NULL) {
  ------------------
  |  Branch (181:6): [True: 0, False: 1]
  ------------------
  182|      0|		if (strlen(env) == CEDULAUY_MRZ_LEN) {
  ------------------
  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  ------------------
  |  Branch (182:7): [True: 0, False: 0]
  ------------------
  183|      0|			memcpy(mrz, env, CEDULAUY_MRZ_LEN);
  ------------------
  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  ------------------
  184|      0|			return 1;
  185|      0|		}
  186|      0|		sc_log(ctx, "Ignoring CEDULAUY_MRZ, it is not %d characters long",
  ------------------
  |  |   71|      0|#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)
  |  |  ------------------
  |  |  |  |  187|      0|				CEDULAUY_MRZ_LEN);
  |  |  |  |  ------------------
  |  |  |  |  |  |   39|      0|#define CEDULAUY_MRZ_LEN	90
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  187|      0|				CEDULAUY_MRZ_LEN);
  188|      0|	}
  189|       |
  190|      1|	return cedulauy_read_mrz_cache(ctx, mrz);
  191|      1|}
card-cedulauy.c:cedulauy_select_app:
  135|     49|{
  136|     49|	struct sc_apdu apdu;
  137|     49|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  138|       |
  139|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  140|       |
  141|     49|	sc_format_apdu_ex(&apdu, card->cla, 0xA4, 0x04, 0x00,
  142|     49|			cedulauy_aid, sizeof cedulauy_aid, resp, sizeof resp);
  143|     49|	SC_TRANSMIT_TEST_RET(card, apdu, "Cannot select the eID application");
  ------------------
  |  |  128|     49|	do { \
  |  |  129|     49|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "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: 2, False: 47]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     49|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 47]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  130|     49|		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: 4, False: 43]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     47|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  131|     47|	} while (0)
  |  |  ------------------
  |  |  |  Branch (131:11): [Folded, False: 43]
  |  |  ------------------
  ------------------
  144|       |
  145|     43|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     43|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     43|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     43|	int _ret = r; \
  |  |  |  |  155|     43|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     43|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     43|	return _ret; \
  |  |  |  |  163|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  146|     43|}
card-cedulauy.c:cedulauy_init:
  297|     49|{
  298|     49|	unsigned long flags;
  299|     49|	int r;
  300|       |
  301|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|       |
  303|     49|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     49|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  304|       |
  305|     49|	if (card->type == SC_CARD_TYPE_CEDULAUY_CONTACTLESS) {
  ------------------
  |  Branch (305:6): [True: 0, False: 49]
  ------------------
  306|       |		/* match_card() has already established PACE and selected the application */
  307|      0|		if (card->drv_data == NULL)
  ------------------
  |  Branch (307:7): [True: 0, False: 0]
  ------------------
  308|      0|			LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "No PACE channel to the 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|     49|	} else {
  310|     49|		r = cedulauy_select_app(card);
  311|     49|		LOG_TEST_RET(card->ctx, r, "Cannot select the eID application");
  ------------------
  |  |  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: 6, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  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|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  312|     49|	}
  313|       |
  314|       |	/* only SHA-256 is hashed on-card, anything else gets a software DigestInfo */
  315|     43|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA256;
  ------------------
  |  |  111|     43|#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|     43|#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|     43|#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|     43|#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|     43|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  316|     43|	r = _sc_card_add_rsa_alg(card, 2048, flags, 0);
  317|       |
  318|     43|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     43|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     43|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     43|	int _ret = r; \
  |  |  |  |  155|     43|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     43|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     43|	return _ret; \
  |  |  |  |  163|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|     43|}
card-cedulauy.c:cedulauy_finish:
  323|     43|{
  324|     43|#ifdef CEDULAUY_HAS_PACE
  325|     43|	sc_sm_stop(card);
  326|     43|	if (card->drv_data != NULL) {
  ------------------
  |  Branch (326:6): [True: 0, False: 43]
  ------------------
  327|      0|		sc_mem_clear(card->drv_data, sizeof(struct cedulauy_drv_data));
  328|      0|		free(card->drv_data);
  329|      0|		card->drv_data = NULL;
  330|      0|	}
  331|     43|#endif
  332|     43|	return SC_SUCCESS;
  ------------------
  |  |   28|     43|#define SC_SUCCESS				0
  ------------------
  333|     43|}
card-cedulauy.c:cedulauy_select_file:
  373|     43|{
  374|     43|	struct sc_path path;
  375|       |
  376|     43|	if (!in_path)
  ------------------
  |  Branch (376:6): [True: 0, False: 43]
  ------------------
  377|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  378|       |
  379|     43|	path = *in_path;
  380|       |
  381|     43|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     43|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     43|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     43|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     43|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|     43|	if (path.aid.len == sizeof cedulauy_aid && 0 == memcmp(path.aid.value, cedulauy_aid, sizeof cedulauy_aid)) {
  ------------------
  |  Branch (383:6): [True: 43, False: 0]
  |  Branch (383:45): [True: 43, False: 0]
  ------------------
  384|       |		/* the driver keeps the eID application selected, no need to select it again */
  385|     43|		path.aid.len = 0;
  386|     43|	}
  387|     43|	if (path.type == SC_PATH_TYPE_PATH && path.len >= 2 && path.value[0] == 0x3F && path.value[1] == 0x00) {
  ------------------
  |  |  119|     86|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (387:6): [True: 0, False: 43]
  |  Branch (387:40): [True: 0, False: 0]
  |  Branch (387:57): [True: 0, False: 0]
  |  Branch (387:82): [True: 0, False: 0]
  ------------------
  388|      0|		memmove(path.value, path.value + 2, path.len - 2);
  389|      0|		path.len -= 2;
  390|      0|	}
  391|     43|	if (path.type == SC_PATH_TYPE_PATH && path.len == 0) {
  ------------------
  |  |  119|     86|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (391:6): [True: 0, False: 43]
  |  Branch (391:40): [True: 0, False: 0]
  ------------------
  392|       |		/* Selection of MF was requested */
  393|      0|		if (file_out) {
  ------------------
  |  Branch (393:7): [True: 0, False: 0]
  ------------------
  394|      0|			sc_file_dup(file_out, cedulauy_get_mf());
  395|      0|			if (*file_out == NULL)
  ------------------
  |  Branch (395:8): [True: 0, False: 0]
  ------------------
  396|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  397|      0|		}
  398|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  399|      0|	}
  400|       |
  401|     43|	LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, &path, file_out));
  ------------------
  |  |  164|     43|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     43|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     43|	int _ret = r; \
  |  |  |  |  155|     43|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 43, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     43|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     43|	return _ret; \
  |  |  |  |  163|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|     43|}
card-cedulauy.c:cedulauy_set_security_env:
  407|    141|{
  408|    141|	struct sc_apdu apdu;
  409|    141|	unsigned char mse_data[] = {0x84, 0x01, 0xFF, 0x80, 0x01, CEDULAUY_ALGO_RSA_PKCS1};
  ------------------
  |  |   73|    141|#define CEDULAUY_ALGO_RSA_PKCS1	       (CEDULAUY_ALGO_HASH_NONE | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   69|    141|#define CEDULAUY_ALGO_HASH_NONE	  0x00 /* DigestInfo built in software */
  |  |  ------------------
  |  |               #define CEDULAUY_ALGO_RSA_PKCS1	       (CEDULAUY_ALGO_HASH_NONE | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   71|    141|#define CEDULAUY_ALGO_PAD_PKCS1	  0x02 /* PKCS#1 v1.5 */
  |  |  ------------------
  ------------------
  410|       |
  411|    141|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    141|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    141|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    141|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    141|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 141]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|       |
  413|    141|	if (env == NULL)
  ------------------
  |  Branch (413:6): [True: 0, False: 141]
  ------------------
  414|    141|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|    141|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   48|    141|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (415:6): [True: 0, False: 141]
  ------------------
  416|    141|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  417|    141|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT) && env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   60|    141|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
              	if ((env->flags & SC_SEC_ENV_ALG_PRESENT) && env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    141|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (417:6): [True: 141, False: 0]
  |  Branch (417:47): [True: 0, False: 141]
  ------------------
  418|    141|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  419|    141|	if (env->key_ref_len != 1)
  ------------------
  |  Branch (419:6): [True: 0, False: 141]
  ------------------
  420|    141|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  421|       |
  422|    141|	mse_data[2] = env->key_ref[0];
  423|    141|	if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256)
  ------------------
  |  |  138|    141|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (423:6): [True: 46, False: 95]
  ------------------
  424|     46|		mse_data[5] = CEDULAUY_ALGO_RSA_PKCS1_SHA256;
  ------------------
  |  |   74|     46|#define CEDULAUY_ALGO_RSA_PKCS1_SHA256 (CEDULAUY_ALGO_HASH_SHA256 | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   70|     46|#define CEDULAUY_ALGO_HASH_SHA256 0x40 /* card builds the DigestInfo */
  |  |  ------------------
  |  |               #define CEDULAUY_ALGO_RSA_PKCS1_SHA256 (CEDULAUY_ALGO_HASH_SHA256 | CEDULAUY_ALGO_PAD_PKCS1)
  |  |  ------------------
  |  |  |  |   71|     46|#define CEDULAUY_ALGO_PAD_PKCS1	  0x02 /* PKCS#1 v1.5 */
  |  |  ------------------
  ------------------
  425|       |
  426|    141|	sc_format_apdu_ex(&apdu, card->cla, 0x22, 0x41, 0xB6,
  427|    141|			mse_data, sizeof mse_data, NULL, 0);
  428|    141|	SC_TRANSMIT_TEST_RET(card, apdu, "MSE SET DST failed");
  ------------------
  |  |  128|    141|	do { \
  |  |  129|    141|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|    141|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|    141|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|    141|	int _ret = (r); \
  |  |  |  |  |  |  168|    141|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 8, False: 133]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|    141|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 133]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  130|    141|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  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: 52, False: 81]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|    133|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  131|    133|	} while (0)
  |  |  ------------------
  |  |  |  Branch (131:11): [Folded, False: 81]
  |  |  ------------------
  ------------------
  429|       |
  430|     81|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|     81|}
card-cedulauy.c:cedulauy_compute_signature:
  436|     81|{
  437|     81|	struct sc_apdu apdu;
  438|     81|	unsigned char sbuf[64];
  439|     81|	unsigned char rbuf[256];
  440|     81|	size_t offs = 0;
  441|       |
  442|     81|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  443|       |
  444|     81|	if (data == NULL || out == NULL)
  ------------------
  |  Branch (444:6): [True: 0, False: 81]
  |  Branch (444:22): [True: 0, False: 81]
  ------------------
  445|     81|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|       |
  447|     81|	if (datalen == 0 || datalen > sizeof(sbuf) - 2)
  ------------------
  |  Branch (447:6): [True: 7, False: 74]
  |  Branch (447:22): [True: 7, False: 67]
  ------------------
  448|     81|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED,
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     14|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     14|		return _ret; \
  |  |  |  |  172|     14|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  449|     67|				"Unsupported hash/DigestInfo length");
  450|       |
  451|       |	/* PSO HASH */
  452|     67|	sbuf[offs++] = 0x90;
  453|     67|	sbuf[offs++] = (unsigned char)datalen;
  454|     67|	memcpy(sbuf + offs, data, datalen);
  455|     67|	offs += datalen;
  456|     67|#ifdef CEDULAUY_HAS_PACE
  457|     67|	if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|     67|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (457:6): [True: 0, False: 67]
  ------------------
  458|       |		/* under SM the card returns an encrypted body that must not be truncated */
  459|      0|		sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x90, 0xA0, sbuf, offs, rbuf, sizeof rbuf);
  460|      0|		apdu.flags |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|      0|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  461|     67|	} else {
  462|     67|		sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x90, 0xA0, sbuf, offs, NULL, 0);
  463|     67|	}
  464|       |#else
  465|       |	sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x90, 0xA0, sbuf, offs, NULL, 0);
  466|       |#endif
  467|     67|	SC_TRANSMIT_TEST_RET(card, apdu, "PSO HASH failed");
  ------------------
  |  |  128|     67|	do { \
  |  |  129|     67|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed"); \
  |  |  ------------------
  |  |  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  |  |  ------------------
  |  |  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (168:6): [True: 6, False: 61]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     67|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 61]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  130|     67|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  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: 18, False: 43]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     61|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  131|     61|	} while (0)
  |  |  ------------------
  |  |  |  Branch (131:11): [Folded, False: 43]
  |  |  ------------------
  ------------------
  468|       |
  469|       |	/* PSO COMPUTE DIGITAL SIGNATURE */
  470|     43|	sc_format_apdu_ex(&apdu, card->cla, 0x2A, 0x9E, 0x9A, NULL, 0, rbuf, sizeof rbuf);
  471|     43|	SC_TRANSMIT_TEST_RET(card, apdu, "PSO COMPUTE DIGITAL SIGNATURE failed");
  ------------------
  |  |  128|     43|	do { \
  |  |  129|     43|		LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "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: 7, False: 36]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     43|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  130|     43|		LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), text); \
  |  |  ------------------
  |  |  |  |  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: 15, False: 21]
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  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|     36|} while(0)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  Branch (173:9): [Folded, False: 21]
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  131|     36|	} while (0)
  |  |  ------------------
  |  |  |  Branch (131:11): [Folded, False: 21]
  |  |  ------------------
  ------------------
  472|       |
  473|     21|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (473:6): [True: 0, False: 21]
  ------------------
  474|     21|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|     21|				"Signature buffer too small");
  476|     21|	memcpy(out, apdu.resp, apdu.resplen);
  477|     21|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 7, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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|     14|	} 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|     21|	return _ret; \
  |  |  |  |  163|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|     21|}
card-cedulauy.c:cedulauy_card_reader_lock_obtained:
  337|    316|{
  338|    316|	if (!was_reset)
  ------------------
  |  Branch (338:6): [True: 316, False: 0]
  ------------------
  339|    316|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    316|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    316|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    316|	int _ret = r; \
  |  |  |  |  155|    316|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 316, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    316|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 316]
  |  |  |  |  ------------------
  |  |  |  |  157|    316|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    316|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    316|	return _ret; \
  |  |  |  |  163|    316|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  340|       |
  341|      0|#ifdef CEDULAUY_HAS_PACE
  342|      0|	if (card->type == SC_CARD_TYPE_CEDULAUY_CONTACTLESS) {
  ------------------
  |  Branch (342:6): [True: 0, False: 0]
  ------------------
  343|      0|		int r;
  344|       |
  345|      0|		sc_sm_stop(card);
  346|      0|		r = cedulauy_perform_pace(card, DRVDATA(card)->mrz);
  ------------------
  |  |  115|      0|#define DRVDATA(card) ((struct cedulauy_drv_data *)((card)->drv_data))
  ------------------
  347|      0|		LOG_TEST_RET(card->ctx, r, "Cannot re-establish the PACE channel");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  348|      0|	}
  349|      0|#endif
  350|       |
  351|      0|	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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  352|      0|}

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

coolkey_get_attribute_data:
  603|  4.61k|{
  604|       |	/* handle the V0 objects first */
  605|  4.61k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  4.61k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (605:6): [True: 772, False: 3.83k]
  ------------------
  606|    772|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  607|    772|	}
  608|       |
  609|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  610|  3.83k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  3.83k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (610:6): [True: 0, False: 3.83k]
  ------------------
  611|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  612|      0|	}
  613|       |
  614|  3.83k|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  615|       |
  616|  3.83k|}
coolkey_compare_id:
  758|   409k|{
  759|   409k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (759:6): [True: 0, False: 409k]
  |  Branch (759:19): [True: 0, False: 409k]
  ------------------
  760|      0|		return 1;
  761|   409k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  762|   409k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  763|   409k|}
coolkey_list_meter:
  766|  10.2k|size_t coolkey_list_meter(const void *el) {
  767|  10.2k|	return sizeof(sc_cardctl_coolkey_object_t);
  768|  10.2k|}
coolkey_fill_object:
 1368|  52.4k|{
 1369|  52.4k|	int r;
 1370|  52.4k|	size_t buf_len = obj->length;
 1371|  52.4k|	u8 *new_obj_data = NULL;
 1372|  52.4k|	sc_cardctl_coolkey_object_t *obj_entry;
 1373|  52.4k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  52.4k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1374|       |
 1375|  52.4k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  52.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  52.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  52.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  52.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 52.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1376|       |
 1377|  52.4k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1377:6): [True: 0, False: 52.4k]
  ------------------
 1378|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1379|      0|	}
 1380|  52.4k|	new_obj_data = malloc(buf_len);
 1381|  52.4k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1381:6): [True: 0, False: 52.4k]
  ------------------
 1382|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1383|      0|	}
 1384|  52.4k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1385|  52.4k|				priv->nonce, sizeof(priv->nonce));
 1386|  52.4k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1386:6): [True: 49.2k, False: 3.27k]
  ------------------
 1387|  49.2k|		free(new_obj_data);
 1388|  49.2k|		if (r < 0) {
  ------------------
  |  Branch (1388:7): [True: 49.2k, False: 0]
  ------------------
 1389|  49.2k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  49.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  49.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  49.2k|	int _ret = r; \
  |  |  |  |  155|  49.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  49.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|  49.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  49.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  49.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|  49.2k|	return _ret; \
  |  |  |  |  163|  49.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1390|  49.2k|		}
 1391|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1392|      0|	}
 1393|  3.27k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1394|  3.27k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1394:6): [True: 0, False: 3.27k]
  ------------------
 1395|      0|		free(new_obj_data);
 1396|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1397|      0|	}
 1398|  3.27k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1398:6): [True: 0, False: 3.27k]
  ------------------
 1399|      0|		free(new_obj_data);
 1400|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1401|      0|	}
 1402|       |	/* Make sure we will not go over the allocated limits in the other
 1403|       |	 * objects if they somehow got different lengths in matching objects */
 1404|  3.27k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1404:6): [True: 0, False: 3.27k]
  ------------------
 1405|      0|		free(new_obj_data);
 1406|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1407|      0|	}
 1408|  3.27k|	obj_entry->data = new_obj_data;
 1409|  3.27k|	obj->data = new_obj_data;
 1410|  3.27k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.27k|	int _ret = r; \
  |  |  |  |  155|  3.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.27k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.27k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.27k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.27k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.27k|	return _ret; \
  |  |  |  |  163|  3.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1411|  3.27k|}
coolkey_find_object_by_template:
 1500|  2.35k|{
 1501|  2.35k|	list_t *list;
 1502|  2.35k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1503|  2.35k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  2.35k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1504|  2.35k|	int i, r;
 1505|  2.35k|	unsigned int tmp_pos = (unsigned int) -1;
 1506|       |
 1507|  2.35k|	list = &priv->objects_list;
 1508|  2.35k|	if (list->iter_active) {
  ------------------
  |  Branch (1508:6): [True: 2.35k, False: 0]
  ------------------
 1509|       |		/* workaround missing functionality of second iterator */
 1510|  2.35k|		tmp_pos = list->iter_pos;
 1511|  2.35k|		list_iterator_stop(list);
 1512|  2.35k|	}
 1513|       |
 1514|  2.35k|	list_iterator_start(list);
 1515|  55.2k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1515:9): [True: 54.5k, False: 725]
  ------------------
 1516|  54.5k|		sc_cardctl_coolkey_attribute_t attribute;
 1517|  54.5k|		current = list_iterator_next(list);
 1518|  54.5k|		attribute.object = current;
 1519|       |
 1520|  61.8k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1520:13): [True: 60.2k, False: 1.62k]
  ------------------
 1521|  60.2k|			attribute.attribute_type = template[i].attribute_type;
 1522|  60.2k|			r = coolkey_find_attribute(card, &attribute);
 1523|  60.2k|			if (r < 0) {
  ------------------
  |  Branch (1523:8): [True: 36.4k, False: 23.8k]
  ------------------
 1524|  36.4k|				break;
 1525|  36.4k|			}
 1526|  23.8k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1526:8): [True: 189, False: 23.6k]
  ------------------
 1527|    189|				break;
 1528|    189|			}
 1529|  23.6k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1529:8): [True: 90, False: 23.5k]
  ------------------
 1530|     90|				break;
 1531|     90|			}
 1532|  23.5k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1532:8): [True: 16.2k, False: 7.29k]
  ------------------
 1533|  23.5k|							attribute.attribute_length) != 0) {
 1534|  16.2k|				break;
 1535|  16.2k|			}
 1536|  23.5k|		}
 1537|       |		/* just return the first one */
 1538|  54.5k|		if (i == count) {
  ------------------
  |  Branch (1538:7): [True: 1.62k, False: 52.9k]
  ------------------
 1539|  1.62k|			rv = current;
 1540|  1.62k|			break;
 1541|  1.62k|		}
 1542|  54.5k|	}
 1543|       |
 1544|  2.35k|	list_iterator_stop(list);
 1545|  2.35k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1545:6): [True: 2.35k, False: 0]
  ------------------
 1546|       |		/* workaround missing functionality of second iterator */
 1547|  2.35k|		list_iterator_start(list);
 1548|  48.6k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1548:10): [True: 48.5k, False: 151]
  |  Branch (1548:41): [True: 46.3k, False: 2.20k]
  ------------------
 1549|  46.3k|			(void) list_iterator_next(list);
 1550|  2.35k|	}
 1551|  2.35k|	return rv;
 1552|  2.35k|}
sc_get_coolkey_driver:
 2485|  16.1k|{
 2486|  16.1k|	return sc_get_driver();
 2487|  16.1k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  518|    772|{
  519|       |	/* we need to manually detect types CK_ULONG */
  520|    772|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  229|    772|#define COOLKEY_V0_OBJECT 0
  ------------------
  521|    772|	int r;
  522|    772|	size_t len;
  523|       |
  524|    772|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1068|    772|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  525|    772|	attr_out->attribute_length = 0;
  526|    772|	attr_out->attribute_value = NULL;
  527|       |
  528|    772|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  529|    772|	if (r < 0) {
  ------------------
  |  Branch (529:6): [True: 0, False: 772]
  ------------------
  530|      0|		return r;
  531|      0|	}
  532|    772|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (532:6): [True: 247, False: 525]
  ------------------
  533|    247|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    247|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  534|    247|	}
  535|    525|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|    525|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     11|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (535:6): [True: 514, False: 11]
  |  Branch (535:34): [True: 0, False: 11]
  ------------------
  536|    514|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     11|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (536:14): [True: 0, False: 11]
  ------------------
  537|    514|		if (len != 4) {
  ------------------
  |  Branch (537:7): [True: 474, False: 40]
  ------------------
  538|    474|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    474|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  539|    474|		}
  540|     40|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|     40|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  541|     40|	}
  542|       |	/* return the length and the data */
  543|     51|	attr_out->attribute_length = len;
  544|     51|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  545|     51|	return SC_SUCCESS;
  ------------------
  |  |   28|     51|#define SC_SUCCESS				0
  ------------------
  546|    525|}
card-coolkey.c:coolkey_get_attribute_type:
  411|  55.0k|{
  412|  55.0k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  413|       |
  414|  55.0k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  415|  55.0k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  351|  5.85k|{
  352|  5.85k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  353|       |	/* don't reference beyond our buffer */
  354|  5.85k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (354:6): [True: 350, False: 5.50k]
  ------------------
  355|    350|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    350|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  356|    350|	}
  357|  5.50k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  358|  5.50k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.50k|#define SC_SUCCESS				0
  ------------------
  359|  5.85k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  553|  3.83k|{
  554|  3.83k|	int r;
  555|  3.83k|	size_t len;
  556|  3.83k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  557|       |
  558|  3.83k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (558:6): [True: 68, False: 3.77k]
  ------------------
  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.77k|	switch (attribute_head->attribute_data_type) {
  564|       |	/* ULONG has implied length of 4 */
  565|    198|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  248|    198|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (565:2): [True: 198, False: 3.57k]
  ------------------
  566|    198|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (566:7): [True: 10, False: 188]
  ------------------
  567|     10|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     10|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  568|     10|		}
  569|    188|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|    188|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  570|    188|		attr_out->attribute_length = 4;
  571|    188|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  572|    188|		return SC_SUCCESS;
  ------------------
  |  |   28|    188|#define SC_SUCCESS				0
  ------------------
  573|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  574|       |	/* return type STRING for BOOLS */
  575|     76|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  249|     76|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (575:2): [True: 76, False: 3.69k]
  ------------------
  576|     76|		attr_out->attribute_length = 1;
  577|     76|		attr_out->attribute_value =  &coolkey_static_false;
  578|     76|		return SC_SUCCESS;
  ------------------
  |  |   28|     76|#define SC_SUCCESS				0
  ------------------
  579|     94|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  250|     94|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (579:2): [True: 94, False: 3.67k]
  ------------------
  580|     94|		attr_out->attribute_length = 1;
  581|     94|		attr_out->attribute_value =  &coolkey_static_true;
  582|     94|		return SC_SUCCESS;
  ------------------
  |  |   28|     94|#define SC_SUCCESS				0
  ------------------
  583|       |	/* string type has encoded length */
  584|  1.97k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  247|  1.97k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (584:2): [True: 1.97k, False: 1.80k]
  ------------------
  585|  1.97k|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  586|  1.97k|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|  1.97k|#define SC_SUCCESS				0
  ------------------
  |  Branch (586:7): [True: 95, False: 1.87k]
  ------------------
  587|     95|			return r;
  588|     95|		}
  589|  1.87k|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (589:7): [True: 353, False: 1.52k]
  ------------------
  590|    353|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    353|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  591|    353|		}
  592|  1.52k|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  593|  1.52k|		attr_out->attribute_length = len;
  594|  1.52k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.52k|#define SC_SUCCESS				0
  ------------------
  595|  1.43k|	default:
  ------------------
  |  Branch (595:2): [True: 1.43k, False: 2.33k]
  ------------------
  596|  1.43k|		break;
  597|  3.77k|	}
  598|  1.43k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  1.43k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  599|  3.77k|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  314|   259k|{
  315|   259k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  316|       |
  317|   259k|	*len = 0;
  318|       |	/* don't reference beyond our buffer */
  319|   259k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (319:6): [True: 204k, False: 54.9k]
  ------------------
  320|   204k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   204k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  321|   204k|	}
  322|  54.9k|	switch (attribute_head->attribute_data_type) {
  323|  17.8k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  247|  17.8k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (323:2): [True: 17.8k, False: 37.0k]
  ------------------
  324|  17.8k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (324:7): [True: 296, False: 17.5k]
  ------------------
  325|    296|			break;
  326|    296|		}
  327|  17.5k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  328|  17.5k|		if (encoded_len) {
  ------------------
  |  Branch (328:7): [True: 15.7k, False: 1.87k]
  ------------------
  329|  15.7k|			*len += 2;
  330|  15.7k|		}
  331|  17.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  17.5k|#define SC_SUCCESS				0
  ------------------
  332|  1.60k|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  249|  1.60k|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (332:2): [True: 1.60k, False: 53.3k]
  ------------------
  333|  7.71k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  250|  7.71k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (333:2): [True: 6.10k, False: 48.8k]
  ------------------
  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.71k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (336:10): [True: 7.71k, False: 0]
  ------------------
  337|  7.71k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.71k|#define SC_SUCCESS				0
  ------------------
  338|      0|		break;
  339|  4.43k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  248|  4.43k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (339:2): [True: 4.43k, False: 50.5k]
  ------------------
  340|  4.43k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  341|  4.43k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.43k|#define SC_SUCCESS				0
  ------------------
  342|  24.9k|	default:
  ------------------
  |  Branch (342:2): [True: 24.9k, False: 30.0k]
  ------------------
  343|  24.9k|		break;
  344|  54.9k|	}
  345|  25.2k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  25.2k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  346|  54.9k|}
card-coolkey.c:coolkey_read_object:
 1097|  52.9k|{
 1098|  52.9k|	coolkey_read_object_param_t params;
 1099|  52.9k|	u8 *out_ptr;
 1100|  52.9k|	size_t left = 0;
 1101|  52.9k|	size_t len;
 1102|  52.9k|	int r;
 1103|       |
 1104|  52.9k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  52.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  52.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  52.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 52.9k]
  |  |  ------------------
  ------------------
 1105|       |
 1106|  52.9k|	ulong2bebytes(&params.object_id[0], object_id);
 1107|       |
 1108|  52.9k|	out_ptr = out_buf;
 1109|  52.9k|	left = out_len;
 1110|  62.6k|	do {
 1111|  62.6k|		ulong2bebytes(&params.offset[0], offset);
 1112|  62.6k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   69|  62.6k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 50.0k, False: 12.6k]
  |  |  ------------------
  ------------------
 1113|  62.6k|		len = left;
 1114|  62.6k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   73|  62.6k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   89|  62.6k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1115|  62.6k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1116|  62.6k|		if (r < 0) {
  ------------------
  |  Branch (1116:7): [True: 47.3k, False: 15.2k]
  ------------------
 1117|  47.3k|			goto fail;
 1118|  47.3k|		}
 1119|       |		/* sanity check to make sure we don't overflow left */
 1120|  15.2k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1120:7): [True: 592, False: 14.6k]
  |  Branch (1120:23): [True: 1.40k, False: 13.2k]
  ------------------
 1121|  1.99k|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.99k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1122|  1.99k|			goto fail;
 1123|  1.99k|		}
 1124|  13.2k|		out_ptr += len;
 1125|  13.2k|		offset += len;
 1126|  13.2k|		left -= len;
 1127|  13.2k|	} while (left != 0);
  ------------------
  |  Branch (1127:11): [True: 9.73k, False: 3.54k]
  ------------------
 1128|       |
 1129|  3.54k|	return (int)out_len;
 1130|       |
 1131|  49.3k|fail:
 1132|  49.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  49.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  49.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  49.3k|	int _ret = r; \
  |  |  |  |  155|  49.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 49.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  49.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|  49.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 49.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  49.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  49.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|  49.3k|	return _ret; \
  |  |  |  |  163|  49.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1133|  49.3k|}
card-coolkey.c:coolkey_apdu_io:
  913|  93.6k|{
  914|  93.6k|	int r;
  915|  93.6k|	sc_apdu_t apdu;
  916|  93.6k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  917|  93.6k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  918|  93.6k|	u8 *rbuf;
  919|  93.6k|	size_t rbuflen;
  920|  93.6k|	int cse = 0;
  921|       |
  922|       |
  923|  93.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  93.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  93.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  93.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 93.6k]
  |  |  ------------------
  ------------------
  924|       |
  925|  93.6k|	sc_log(card->ctx, "%02x %02x %02x %zu : %zu %zu",
  ------------------
  |  |   71|  93.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__
  |  |  ------------------
  ------------------
  926|  93.6k|			ins, p1, p2, sendbuflen, card->max_send_size, card->max_recv_size);
  927|       |
  928|  93.6k|	rbuf = rbufinitbuf;
  929|  93.6k|	rbuflen = sizeof(rbufinitbuf);
  930|       |
  931|       |	/* if caller provided a buffer and length */
  932|  93.6k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (932:6): [True: 78.2k, False: 15.3k]
  |  Branch (932:17): [True: 78.2k, False: 0]
  |  Branch (932:29): [True: 78.2k, False: 0]
  |  Branch (932:43): [True: 72.7k, False: 5.49k]
  ------------------
  933|  72.7k|		rbuf = *recvbuf;
  934|  72.7k|		rbuflen = *recvbuflen;
  935|  72.7k|	}
  936|       |
  937|  93.6k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (937:6): [True: 78.2k, False: 15.4k]
  |  Branch (937:17): [True: 0, False: 15.4k]
  ------------------
  938|  78.2k|		if (recvbuf) {
  ------------------
  |  Branch (938:7): [True: 62.8k, False: 15.3k]
  ------------------
  939|  62.8k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  62.8k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  940|  62.8k|		} else {
  941|  15.3k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  15.3k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  942|  15.3k|		}
  943|  78.2k|	} else {
  944|  15.4k|		if (recvbuf) {
  ------------------
  |  Branch (944:7): [True: 15.4k, False: 0]
  ------------------
  945|  15.4k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  15.4k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  946|  15.4k|		} else {
  947|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  948|      0|		}
  949|  15.4k|	}
  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|  93.6k|	if (nonce) {
  ------------------
  |  Branch (956:6): [True: 67.0k, False: 26.5k]
  ------------------
  957|  67.0k|		u8 *buf = rsendbuf;
  958|  67.0k|		if (sendbuf) {
  ------------------
  |  Branch (958:7): [True: 67.0k, False: 0]
  ------------------
  959|  67.0k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   69|  67.0k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 67.0k, False: 0]
  |  |  ------------------
  ------------------
  960|  67.0k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  961|  67.0k|			buf += sendbuflen;
  962|  67.0k|		}
  963|  67.0k|		memcpy(buf, nonce, nonce_len);
  964|  67.0k|		sendbuflen += nonce_len;
  965|  67.0k|		sendbuf =rsendbuf;
  966|  67.0k|	}
  967|       |
  968|  93.6k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  969|       |
  970|  93.6k|	apdu.lc = sendbuflen;
  971|  93.6k|	apdu.datalen = sendbuflen;
  972|  93.6k|	apdu.data = sendbuf;
  973|       |
  974|       |
  975|       |	/* coolkey uses non-standard classes */
  976|  93.6k|	apdu.cla = cla;
  977|       |
  978|  93.6k|	if (recvbuf) {
  ------------------
  |  Branch (978:6): [True: 78.2k, False: 15.3k]
  ------------------
  979|  78.2k|		apdu.resp = rbuf;
  980|  78.2k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (980:13): [True: 16.6k, False: 61.6k]
  ------------------
  981|  78.2k|		apdu.resplen = rbuflen;
  982|  78.2k|	} else {
  983|  15.3k|		 apdu.resp =  rbuf;
  984|  15.3k|		 apdu.le = 0;
  985|  15.3k|		 apdu.resplen = 0;
  986|  15.3k|	}
  987|       |
  988|  93.6k|	sc_log(card->ctx, "calling sc_transmit_apdu flags=%lx le=%zu, resplen=%zu, resp=%p",
  ------------------
  |  |   71|  93.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__
  |  |  ------------------
  ------------------
  989|  93.6k|			apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  990|       |
  991|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  992|  93.6k|	r = sc_transmit_apdu(card, &apdu);
  993|       |
  994|  93.6k|	sc_log(card->ctx, "result r=%d apdu.resplen=%zu sw1=%02x sw2=%02x",
  ------------------
  |  |   71|  93.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__
  |  |  ------------------
  ------------------
  995|  93.6k|			r, apdu.resplen, apdu.sw1, apdu.sw2);
  996|       |
  997|  93.6k|	if (r < 0) {
  ------------------
  |  Branch (997:6): [True: 1.25k, False: 92.4k]
  ------------------
  998|  1.25k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  1.25k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  999|  1.25k|		goto err;
 1000|  1.25k|	}
 1001|  92.4k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1002|  92.4k|	if (r < 0) {
  ------------------
  |  Branch (1002:6): [True: 55.0k, False: 37.4k]
  ------------------
 1003|  55.0k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  55.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1004|  55.0k|		goto err;
 1005|  55.0k|	}
 1006|       |
 1007|  37.4k|	if (recvbuflen) {
  ------------------
  |  Branch (1007:6): [True: 29.9k, False: 7.46k]
  ------------------
 1008|  29.9k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1008:7): [True: 29.8k, False: 94]
  |  Branch (1008:18): [True: 0, False: 29.8k]
  ------------------
 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|  29.9k|		*recvbuflen =  apdu.resplen;
 1017|  29.9k|		r = (int)*recvbuflen;
 1018|  29.9k|	}
 1019|       |
 1020|  93.6k|err:
 1021|  93.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  93.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  93.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  93.6k|	int _ret = r; \
  |  |  |  |  155|  93.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 65.2k, False: 28.3k]
  |  |  |  |  ------------------
  |  |  |  |  156|  65.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|  56.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 56.2k, False: 9.03k]
  |  |  |  |  ------------------
  |  |  |  |  157|  65.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  65.2k|	} else { \
  |  |  |  |  159|  28.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  28.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  28.3k|	} \
  |  |  |  |  162|  93.6k|	return _ret; \
  |  |  |  |  163|  93.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1022|  93.6k|}
card-coolkey.c:coolkey_find_object_by_id:
  826|  19.0k|{
  827|  19.0k|	int pos;
  828|  19.0k|	static sc_cardctl_coolkey_object_t cmp = {{
  829|  19.0k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  19.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  830|  19.0k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  823|  19.0k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  823|  19.0k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  831|  19.0k|	}, 0, 0, NULL};
  832|       |
  833|  19.0k|	cmp.id = object_id;
  834|  19.0k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (834:6): [True: 11.3k, False: 7.69k]
  ------------------
  835|  11.3k|		return NULL;
  836|       |
  837|  7.69k|	return list_get_at(list, pos);
  838|  19.0k|}
card-coolkey.c:coolkey_find_attribute:
 1420|   135k|{
 1421|   135k|	u8 object_record_type;
 1422|   135k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1423|   135k|	const u8 *obj = attribute->object->data;
 1424|   135k|	const u8 *attr = NULL;
 1425|   135k|	size_t buf_len = attribute->object->length;
 1426|   135k|	coolkey_object_header_t *object_head;
 1427|   135k|	int attribute_count,i;
 1428|   135k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1068|   135k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1429|   135k|	attribute->attribute_length = 0;
 1430|   135k|	attribute->attribute_value = NULL;
 1431|       |
 1432|   135k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   135k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   135k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   135k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   135k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 135k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1433|       |
 1434|   135k|	if (obj == NULL) {
  ------------------
  |  Branch (1434:6): [True: 52.4k, False: 82.5k]
  ------------------
 1435|       |		/* cast away const so we can cache the data value */
 1436|  52.4k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1437|  52.4k|		if (r < 0) {
  ------------------
  |  Branch (1437:7): [True: 49.1k, False: 3.26k]
  ------------------
 1438|  49.1k|			return r;
 1439|  49.1k|		}
 1440|  3.26k|		obj = attribute->object->data;
 1441|  3.26k|		if (obj == NULL) {
  ------------------
  |  Branch (1441:7): [True: 0, False: 3.26k]
  ------------------
 1442|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1443|      0|		}
 1444|  3.26k|	}
 1445|       |
 1446|       |	/* should be a static assert so we catch this at compile time */
 1447|   135k|	static_assert(sizeof(coolkey_object_header_t) >= sizeof(coolkey_v0_object_header_t), "internal error");
 1448|       |	/* make sure we have enough of the object to read the record_type */
 1449|  85.8k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1449:6): [True: 1.15k, False: 84.6k]
  ------------------
 1450|  1.15k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  1.15k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1451|  1.15k|	}
 1452|  84.6k|	object_head = (coolkey_object_header_t *)obj;
 1453|  84.6k|	object_record_type = object_head->record_type;
 1454|       |	/* make sure it's a type we recognize */
 1455|  84.6k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  230|  84.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  9.09k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1455:6): [True: 9.09k, False: 75.5k]
  |  Branch (1455:51): [True: 6.36k, False: 2.73k]
  ------------------
 1456|  6.36k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  6.36k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1457|  6.36k|	}
 1458|       |
 1459|       |	/*
 1460|       |	 * now loop through all the attributes in the list. first find the start of the list
 1461|       |	 */
 1462|  78.3k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1463|  78.3k|	if (attr == NULL) {
  ------------------
  |  Branch (1463:6): [True: 305, False: 78.0k]
  ------------------
 1464|    305|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    305|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1465|    305|	}
 1466|  78.0k|	buf_len -= (attr-obj);
 1467|       |
 1468|       |	/* now get the count */
 1469|  78.0k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1470|   127k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1470:12): [True: 56.3k, False: 71.3k]
  ------------------
 1471|  56.3k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1472|       |		/* make sure we have the complete record */
 1473|  56.3k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1473:7): [True: 0, False: 56.3k]
  |  Branch (1473:31): [True: 2.03k, False: 54.2k]
  ------------------
 1474|  2.03k|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  2.03k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1475|  2.03k|		}
 1476|       |		/* does the attribute match the one we are looking for */
 1477|  54.2k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1477:7): [True: 4.61k, False: 49.6k]
  ------------------
 1478|       |			/* yup, return it */
 1479|  4.61k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1480|  4.61k|		}
 1481|       |		/* go to the next attribute on the list */
 1482|  49.6k|		buf_len -= record_len;
 1483|  49.6k|		attr += record_len;
 1484|  49.6k|	}
 1485|       |	/* not find in attribute list, check the fixed attribute record */
 1486|  71.3k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  71.3k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1486:6): [True: 69.4k, False: 1.96k]
  ------------------
 1487|  69.4k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1488|       |
 1489|  69.4k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1490|  69.4k|	}
 1491|  1.96k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|  1.96k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.96k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.96k|	int _ret = r; \
  |  |  |  |  155|  1.96k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.96k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.96k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.96k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.96k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.96k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.96k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.96k|	return _ret; \
  |  |  |  |  163|  1.96k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1492|  1.96k|}
card-coolkey.c:coolkey_attribute_start:
  422|  80.9k|{
  423|  80.9k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  230|  80.9k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (423:18): [True: 75.5k, False: 5.39k]
  ------------------
  424|  80.9k|			sizeof(coolkey_v0_object_header_t);
  425|       |
  426|  80.9k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  230|  80.9k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  5.39k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (426:6): [True: 5.39k, False: 75.5k]
  |  Branch (426:51): [True: 0, False: 5.39k]
  ------------------
  427|      0|		return NULL;
  428|      0|	}
  429|  80.9k|	if (offset > buf_len) {
  ------------------
  |  Branch (429:6): [True: 305, False: 80.6k]
  ------------------
  430|    305|		return NULL;
  431|    305|	}
  432|  80.6k|	return obj + offset;
  433|  80.9k|}
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: 2.73k, False: 75.2k]
  ------------------
  505|  2.73k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  506|  2.73k|	}
  507|  75.2k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  75.2k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (507:6): [True: 0, False: 75.2k]
  ------------------
  508|      0|		return 0;
  509|      0|	}
  510|  75.2k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  511|  75.2k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  441|  2.73k|{
  442|  2.73k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  443|  2.73k|	const u8 *attr;
  444|  2.73k|	int count = 0;
  445|  2.73k|	size_t attribute_data_len;
  446|       |
  447|       |	/* make sure we have enough of the object to read the record_type */
  448|  2.73k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (448:6): [True: 76, False: 2.65k]
  ------------------
  449|     76|		return 0;
  450|     76|	}
  451|       |	/*
  452|       |	 * now loop through all the attributes in the list. first find the start of the list
  453|       |	 */
  454|  2.65k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  229|  2.65k|#define COOLKEY_V0_OBJECT 0
  ------------------
  455|  2.65k|	if (attr == NULL) {
  ------------------
  |  Branch (455:6): [True: 0, False: 2.65k]
  ------------------
  456|      0|		return 0;
  457|      0|	}
  458|       |
  459|  2.65k|	buf_len -= (attr-obj);
  460|  2.65k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  461|  2.65k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (461:6): [True: 621, False: 2.03k]
  ------------------
  462|    621|		return 0;
  463|    621|	}
  464|       |
  465|  4.18k|	while (attribute_data_len) {
  ------------------
  |  Branch (465:9): [True: 3.08k, False: 1.10k]
  ------------------
  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: 931, False: 2.15k]
  ------------------
  473|    931|			break;
  474|    931|		}
  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.15k|		if (len > buf_len)
  ------------------
  |  Branch (480:7): [True: 0, False: 2.15k]
  ------------------
  481|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  482|  2.15k|		count++;
  483|  2.15k|		attr += len;
  484|  2.15k|		buf_len -= len;
  485|  2.15k|		attribute_data_len -= len;
  486|  2.15k|	}
  487|  2.03k|	return count;
  488|  2.03k|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  381|  5.07k|{
  382|  5.07k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  383|  5.07k|	size_t len;
  384|  5.07k|	int r;
  385|       |
  386|  5.07k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  387|  5.07k|	if (r < 0) {
  ------------------
  |  Branch (387:6): [True: 350, False: 4.72k]
  ------------------
  388|    350|		return buf_len; /* skip to the end, ignore the rest of the record */
  389|    350|	}
  390|  4.72k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   69|  4.72k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.26k, False: 3.46k]
  |  |  ------------------
  ------------------
  391|  5.07k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  492|  75.2k|{
  493|  75.2k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  494|       |
  495|  75.2k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (495:6): [True: 25.6k, False: 49.6k]
  ------------------
  496|  25.6k|		return 0;
  497|  25.6k|	}
  498|  49.6k|	return bebytes2ushort(object_head->attribute_count);
  499|  75.2k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  395|  56.3k|{
  396|  56.3k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  229|  56.3k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (396:6): [True: 1.99k, False: 54.3k]
  ------------------
  397|  1.99k|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  398|  1.99k|	}
  399|  54.3k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  230|  54.3k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (399:6): [True: 0, False: 54.3k]
  ------------------
  400|      0|		return buf_len; /* skip to the end */
  401|      0|	}
  402|  54.3k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  403|  54.3k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  365|   257k|{
  366|   257k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  367|   257k|	size_t len = 0;
  368|   257k|	int r;
  369|       |
  370|   257k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  371|   257k|	if (r < 0) {
  ------------------
  |  Branch (371:6): [True: 229k, False: 27.8k]
  ------------------
  372|   229k|		return buf_len; /* skip to the end, ignore the rest of the record */
  373|   229k|	}
  374|       |
  375|  27.8k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   69|  27.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.91k, False: 25.9k]
  |  |  ------------------
  ------------------
  376|   257k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  675|  69.4k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  676|  69.4k|	unsigned long cka_id = fixed_attributes & 0xf;
  677|  69.4k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  678|  69.4k|	unsigned long mask, bit;
  679|       |
  680|  69.4k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  69.4k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (680:6): [True: 9.64k, False: 59.7k]
  ------------------
  681|  9.64k|		attr_out->attribute_length = 1;
  682|  9.64k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  683|  9.64k|		return SC_SUCCESS;
  ------------------
  |  |   28|  9.64k|#define SC_SUCCESS				0
  ------------------
  684|  9.64k|	}
  685|  59.7k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  59.7k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (685:6): [True: 21.4k, False: 38.2k]
  ------------------
  686|  21.4k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1069|  21.4k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  687|  21.4k|		attr_out->attribute_length = 4;
  688|  21.4k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  689|  21.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  21.4k|#define SC_SUCCESS				0
  ------------------
  690|  21.4k|	}
  691|       |	/* If it matched, it must be one of the booleans */
  692|  38.2k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  693|  38.2k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  694|       |	/* attribute isn't in the list */
  695|  38.2k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (695:6): [True: 15.0k, False: 23.2k]
  ------------------
  696|  15.0k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  15.0k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  697|  15.0k|	}
  698|  23.2k|	attr_out->attribute_length = 1;
  699|  23.2k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (699:30): [True: 7.12k, False: 16.0k]
  ------------------
  700|  23.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  23.2k|#define SC_SUCCESS				0
  ------------------
  701|  38.2k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  621|  38.2k|{
  622|  38.2k|	switch(type) {
  623|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (623:2): [True: 0, False: 38.2k]
  ------------------
  624|  2.62k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  2.62k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (624:2): [True: 2.62k, False: 35.6k]
  ------------------
  625|  3.53k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  3.53k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (625:2): [True: 3.53k, False: 34.7k]
  ------------------
  626|  1.81k|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|  1.81k|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (626:2): [True: 1.81k, False: 36.4k]
  ------------------
  627|  1.81k|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|  1.81k|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (627:2): [True: 1.81k, False: 36.4k]
  ------------------
  628|  1.81k|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|  1.81k|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (628:2): [True: 1.81k, False: 36.4k]
  ------------------
  629|  1.81k|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|  1.81k|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (629:2): [True: 1.81k, False: 36.4k]
  ------------------
  630|  1.81k|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|  1.81k|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (630:2): [True: 1.81k, False: 36.4k]
  ------------------
  631|  1.81k|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|  1.81k|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (631:2): [True: 1.81k, False: 36.4k]
  ------------------
  632|  1.81k|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|  1.81k|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (632:2): [True: 1.81k, False: 36.4k]
  ------------------
  633|  1.81k|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|  1.81k|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (633:2): [True: 1.81k, False: 36.4k]
  ------------------
  634|  1.81k|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|  1.81k|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (634:2): [True: 1.81k, False: 36.4k]
  ------------------
  635|  1.81k|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|  1.81k|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (635:2): [True: 1.81k, False: 36.4k]
  ------------------
  636|  1.81k|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|  1.81k|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (636:2): [True: 1.81k, False: 36.4k]
  ------------------
  637|  1.81k|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|  1.81k|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (637:2): [True: 1.81k, False: 36.4k]
  ------------------
  638|  1.81k|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|  1.81k|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (638:2): [True: 1.81k, False: 36.4k]
  ------------------
  639|  1.81k|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|  1.81k|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (639:2): [True: 1.81k, False: 36.4k]
  ------------------
  640|  6.73k|	default: break;
  ------------------
  |  Branch (640:2): [True: 6.73k, False: 31.5k]
  ------------------
  641|  38.2k|	}
  642|  6.73k|	return 0; /* return no bits */
  643|  38.2k|}
card-coolkey.c:sc_get_driver:
 2458|  16.1k|{
 2459|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2460|       |
 2461|  16.1k|	coolkey_ops = *iso_drv->ops;
 2462|  16.1k|	coolkey_ops.match_card = coolkey_match_card;
 2463|  16.1k|	coolkey_ops.init = coolkey_init;
 2464|  16.1k|	coolkey_ops.finish = coolkey_finish;
 2465|       |
 2466|  16.1k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2467|  16.1k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2468|  16.1k|	coolkey_ops.read_binary = coolkey_read_binary;
 2469|  16.1k|	coolkey_ops.write_binary = coolkey_write_binary;
 2470|  16.1k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2471|  16.1k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2472|  16.1k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2473|  16.1k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2474|  16.1k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2475|  16.1k|	coolkey_ops.check_sw = coolkey_check_sw;
 2476|  16.1k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2477|  16.1k|	coolkey_ops.logout = coolkey_logout;
 2478|  16.1k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2479|       |
 2480|  16.1k|	return &coolkey_drv;
 2481|  16.1k|}
card-coolkey.c:coolkey_match_card:
 2297|  7.44k|{
 2298|  7.44k|	int r;
 2299|       |
 2300|  7.44k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.44k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.44k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.44k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.44k]
  |  |  ------------------
  ------------------
 2301|       |
 2302|  7.44k|	r = coolkey_select_applet(card);
 2303|  7.44k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  7.44k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2303:6): [True: 1.49k, False: 5.95k]
  ------------------
 2304|  1.49k|		sc_apdu_t apdu;
 2305|       |
 2306|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2307|       |		 * on Coolkey applet (reserved for GetMemory function),
 2308|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2309|       |		 */
 2310|  1.49k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.49k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   80|  1.49k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2311|  1.49k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   73|  1.49k|#define COOLKEY_CLASS           0xb0
  ------------------
 2312|  1.49k|		apdu.le = 0x00;
 2313|  1.49k|		apdu.resplen = 0;
 2314|  1.49k|		apdu.resp = NULL;
 2315|  1.49k|		r = sc_transmit_apdu(card, &apdu);
 2316|  1.49k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.99k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2316:7): [True: 1.49k, False: 2]
  |  Branch (2316:26): [True: 1.10k, False: 389]
  |  Branch (2316:46): [True: 1.09k, False: 8]
  ------------------
 2317|  1.09k|			return 1;
 2318|  1.09k|		}
 2319|    399|		return 0;
 2320|  1.49k|	}
 2321|  5.95k|	return 0;
 2322|  7.44k|}
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:
 2326|  1.09k|{
 2327|  1.09k|	int r;
 2328|  1.09k|	unsigned long flags;
 2329|  1.09k|	unsigned long ext_flags;
 2330|  1.09k|	coolkey_private_data_t * priv;
 2331|       |
 2332|  1.09k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.09k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.09k]
  |  |  ------------------
  ------------------
 2333|       |
 2334|  1.09k|	r = coolkey_initialize(card);
 2335|  1.09k|	if (r < 0) {
  ------------------
  |  Branch (2335:6): [True: 416, False: 680]
  ------------------
 2336|    416|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    416|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    416|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    416|	int _ret = r; \
  |  |  |  |  155|    416|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 416, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    416|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    416|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 416, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    416|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    416|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    416|	return _ret; \
  |  |  |  |  163|    416|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2337|    416|	}
 2338|       |
 2339|    680|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2340|       |
 2341|       |	/* set Token Major/minor version */
 2342|    680|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    680|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2343|       |
 2344|    680|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2345|    680|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2346|    680|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2347|       |
 2348|    680|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  174|    680|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  173|    680|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  175|    680|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    680|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2349|    680|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  201|    680|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  202|    680|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2350|       |
 2351|    680|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2352|    680|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2353|    680|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2354|       |
 2355|       |
 2356|    680|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    680|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2357|    680|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2357:6): [True: 391, False: 289]
  ------------------
 2358|    391|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    391|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2359|    391|	}
 2360|       |
 2361|    680|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 680]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2362|    680|}
card-coolkey.c:coolkey_initialize:
 2166|  1.09k|{
 2167|  1.09k|	int r;
 2168|  1.09k|	coolkey_private_data_t *priv = NULL;
 2169|  1.09k|	coolkey_life_cycle_t life_cycle;
 2170|  1.09k|	coolkey_object_info_t object_info;
 2171|  1.09k|	int combined_processed = 0;
 2172|       |
 2173|       |	/* already found? */
 2174|  1.09k|	if (card->drv_data) {
  ------------------
  |  Branch (2174:6): [True: 0, False: 1.09k]
  ------------------
 2175|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2176|      0|	}
 2177|  1.09k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.09k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2178|       |
 2179|  1.09k|	priv = coolkey_new_private_data();
 2180|  1.09k|	if (priv == NULL) {
  ------------------
  |  Branch (2180:6): [True: 0, False: 1.09k]
  ------------------
 2181|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2182|      0|		goto cleanup;
 2183|      0|	}
 2184|  1.09k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2185|  1.09k|	if (r < 0) {
  ------------------
  |  Branch (2185:6): [True: 87, False: 1.00k]
  ------------------
 2186|     87|		goto cleanup;
 2187|     87|	}
 2188|       |
 2189|       |	/* Select a coolkey read the coolkey objects out */
 2190|  1.00k|	r = coolkey_select_applet(card);
 2191|  1.00k|	if (r < 0) {
  ------------------
  |  Branch (2191:6): [True: 6, False: 1.00k]
  ------------------
 2192|      6|		goto cleanup;
 2193|      6|	}
 2194|       |
 2195|  1.00k|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2196|  1.00k|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2197|  1.00k|	priv->pin_count = life_cycle.pin_count;
 2198|  1.00k|	priv->life_cycle = life_cycle.life_cycle;
 2199|       |
 2200|       |	/* walk down the list of objects and read them off the token */
 2201|  1.00k|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  105|  1.00k|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2202|  14.2k|	while (r >= 0) {
  ------------------
  |  Branch (2202:9): [True: 13.4k, False: 838]
  ------------------
 2203|  13.4k|		unsigned long object_id;
 2204|  13.4k|		unsigned long object_len;
 2205|       |
 2206|       |		/* The card did not return what we expected: Lets try other objects */
 2207|  13.4k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2207:7): [True: 13, False: 13.4k]
  ------------------
 2208|     13|			break;
 2209|       |
 2210|       |		/* TODO also look at the ACL... */
 2211|       |
 2212|  13.4k|		object_id = bebytes2ulong(object_info.object_id);
 2213|  13.4k|		object_len = bebytes2ulong(object_info.object_length);
 2214|       |		/* Avoid insanely large data */
 2215|  13.4k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  13.4k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2215:7): [True: 13, False: 13.3k]
  ------------------
 2216|     13|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     13|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2217|     13|			goto cleanup;
 2218|     13|		}
 2219|       |
 2220|       |		/* the combined object is a single object that can store the other objects.
 2221|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2222|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2223|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2224|       |		 * process it separately so that we can have both combined objects managed
 2225|       |		 * by TPS and user managed certs on the same token */
 2226|  13.3k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  110|  13.3k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2226:7): [True: 272, False: 13.1k]
  ------------------
 2227|    272|			u8 *object = malloc(object_len);
 2228|    272|			if (object == NULL) {
  ------------------
  |  Branch (2228:8): [True: 0, False: 272]
  ------------------
 2229|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2230|      0|				break;
 2231|      0|			}
 2232|    272|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  110|    272|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2233|    272|				priv->nonce, sizeof(priv->nonce));
 2234|    272|			if (r < 0) {
  ------------------
  |  Branch (2234:8): [True: 56, False: 216]
  ------------------
 2235|     56|				free(object);
 2236|     56|				break;
 2237|     56|			}
 2238|    216|			r = coolkey_process_combined_object(card, priv, object, r);
 2239|    216|			free(object);
 2240|    216|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    216|#define SC_SUCCESS				0
  ------------------
  |  Branch (2240:8): [True: 83, False: 133]
  ------------------
 2241|     83|				break;
 2242|     83|			}
 2243|    133|			combined_processed = 1;
 2244|  13.1k|		} else {
 2245|  13.1k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  13.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__
  |  |  ------------------
  ------------------
 2246|  13.1k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2247|  13.1k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  13.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2247:8): [True: 3.73k, False: 9.38k]
  ------------------
 2248|  3.73k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  3.73k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2249|  13.1k|		}
 2250|       |
 2251|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2252|  13.2k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  106|  13.2k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2253|  13.2k|	}
 2254|    990|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    990|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2254:6): [True: 295, False: 695]
  ------------------
 2255|       |		/* This means the card does not cooperate at all: bail out */
 2256|    295|		if (r >= 0) {
  ------------------
  |  Branch (2256:7): [True: 13, False: 282]
  ------------------
 2257|     13|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     13|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2258|     13|		}
 2259|    295|		goto cleanup;
 2260|    295|	}
 2261|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2262|    695|	if (!combined_processed) {
  ------------------
  |  Branch (2262:6): [True: 566, False: 129]
  ------------------
 2263|    566|		global_platform_cplc_data_t cplc_data;
 2264|       |		/* select the card manager, because a card with applet only will have
 2265|       |		   already selected the coolkey applet */
 2266|       |
 2267|    566|		r = gp_select_card_manager(card);
 2268|    566|		if (r < 0) {
  ------------------
  |  Branch (2268:7): [True: 3, False: 563]
  ------------------
 2269|      3|			goto cleanup;
 2270|      3|		}
 2271|       |
 2272|    563|		r = gp_get_cplc_data(card, &cplc_data);
 2273|    563|		if (r < 0) {
  ------------------
  |  Branch (2273:7): [True: 12, False: 551]
  ------------------
 2274|     12|			goto cleanup;
 2275|     12|		}
 2276|    551|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2277|    551|		priv->token_name = (u8 *)strdup("COOLKEY");
 2278|    551|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2278:7): [True: 0, False: 551]
  ------------------
 2279|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2280|      0|			goto cleanup;
 2281|      0|		}
 2282|    551|		priv->token_name_length = sizeof("COOLKEY")-1;
 2283|    551|	}
 2284|    680|	card->drv_data = priv;
 2285|    680|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 680]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2286|       |
 2287|    416|cleanup:
 2288|    416|	if (priv) {
  ------------------
  |  Branch (2288:6): [True: 416, False: 0]
  ------------------
 2289|    416|		coolkey_free_private_data(priv);
 2290|    416|	}
 2291|    416|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    416|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    416|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    416|	int _ret = r; \
  |  |  |  |  155|    416|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 416, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    416|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    416|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 416, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    416|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    416|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    416|	return _ret; \
  |  |  |  |  163|    416|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2292|    416|}
card-coolkey.c:coolkey_new_private_data:
  773|  1.09k|{
  774|  1.09k|	coolkey_private_data_t *priv;
  775|       |
  776|       |	/* allocate priv and zero all the fields */
  777|  1.09k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  778|  1.09k|	if (!priv)
  ------------------
  |  Branch (778:6): [True: 0, False: 1.09k]
  ------------------
  779|      0|		return NULL;
  780|       |
  781|       |	/* set other fields as appropriate */
  782|  1.09k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|  1.09k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  783|  1.09k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.09k]
  ------------------
  784|  1.09k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (784:6): [True: 0, False: 1.09k]
  ------------------
  785|  1.09k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (785:6): [True: 0, False: 1.09k]
  ------------------
  786|      0|		coolkey_free_private_data(priv);
  787|      0|		return NULL;
  788|      0|	}
  789|       |
  790|  1.09k|	return priv;
  791|  1.09k|}
card-coolkey.c:coolkey_get_life_cycle:
 1029|  1.09k|{
 1030|  1.09k|	coolkey_status_t status;
 1031|  1.09k|	u8 *receive_buf;
 1032|  1.09k|	size_t receive_len;
 1033|  1.09k|	int len;
 1034|       |
 1035|  1.09k|	receive_len = sizeof(*life_cycle);
 1036|  1.09k|	receive_buf = (u8 *)life_cycle;
 1037|  1.09k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   73|  1.09k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   79|  1.09k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1038|  1.09k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1039|  1.09k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1039:6): [True: 1.00k, False: 89]
  ------------------
 1040|  1.00k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.00k|#define SC_SUCCESS				0
  ------------------
 1041|  1.00k|	}
 1042|       |
 1043|     89|	receive_len = 1;
 1044|     89|	receive_buf = &life_cycle->life_cycle;
 1045|     89|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   73|     89|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   79|     89|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1046|     89|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1047|     89|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1047:6): [True: 79, False: 10]
  ------------------
 1048|     79|		return len;
 1049|     79|	}
 1050|     10|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1050:6): [True: 2, False: 8]
  ------------------
 1051|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1052|      2|	}
 1053|      8|	receive_len = sizeof(status);
 1054|      8|	receive_buf = (u8 *)&status;
 1055|      8|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   73|      8|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   80|      8|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1056|      8|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1057|      8|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1057:6): [True: 2, False: 6]
  ------------------
 1058|      2|		return len;
 1059|      2|	}
 1060|      6|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1060:6): [True: 4, False: 2]
  ------------------
 1061|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1062|      4|	}
 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|      6|}
card-coolkey.c:coolkey_list_object:
 2153|  14.2k|{
 2154|  14.2k|	u8 *rbuf = (u8 *) object_info;
 2155|  14.2k|	size_t rbuflen = sizeof(*object_info);
 2156|       |
 2157|  14.2k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   73|  14.2k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   82|  14.2k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2158|  14.2k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2159|       |
 2160|  14.2k|}
card-coolkey.c:coolkey_process_combined_object:
 2017|    216|{
 2018|    216|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2019|    216|	unsigned short compressed_offset;
 2020|    216|	unsigned short compressed_length;
 2021|    216|	unsigned short compressed_type;
 2022|    216|	size_t object_offset;
 2023|    216|	unsigned short object_count;
 2024|    216|	coolkey_decompressed_header_t *decompressed_header;
 2025|    216|	u8 *decompressed_object = NULL;
 2026|    216|	size_t decompressed_object_len = 0;
 2027|    216|	int free_decompressed = 0;
 2028|    216|	int i, r;
 2029|       |
 2030|    216|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2030:6): [True: 2, False: 214]
  ------------------
 2031|      2|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      2|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2032|      2|	}
 2033|    214|	compressed_offset = bebytes2ushort(header->compression_offset);
 2034|    214|	compressed_length = bebytes2ushort(header->compression_length);
 2035|    214|	compressed_type   = bebytes2ushort(header->compression_type);
 2036|       |
 2037|    214|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2037:6): [True: 16, False: 198]
  ------------------
 2038|     16|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     16|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2039|     16|	}
 2040|       |
 2041|       |	/* store the CUID */
 2042|    198|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2043|       |
 2044|    198|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  181|    198|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2044:6): [True: 142, False: 56]
  ------------------
 2045|    142|#ifdef ENABLE_ZLIB
 2046|    142|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|    142|#define COMPRESSION_AUTO	0
  ------------------
 2047|    142|		if (r)
  ------------------
  |  Branch (2047:7): [True: 12, False: 130]
  ------------------
 2048|     12|			goto done;
 2049|    130|		free_decompressed = 1;
 2050|       |#else
 2051|       |		sc_log(card->ctx, "Coolkey compression not supported, no zlib");
 2052|       |		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2053|       |#endif
 2054|    130|	}  else {
 2055|     56|		decompressed_object =&object[compressed_offset];
 2056|     56|		decompressed_object_len = (size_t) compressed_length;
 2057|     56|	}
 2058|       |
 2059|    186|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2060|       |
 2061|    186|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2061:6): [True: 9, False: 177]
  ------------------
 2062|      9|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      9|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2063|      9|		goto done;
 2064|      9|	}
 2065|    177|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2066|    177|	object_count = bebytes2ushort(decompressed_header->object_count);
 2067|       |
 2068|       |
 2069|       |	/*
 2070|       |	 * using 2 different tests here so we can log different errors if logging is
 2071|       |	 * turned on.
 2072|       |	 */
 2073|       |	/* make sure token_name doesn't overrun the buffer */
 2074|    177|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2074:6): [True: 0, False: 177]
  ------------------
 2075|    177|		offsetof(coolkey_decompressed_header_t, token_name) > decompressed_object_len) {
 2076|      0|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2077|      0|		goto done;
 2078|      0|	}
 2079|       |	/* make sure it doesn't overlap the object space */
 2080|    177|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2080:6): [True: 4, False: 173]
  ------------------
 2081|    177|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2082|      4|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      4|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2083|      4|		goto done;
 2084|      4|	}
 2085|       |
 2086|       |	/* store the token name in the priv structure so the emulator can set it */
 2087|    173|	free(priv->token_name);
 2088|    173|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2089|    173|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2089:6): [True: 0, False: 173]
  ------------------
 2090|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2091|      0|		goto done;
 2092|      0|	}
 2093|    173|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2094|    173|							decompressed_header->token_name_length);
 2095|    173|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2096|    173|	priv->token_name_length = decompressed_header->token_name_length;
 2097|       |
 2098|    173|	if (object_count > decompressed_object_len / sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2098:6): [True: 13, False: 160]
  ------------------
 2099|     13|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     13|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2100|     13|		goto done;
 2101|     13|	}
 2102|       |
 2103|    991|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2103:12): [True: 858, False: 133]
  ------------------
 2104|    858|		u8 *current_object = NULL;
 2105|    858|		coolkey_combined_object_header_t *object_header = NULL;
 2106|    858|		unsigned long object_id;
 2107|    858|		int current_object_len;
 2108|       |
 2109|       |		/* Can we read the object header at all? */
 2110|    858|		if (decompressed_object_len < sizeof(coolkey_combined_object_header_t) ||
  ------------------
  |  Branch (2110:7): [True: 0, False: 858]
  ------------------
 2111|    858|		    object_offset > decompressed_object_len - sizeof(coolkey_combined_object_header_t)) {
  ------------------
  |  Branch (2111:7): [True: 23, False: 835]
  ------------------
 2112|     23|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     23|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2113|     23|			goto done;
 2114|     23|		}
 2115|       |
 2116|    835|		current_object = &decompressed_object[object_offset];
 2117|    835|		object_header = (coolkey_combined_object_header_t *)current_object;
 2118|       |
 2119|       |		/* Parse object ID */
 2120|    835|		object_id = bebytes2ulong(object_header->object_id);
 2121|       |
 2122|       |		/* figure out how big it is */
 2123|    835|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2124|    835|		if (r < 0) {
  ------------------
  |  Branch (2124:7): [True: 0, False: 835]
  ------------------
 2125|      0|			goto done;
 2126|      0|		}
 2127|    835|		if ((size_t)r > decompressed_object_len - object_offset) {
  ------------------
  |  Branch (2127:7): [True: 0, False: 835]
  ------------------
 2128|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2129|      0|			goto done;
 2130|      0|		}
 2131|    835|		current_object_len = r;
 2132|    835|		object_offset += current_object_len;
 2133|       |
 2134|       |		/* record this object */
 2135|    835|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   71|    835|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2136|    835|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2137|    835|		if (r) {
  ------------------
  |  Branch (2137:7): [True: 4, False: 831]
  ------------------
 2138|      4|			goto done;
 2139|      4|		}
 2140|       |
 2141|    835|	}
 2142|    133|	r = SC_SUCCESS;
  ------------------
  |  |   28|    133|#define SC_SUCCESS				0
  ------------------
 2143|       |
 2144|    198|done:
 2145|    198|	if (free_decompressed) {
  ------------------
  |  Branch (2145:6): [True: 130, False: 68]
  ------------------
 2146|    130|		free(decompressed_object);
 2147|    130|	}
 2148|    198|	return r;
 2149|    133|}
card-coolkey.c:coolkey_v1_get_object_length:
  707|    835|{
  708|    835|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  709|    835|	int attribute_count;
  710|    835|	u8 *current_attribute;
  711|    835|	int j;
  712|    835|	size_t len;
  713|       |
  714|    835|	len = sizeof(coolkey_combined_object_header_t);
  715|    835|	if (buf_len <= len) {
  ------------------
  |  Branch (715:6): [True: 1, False: 834]
  ------------------
  716|      1|		return (int)buf_len;
  717|      1|	}
  718|    834|	attribute_count = bebytes2ushort(object_head->attribute_count);
  719|    834|	buf_len -= len;
  720|       |
  721|   203k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (721:45): [True: 202k, False: 834]
  ------------------
  722|   202k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  723|       |
  724|   202k|		len += attribute_len;
  725|   202k|		current_attribute += attribute_len;
  726|   202k|		buf_len -= attribute_len;
  727|   202k|	}
  728|    834|	return (int)len;
  729|    835|}
card-coolkey.c:coolkey_add_object:
 1976|  13.9k|{
 1977|  13.9k|	sc_cardctl_coolkey_object_t new_object;
 1978|  13.9k|	int r;
 1979|       |
 1980|  13.9k|	memset(&new_object, 0, sizeof(new_object));
 1981|  13.9k|	new_object.path = coolkey_template_path;
 1982|  13.9k|	new_object.path.len = 4;
 1983|  13.9k|	ulong2bebytes(new_object.path.value, object_id);
 1984|  13.9k|	new_object.id = object_id;
 1985|  13.9k|	new_object.length = object_length;
 1986|       |
 1987|       |	/* The object ID needs to be unique */
 1988|  13.9k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1988:6): [True: 3.73k, False: 10.2k]
  ------------------
 1989|  3.73k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.73k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1990|  3.73k|	}
 1991|       |
 1992|  10.2k|	if (object_data) {
  ------------------
  |  Branch (1992:6): [True: 831, False: 9.38k]
  ------------------
 1993|    831|		new_object.data = malloc(object_length + add_v1_record);
 1994|    831|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1994:7): [True: 0, False: 831]
  ------------------
 1995|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1996|      0|		}
 1997|    831|		if (add_v1_record) {
  ------------------
  |  Branch (1997:7): [True: 831, False: 0]
  ------------------
 1998|    831|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  230|    831|#define COOLKEY_V1_OBJECT 1
  ------------------
 1999|    831|			new_object.length++;
 2000|    831|		}
 2001|    831|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 2002|    831|	}
 2003|       |
 2004|  10.2k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 2005|  10.2k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  10.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2005:6): [True: 0, False: 10.2k]
  ------------------
 2006|       |		/* if we didn't successfully put the object on the list,
 2007|       |		 * the data space didn't get adopted. free it before we return */
 2008|      0|		free(new_object.data);
 2009|       |		new_object.data = NULL;
 2010|      0|	}
 2011|  10.2k|	return r;
 2012|  10.2k|}
card-coolkey.c:coolkey_add_object_to_list:
  817|  10.2k|{
  818|  10.2k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (818:6): [True: 0, False: 10.2k]
  ------------------
  819|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  131|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  820|  10.2k|	return SC_SUCCESS;
  ------------------
  |  |   28|  10.2k|#define SC_SUCCESS				0
  ------------------
  821|  10.2k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1079|    551|{
 1080|    551|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1081|    551|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1082|    551|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1083|    551|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1084|    551|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1085|    551|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1086|    551|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1087|    551|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1088|    551|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1089|    551|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1090|    551|}
card-coolkey.c:coolkey_free_private_data:
  794|  1.09k|{
  795|  1.09k|	list_t *l = &priv->objects_list;
  796|  1.09k|	sc_cardctl_coolkey_object_t *o;
  797|       |
  798|       |	/* Clean up the allocated memory in the items */
  799|  1.09k|	list_iterator_start(l);
  800|  11.3k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (800:9): [True: 10.2k, False: 1.09k]
  ------------------
  801|  10.2k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  802|  10.2k|		free(o->data);
  803|  10.2k|		o->data = NULL;
  804|  10.2k|	}
  805|  1.09k|	list_iterator_stop(l);
  806|       |
  807|  1.09k|	list_destroy(&priv->objects_list);
  808|  1.09k|	free(priv->token_name);
  809|  1.09k|	free(priv);
  810|  1.09k|	return;
  811|  1.09k|}
card-coolkey.c:coolkey_finish:
 1963|    680|{
 1964|    680|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    680|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1965|       |
 1966|    680|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    680|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    680|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    680|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 680]
  |  |  ------------------
  ------------------
 1967|    680|	if (priv) {
  ------------------
  |  Branch (1967:6): [True: 680, False: 0]
  ------------------
 1968|    680|		coolkey_free_private_data(priv);
 1969|    680|		card->drv_data = NULL;
 1970|    680|	}
 1971|    680|	return SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
 1972|    680|}
card-coolkey.c:coolkey_select_file:
 1914|  2.69k|{
 1915|  2.69k|	int r;
 1916|  2.69k|	struct sc_file *file = NULL;
 1917|  2.69k|	coolkey_private_data_t *priv;
 1918|  2.69k|	unsigned long object_id;
 1919|       |
 1920|  2.69k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1920:6): [True: 0, False: 2.69k]
  |  Branch (1920:22): [True: 0, False: 2.69k]
  ------------------
 1921|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1922|       |
 1923|  2.69k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.69k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.69k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.69k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.69k]
  |  |  ------------------
  ------------------
 1924|       |
 1925|  2.69k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  2.69k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1926|  2.69k|	if (priv == NULL)
  ------------------
  |  Branch (1926:6): [True: 0, False: 2.69k]
  ------------------
 1927|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1928|       |
 1929|  2.69k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1929:6): [True: 4, False: 2.68k]
  ------------------
 1930|      4|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      4|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1931|      4|	}
 1932|  2.68k|	r = coolkey_select_applet(card);
 1933|  2.68k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.68k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1933:6): [True: 1.79k, False: 888]
  ------------------
 1934|  1.79k|		return r;
 1935|  1.79k|	}
 1936|    888|	object_id = bebytes2ulong(in_path->value);
 1937|    888|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1938|    888|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1938:6): [True: 507, False: 381]
  ------------------
 1939|    507|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    507|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1940|    507|	}
 1941|       |
 1942|    381|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|    381|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1943|    381|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  112|    381|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1943:6): [True: 351, False: 30]
  ------------------
 1944|    351|		priv->key_id = coolkey_get_key_id(object_id);
 1945|    351|	}
 1946|    381|	if (file_out) {
  ------------------
  |  Branch (1946:6): [True: 16, False: 365]
  ------------------
 1947|     16|		file = sc_file_new();
 1948|     16|		if (file == NULL)
  ------------------
  |  Branch (1948:7): [True: 0, False: 16]
  ------------------
 1949|     16|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1950|     16|		file->path = *in_path;
 1951|       |		/* this could be like the FCI */
 1952|     16|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     16|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1953|     16|		file->shareable = 0;
 1954|     16|		file->ef_structure = 0;
 1955|     16|		file->size = priv->obj->length;
 1956|     16|		*file_out = file;
 1957|     16|	}
 1958|       |
 1959|    381|	return SC_SUCCESS;
  ------------------
  |  |   28|    381|#define SC_SUCCESS				0
  ------------------
 1960|    381|}
card-coolkey.c:coolkey_class:
 1887|    381|static u8 coolkey_class(unsigned long object_id) {
 1888|    381|	return (object_id >> 24) & 0xff;
 1889|    381|}
card-coolkey.c:coolkey_get_key_id:
 1891|    351|static unsigned short coolkey_get_key_id(unsigned long object_id) {
 1892|    351|	char char_index = (object_id >> 16) & 0xff;
 1893|    351|	if (char_index >= '0' && char_index <= '9') {
  ------------------
  |  Branch (1893:6): [True: 343, False: 8]
  |  Branch (1893:27): [True: 265, False: 78]
  ------------------
 1894|    265|		return (u8)(char_index - '0');
 1895|    265|	}
 1896|     86|	if (char_index >= 'A' && char_index <= 'Z') {
  ------------------
  |  Branch (1896:6): [True: 78, False: 8]
  |  Branch (1896:27): [True: 62, False: 16]
  ------------------
 1897|     62|		return (u8)(char_index - 'A' + 10);
 1898|     62|	}
 1899|     24|	if (char_index >= 'a' && char_index <= 'z') {
  ------------------
  |  Branch (1899:6): [True: 16, False: 8]
  |  Branch (1899:27): [True: 10, False: 6]
  ------------------
 1900|     10|		return (u8)(char_index - 'a' + 26 + 10);
 1901|     10|	}
 1902|     14|	return COOLKEY_INVALID_KEY;
  ------------------
  |  |  111|     14|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1903|     24|}
card-coolkey.c:coolkey_read_binary:
 1184|    143|{
 1185|    143|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    143|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1186|    143|	int r = 0;
 1187|    143|	size_t len;
 1188|    143|	u8 *data = NULL;
 1189|       |
 1190|    143|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    143|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    143|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    143|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 143]
  |  |  ------------------
  ------------------
 1191|    143|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1191:6): [True: 0, False: 143]
  ------------------
 1192|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1193|      0|	}
 1194|       |
 1195|       |	/* if we've already read the data, just return it */
 1196|    143|	if (priv->obj->data) {
  ------------------
  |  Branch (1196:6): [True: 129, False: 14]
  ------------------
 1197|    129|		sc_log(card->ctx, "returning cached value idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1198|    129|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   69|    129|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 119, False: 10]
  |  |  ------------------
  ------------------
 1199|    129|		memcpy(buf, &priv->obj->data[idx], len);
 1200|    129|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|    129|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    129|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    129|	int _ret = r; \
  |  |  |  |  155|    129|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 129]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    129|	} else { \
  |  |  |  |  159|    129|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    129|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    129|	} \
  |  |  |  |  162|    129|	return _ret; \
  |  |  |  |  163|    129|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1201|    129|	}
 1202|       |
 1203|     14|	sc_log(card->ctx, "clearing cache idx=%u count=%zu", idx, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1204|       |
 1205|     14|	data = malloc(priv->obj->length);
 1206|     14|	if (data == NULL) {
  ------------------
  |  Branch (1206:6): [True: 0, False: 14]
  ------------------
 1207|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1208|      0|		goto done;
 1209|      0|	}
 1210|       |
 1211|       |
 1212|     14|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1213|     14|		priv->nonce, sizeof(priv->nonce));
 1214|     14|	if (r < 0)
  ------------------
  |  Branch (1214:6): [True: 3, False: 11]
  ------------------
 1215|      3|		goto done;
 1216|       |
 1217|     11|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1217:6): [True: 0, False: 11]
  ------------------
 1218|      0|		priv->obj->length = r;
 1219|      0|	}
 1220|       |
 1221|       |
 1222|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
 1223|     11|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   69|     11|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 10, False: 1]
  |  |  ------------------
  ------------------
 1224|     11|	memcpy(buf, &data[idx], len);
 1225|     11|	r = (int)len;
 1226|       |	/* cache the data in the object */
 1227|     11|	priv->obj->data=data;
 1228|     11|	data = NULL;
 1229|       |
 1230|     14|done:
 1231|     14|	if (data)
  ------------------
  |  Branch (1231:6): [True: 3, False: 11]
  ------------------
 1232|      3|		free(data);
 1233|     14|	LOG_FUNC_RETURN(card->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: 3, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     11|	} else { \
  |  |  |  |  159|     11|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     11|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     11|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1234|     14|}
card-coolkey.c:coolkey_set_security_env:
 1630|    363|{
 1631|    363|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    363|#define SC_SUCCESS				0
  ------------------
 1632|    363|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    363|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1633|       |
 1634|    363|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    363|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    363|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    363|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 363]
  |  |  ------------------
  ------------------
 1635|       |
 1636|    363|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   71|    363|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1637|    363|			env->flags, env->operation, env->algorithm, env->algorithm_flags, env->algorithm_ref,
 1638|    363|			env->key_ref[0], env->key_ref_len);
 1639|       |
 1640|    363|	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   69|    363|#define SC_ALGORITHM_RSA		0
  ------------------
              	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1640:6): [True: 0, False: 363]
  |  Branch (1640:46): [True: 0, False: 0]
  ------------------
 1641|      0|		 r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1642|      0|	}
 1643|    363|	priv->algorithm = env->algorithm;
 1644|    363|	priv->operation = env->operation;
 1645|       |
 1646|    363|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    363|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    363|	int _ret = r; \
  |  |  155|    363|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 363, False: 0]
  |  |  ------------------
  |  |  156|    363|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 363]
  |  |  ------------------
  |  |  157|    363|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    363|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    363|	return _ret; \
  |  |  163|    363|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1647|    363|}
card-coolkey.c:coolkey_compute_crypt:
 1863|    363|{
 1864|    363|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    363|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1865|    363|	int r;
 1866|    363|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    363|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    363|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    363|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 363]
  |  |  ------------------
  ------------------
 1867|       |
 1868|    363|	if (data == NULL || out == NULL || priv == NULL)
  ------------------
  |  Branch (1868:6): [True: 0, False: 363]
  |  Branch (1868:22): [True: 0, False: 363]
  |  Branch (1868:37): [True: 0, False: 363]
  ------------------
 1869|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1870|       |
 1871|    363|	switch (priv->algorithm) {
 1872|    363|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    363|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1872:2): [True: 363, False: 0]
  ------------------
 1873|    363|		r = coolkey_rsa_op(card, data, datalen, out, outlen);
 1874|    363|		break;
 1875|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1875:2): [True: 0, False: 363]
  ------------------
 1876|      0|		r = coolkey_ecc_op(card, data, datalen, out, outlen);
 1877|      0|		break;
 1878|      0|	default:
  ------------------
  |  Branch (1878:2): [True: 0, False: 363]
  ------------------
 1879|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1880|      0|		break;
 1881|    363|	}
 1882|       |
 1883|    363|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    363|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    363|	int _ret = r; \
  |  |  155|    363|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 344, False: 19]
  |  |  ------------------
  |  |  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|    329|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 329, False: 15]
  |  |  ------------------
  |  |  157|    344|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    344|	} 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|    363|	return _ret; \
  |  |  163|    363|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1884|    363|}
card-coolkey.c:coolkey_rsa_op:
 1678|    363|{
 1679|    363|	int r;
 1680|    363|	u8 **crypt_out_p = NULL;
 1681|    363|	size_t crypt_out_len_p = 0;
 1682|    363|	coolkey_private_data_t *priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    363|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1683|    363|	coolkey_compute_crypt_params_t params;
 1684|    363|	u8 key_number;
 1685|    363|	size_t params_len;
 1686|    363|	u8 buf[MAX_COMPUTE_BUF + 2];
 1687|    363|	size_t buf_len;
 1688|    363|	u8 *buf_out;
 1689|       |
 1690|    363|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    363|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    363|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    363|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 363]
  |  |  ------------------
  ------------------
 1691|    363|	sc_log(card->ctx, "datalen=%zu outlen=%zu\n", datalen, max_out_len);
  ------------------
  |  |   71|    363|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1692|       |
 1693|    363|	if (datalen > 0xFFFF) {
  ------------------
  |  Branch (1693:6): [True: 0, False: 363]
  ------------------
 1694|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1695|      0|		goto done;
 1696|      0|	}
 1697|       |
 1698|    363|	if (priv->key_id > 0xff) {
  ------------------
  |  Branch (1698:6): [True: 26, False: 337]
  ------------------
 1699|     26|		r = SC_ERROR_NO_DEFAULT_KEY;
  ------------------
  |  |  106|     26|#define SC_ERROR_NO_DEFAULT_KEY			-1504
  ------------------
 1700|     26|		goto done;
 1701|     26|	}
 1702|    337|	key_number = priv->key_id;
 1703|       |
 1704|    337|	memset(&params, 0, sizeof(params));
 1705|    337|	params.init.mode = COOLKEY_CRYPT_MODE_RSA_NO_PAD;
  ------------------
  |  |   99|    337|#define COOLKEY_CRYPT_MODE_RSA_NO_PAD    0x00
  ------------------
 1706|    337|	params.init.direction = COOLKEY_CRYPT_DIRECTION_ENCRYPT; /* for no pad, direction is irrelevant */
  ------------------
  |  |  102|    337|#define COOLKEY_CRYPT_DIRECTION_ENCRYPT  0x03
  ------------------
 1707|       |
 1708|       |	/* send the data to the card if necessary */
 1709|    337|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1657|    337|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1709:6): [True: 177, False: 160]
  ------------------
 1710|       |		/* We need to write data to special object on the card as it does not safely fit APDU */
 1711|    177|		u8 len_buf[2];
 1712|       |
 1713|    177|		params.init.location = COOLKEY_CRYPT_LOCATION_DL_OBJECT;
  ------------------
  |  |  101|    177|#define COOLKEY_CRYPT_LOCATION_DL_OBJECT 0x02
  ------------------
 1714|       |
 1715|    177|		params_len = sizeof(params.init);
 1716|       |
 1717|    177|		ushort2bebytes(len_buf, datalen);
 1718|       |
 1719|    177|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  109|    177|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1720|    177|					priv->nonce, sizeof(priv->nonce));
 1721|    177|		if (r < 0) {
  ------------------
  |  Branch (1721:7): [True: 19, False: 158]
  ------------------
 1722|     19|			goto done;
 1723|     19|		}
 1724|       |
 1725|    158|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 2, data, datalen, priv->nonce, sizeof(priv->nonce));
  ------------------
  |  |  109|    158|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1726|    158|		if (r < 0) {
  ------------------
  |  Branch (1726:7): [True: 59, False: 99]
  ------------------
 1727|     59|			goto done;
 1728|     59|		}
 1729|     99|		ushort2bebytes(params.init.buf_len, 0);
 1730|    160|	} else {
 1731|       |		/* The data fits in APDU. Copy it to the params object */
 1732|    160|		params.init.location = COOLKEY_CRYPT_LOCATION_APDU;
  ------------------
  |  |  100|    160|#define COOLKEY_CRYPT_LOCATION_APDU      0x01
  ------------------
 1733|       |
 1734|    160|		params_len = sizeof(params.init) + datalen;
 1735|       |
 1736|    160|		buf_out = &buf[0];
 1737|    160|		crypt_out_p = &buf_out;
 1738|    160|		buf_len = sizeof(buf);
 1739|    160|		crypt_out_len_p = buf_len;
 1740|       |
 1741|    160|		ushort2bebytes(params.init.buf_len, datalen);
 1742|    160|		memcpy(params.buf, data, datalen);
 1743|    160|	}
 1744|       |
 1745|    259|	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   73|    259|#define COOLKEY_CLASS           0xb0
  ------------------
              	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   85|    259|#define COOLKEY_INS_COMPUTE_CRYPT              0x36
  ------------------
 1746|    259|			key_number, COOLKEY_CRYPT_ONE_STEP, (u8 *)&params, params_len,
  ------------------
  |  |   97|    259|#define COOLKEY_CRYPT_ONE_STEP 4
  ------------------
 1747|    259|			crypt_out_p, &crypt_out_len_p, priv->nonce, sizeof(priv->nonce));
 1748|    259|	if (r < 0) {
  ------------------
  |  Branch (1748:6): [True: 45, False: 214]
  ------------------
 1749|     45|		goto done;
 1750|     45|	}
 1751|    214|	buf_len = crypt_out_len_p;
 1752|       |
 1753|    214|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1657|    214|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1753:6): [True: 94, False: 120]
  ------------------
 1754|     94|		u8 len_buf[2];
 1755|     94|		size_t out_length;
 1756|       |
 1757|     94|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  109|     94|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1758|     94|					priv->nonce, sizeof(priv->nonce));
 1759|     94|		if (r < 0) {
  ------------------
  |  Branch (1759:7): [True: 57, False: 37]
  ------------------
 1760|     57|			goto done;
 1761|     57|		}
 1762|       |
 1763|     37|		out_length = bebytes2ushort(len_buf);
 1764|     37|		if (out_length > max_out_len) {
  ------------------
  |  Branch (1764:7): [True: 0, False: 37]
  ------------------
 1765|      0|			r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1766|      0|			goto done;
 1767|      0|		}
 1768|       |
 1769|     37|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, sizeof(len_buf), out, out_length,
  ------------------
  |  |  109|     37|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1770|     37|					priv->nonce, sizeof(priv->nonce));
 1771|       |
 1772|    120|	} else {
 1773|    120|		size_t out_length;
 1774|    120|		if (buf_len < 2) {
  ------------------
  |  Branch (1774:7): [True: 69, False: 51]
  ------------------
 1775|     69|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     69|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1776|     69|			goto done;
 1777|     69|		}
 1778|     51|		out_length = bebytes2ushort(buf);
 1779|     51|		if (out_length > (buf_len - 2)) {
  ------------------
  |  Branch (1779:7): [True: 29, False: 22]
  ------------------
 1780|     29|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     29|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1781|     29|			goto done;
 1782|     29|		}
 1783|     22|		if (out_length > max_out_len) {
  ------------------
  |  Branch (1783:7): [True: 0, False: 22]
  ------------------
 1784|      0|			r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1785|      0|			goto done;
 1786|      0|		}
 1787|     22|		memcpy(out, buf + 2, out_length);
 1788|     22|		r = (int)out_length;
 1789|     22|	}
 1790|       |
 1791|    363|done:
 1792|    363|	sc_mem_clear(buf, sizeof(buf));
 1793|    363|	return r;
 1794|    214|}
card-coolkey.c:coolkey_write_object:
 1140|    335|{
 1141|    335|	coolkey_write_object_param_t params;
 1142|    335|	size_t operation_len;
 1143|    335|	size_t left = buf_len;
 1144|    335|	int r;
 1145|    335|	size_t max_operation_len;
 1146|       |
 1147|    335|	if (card->max_send_size < sizeof(coolkey_read_object_param_t) + nonce_size)
  ------------------
  |  Branch (1147:6): [True: 0, False: 335]
  ------------------
 1148|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1149|       |
 1150|       |	/* set limit for the card's maximum send size and short write */
 1151|    335|	max_operation_len = MIN(COOLKEY_MAX_CHUNK_SIZE, (card->max_send_size - sizeof(coolkey_read_object_param_t) - nonce_size));
  ------------------
  |  |   69|    335|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 335]
  |  |  ------------------
  ------------------
 1152|       |
 1153|    335|	ulong2bebytes(&params.head.object_id[0], object_id);
 1154|       |
 1155|  4.15k|	do {
 1156|  4.15k|		ulong2bebytes(&params.head.offset[0], offset);
 1157|  4.15k|		operation_len = MIN(left, max_operation_len);
  ------------------
  |  |   69|  4.15k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 285, False: 3.86k]
  |  |  ------------------
  ------------------
 1158|  4.15k|		params.head.length = operation_len;
 1159|  4.15k|		memcpy(params.buf, buf, operation_len);
 1160|  4.15k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   73|  4.15k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   90|  4.15k|#define COOLKEY_INS_WRITE_OBJECT               0x54
  ------------------
 1161|  4.15k|			(u8 *)&params, sizeof(params.head)+operation_len, NULL, 0, nonce, nonce_size);
 1162|  4.15k|		if (r < 0) {
  ------------------
  |  Branch (1162:7): [True: 78, False: 4.07k]
  ------------------
 1163|     78|			goto fail;
 1164|     78|		}
 1165|  4.07k|		buf += operation_len;
 1166|  4.07k|		offset += operation_len;
 1167|  4.07k|		left -= operation_len;
 1168|  4.07k|	} while (left != 0);
  ------------------
  |  Branch (1168:11): [True: 3.81k, False: 257]
  ------------------
 1169|       |
 1170|    257|	return (int)(buf_len - left);
 1171|       |
 1172|     78|fail:
 1173|     78|	return r;
 1174|    335|}
card-coolkey.c:coolkey_card_ctl:
 1585|  89.3k|{
 1586|  89.3k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  89.3k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1587|       |
 1588|  89.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  89.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  89.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  89.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  89.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 89.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1589|  89.3k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  89.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__
  |  |  ------------------
  ------------------
 1590|       |
 1591|  89.3k|	if (priv == NULL) {
  ------------------
  |  Branch (1591:6): [True: 0, False: 89.3k]
  ------------------
 1592|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1593|      0|	}
 1594|  89.3k|	switch(cmd) {
  ------------------
  |  Branch (1594:9): [True: 89.3k, False: 0]
  ------------------
 1595|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1595:3): [True: 0, False: 89.3k]
  ------------------
 1596|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1597|    679|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1597:3): [True: 679, False: 88.6k]
  ------------------
 1598|    679|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1599|  3.30k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1599:3): [True: 3.30k, False: 86.0k]
  ------------------
 1600|  3.30k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1601|    679|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1601:3): [True: 679, False: 88.6k]
  ------------------
 1602|    679|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1603|  9.24k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1603:3): [True: 9.24k, False: 80.1k]
  ------------------
 1604|  9.24k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1605|    679|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1605:3): [True: 679, False: 88.6k]
  ------------------
 1606|    679|			return coolkey_final_iterator(&priv->objects_list);
 1607|  74.7k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1607:3): [True: 74.7k, False: 14.5k]
  ------------------
 1608|  74.7k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1609|  89.3k|	}
 1610|       |
 1611|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1612|      0|}
card-coolkey.c:coolkey_get_token_info:
 1330|    679|{
 1331|    679|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    679|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1332|    679|	char *label = NULL;
 1333|    679|	char *manufacturer_id = NULL;
 1334|    679|	char *serial_number = NULL;
 1335|       |
 1336|    679|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    679|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    679|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    679|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    679|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 679]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1337|    679|	label = strdup((char *)priv->token_name);
 1338|    679|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1339|    679|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1340|       |
 1341|    679|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1341:6): [True: 679, False: 0]
  |  Branch (1341:15): [True: 679, False: 0]
  |  Branch (1341:34): [True: 679, False: 0]
  ------------------
 1342|    679|		free(token_info->label);
 1343|    679|		token_info->label = label;
 1344|    679|		free(token_info->manufacturer_id);
 1345|    679|		token_info->manufacturer_id = manufacturer_id;
 1346|    679|		free(token_info->serial_number);
 1347|    679|		token_info->serial_number = serial_number;
 1348|    679|		return SC_SUCCESS;
  ------------------
  |  |   28|    679|#define SC_SUCCESS				0
  ------------------
 1349|    679|	}
 1350|      0|	free(label);
 1351|      0|	free(manufacturer_id);
 1352|      0|	free(serial_number);
 1353|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1354|    679|}
card-coolkey.c:coolkey_get_manufacturer:
 1301|    679|{
 1302|    679|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1303|    679|	int i;
 1304|    679|	char *buf;
 1305|    679|	const char *manufacturer_string = "%04x Unknown";
 1306|    679|	size_t len;
 1307|    679|	int r;
 1308|       |
 1309|  4.04k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1309:12): [True: 3.39k, False: 653]
  ------------------
 1310|  3.39k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1310:7): [True: 26, False: 3.36k]
  ------------------
 1311|     26|			manufacturer_string = manufacturer_list[i].string;
 1312|     26|			break;
 1313|     26|		}
 1314|  3.39k|	}
 1315|    679|	len = strlen(manufacturer_string)+1;
 1316|    679|	buf= malloc(len);
 1317|    679|	if (buf == NULL) {
  ------------------
  |  Branch (1317:6): [True: 0, False: 679]
  ------------------
 1318|      0|		return NULL;
 1319|      0|	}
 1320|    679|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1321|    679|	if (r < 0) {
  ------------------
  |  Branch (1321:6): [True: 0, False: 679]
  ------------------
 1322|      0|		free(buf);
 1323|      0|		return NULL;
 1324|      0|	}
 1325|    679|	return buf;
 1326|    679|}
card-coolkey.c:coolkey_cuid_to_string:
 1276|    679|{
 1277|    679|	char *buf;
 1278|    679|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1279|    679|	buf = malloc(len);
 1280|    679|	if (buf == NULL) {
  ------------------
  |  Branch (1280:6): [True: 0, False: 679]
  ------------------
 1281|      0|		return NULL;
 1282|      0|	}
 1283|    679|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1284|    679|	return buf;
 1285|    679|}
card-coolkey.c:coolkey_find_object:
 1556|  3.30k|{
 1557|  3.30k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1558|  3.30k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|  3.30k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1559|  3.30k|	int r;
 1560|       |
 1561|  3.30k|	switch (fobj->type) {
 1562|    946|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1079|    946|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1562:2): [True: 946, False: 2.35k]
  ------------------
 1563|    946|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1564|    946|		break;
 1565|  2.35k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1080|  2.35k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1565:2): [True: 2.35k, False: 946]
  ------------------
 1566|  2.35k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1567|  2.35k|		break;
 1568|      0|	default:
  ------------------
  |  Branch (1568:2): [True: 0, False: 3.30k]
  ------------------
 1569|      0|		break;
 1570|  3.30k|	}
 1571|  3.30k|	if (obj == NULL) {
  ------------------
  |  Branch (1571:6): [True: 1.36k, False: 1.93k]
  ------------------
 1572|  1.36k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  1.36k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1573|  1.36k|	}
 1574|  1.93k|	if (obj->data == NULL) {
  ------------------
  |  Branch (1574:6): [True: 54, False: 1.88k]
  ------------------
 1575|     54|		r = coolkey_fill_object(card, obj);
 1576|     54|		if (r < 0) {
  ------------------
  |  Branch (1576:7): [True: 43, False: 11]
  ------------------
 1577|     43|			return r;
 1578|     43|		}
 1579|     54|	}
 1580|  1.89k|	fobj->obj = obj;
 1581|  1.89k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.89k|#define SC_SUCCESS				0
  ------------------
 1582|  1.93k|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1249|    679|{
 1250|    679|	*countp = list_size(list);
 1251|    679|	list_iterator_start(list);
 1252|    679|	return SC_SUCCESS;
  ------------------
  |  |   28|    679|#define SC_SUCCESS				0
  ------------------
 1253|    679|}
card-coolkey.c:coolkey_fetch_object:
 1257|  9.24k|{
 1258|  9.24k|	sc_cardctl_coolkey_object_t *ptr;
 1259|  9.24k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1259:6): [True: 0, False: 9.24k]
  ------------------
 1260|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1261|      0|	}
 1262|       |
 1263|  9.24k|	ptr = list_iterator_next(list);
 1264|  9.24k|	*coolkey_obj = *ptr;
 1265|  9.24k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.24k|#define SC_SUCCESS				0
  ------------------
 1266|  9.24k|}
card-coolkey.c:coolkey_final_iterator:
 1270|    679|{
 1271|    679|	list_iterator_stop(list);
 1272|    679|	return SC_SUCCESS;
  ------------------
  |  |   28|    679|#define SC_SUCCESS				0
  ------------------
 1273|    679|}
card-coolkey.c:coolkey_check_sw:
  877|  95.8k|{
  878|  95.8k|	sc_log(card->ctx,
  ------------------
  |  |   71|  95.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__
  |  |  ------------------
  ------------------
  879|  95.8k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  880|       |
  881|  95.8k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (881:6): [True: 43.0k, False: 52.7k]
  |  Branch (881:21): [True: 39.6k, False: 3.42k]
  ------------------
  882|  39.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  39.6k|#define SC_SUCCESS				0
  ------------------
  883|       |
  884|  56.1k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (884:6): [True: 982, False: 55.2k]
  ------------------
  885|    982|		if (sw2 == 0xff) {
  ------------------
  |  Branch (885:7): [True: 5, False: 977]
  ------------------
  886|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  887|      5|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
  888|      5|		}
  889|    977|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (889:7): [True: 35, False: 942]
  ------------------
  890|     35|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  131|     35|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  891|     35|		}
  892|    942|		return coolkey_error_codes[sw2].sc_error;
  893|    977|	}
  894|       |
  895|       |	/* iso error */
  896|  55.2k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  897|  56.1k|}
card-coolkey.c:coolkey_pin_cmd:
 2367|    696|{
 2368|    696|	int r;
 2369|    696|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  754|    696|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2370|    696|	size_t rbuflen;
 2371|    696|	u8 *rbuf;
 2372|       |
 2373|       |	/* COOLKEY uses a separate pin from the card pin, managed by the applet.
 2374|       |	 * if we successfully log into coolkey, we will get a nonce, which we append
 2375|       |	 * to our APDUs to authenticate the apdu to the card. This allows coolkey to
 2376|       |	 * maintain separate per application login states without the application
 2377|       |	 * having to cache the pin */
 2378|    696|	switch (data->cmd) {
 2379|    679|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    679|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2379:2): [True: 679, False: 17]
  ------------------
 2380|    679|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2380:7): [True: 3, False: 676]
  ------------------
 2381|      3|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      3|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2382|    676|		} else {
 2383|    676|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|    676|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 2384|       |			/* coolkey retries is 100. It's unlikely the pin is block.
 2385|       |			 * instead, coolkey slows down the login command exponentially
 2386|       |			 */
 2387|    676|			data->pin1.tries_left = 0xf;
 2388|    676|		}
 2389|    679|		r = SC_SUCCESS;
  ------------------
  |  |   28|    679|#define SC_SUCCESS				0
  ------------------
 2390|    679|		break;
 2391|       |
 2392|      3|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      3|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2392:2): [True: 3, False: 693]
  ------------------
 2393|      6|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      6|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2393:2): [True: 3, False: 693]
  ------------------
 2394|       |		/* these 2 commands are currently reserved for TPS */
 2395|      6|	default:
  ------------------
  |  Branch (2395:2): [True: 0, False: 696]
  ------------------
 2396|      6|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      6|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2397|      6|		break;
 2398|     11|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|     11|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2398:2): [True: 11, False: 685]
  ------------------
 2399|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2400|       |		 * just support the one pin for now (we need an array of nonces to handle
 2401|       |		 * multiple pins) */
 2402|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2403|     11|		rbuflen = sizeof(priv->nonce);
 2404|     11|		rbuf = &priv->nonce[0];
 2405|     11|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   73|     11|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   81|     11|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2406|     11|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2407|     11|			&rbuf, &rbuflen, NULL, 0);
 2408|     11|		if (r < 0) {
  ------------------
  |  Branch (2408:7): [True: 8, False: 3]
  ------------------
 2409|      8|			break;
 2410|      8|		}
 2411|      3|		priv->nonce_valid = 1;
 2412|      3|		r = SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 2413|    696|	}
 2414|    696|	return r;
 2415|    696|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2436|  29.6k|{
 2437|  29.6k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  29.6k|#define SC_SUCCESS				0
  ------------------
 2438|       |
 2439|  29.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  29.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  29.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  29.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 29.6k]
  |  |  ------------------
  ------------------
 2440|       |
 2441|  29.6k|	if (was_reset > 0) {
  ------------------
  |  Branch (2441:6): [True: 0, False: 29.6k]
  ------------------
 2442|      0|		r = coolkey_select_applet(card);
 2443|      0|	}
 2444|       |
 2445|  29.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  29.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  29.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  29.6k|	int _ret = r; \
  |  |  |  |  155|  29.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 29.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  29.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: 29.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  29.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  29.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|  29.6k|	return _ret; \
  |  |  |  |  163|  29.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2446|  29.6k|}

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

dnie_match_card:
  751|  18.7k|{
  752|  18.7k|	int result = 0;
  753|  18.7k|	int matched = -1;
  754|  18.7k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  18.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  18.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  18.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  18.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 18.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  755|  18.7k|	matched = _sc_match_atr(card, dnie_atrs, &card->type);
  756|  18.7k|	result = (matched >= 0) ? 1 : 0;
  ------------------
  |  Branch (756:11): [True: 1.27k, False: 17.4k]
  ------------------
  757|  18.7k|	LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  164|  18.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.7k|	int _ret = r; \
  |  |  |  |  155|  18.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.4k, False: 1.27k]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.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: 17.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.4k|	} else { \
  |  |  |  |  159|  1.27k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.27k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.27k|	} \
  |  |  |  |  162|  18.7k|	return _ret; \
  |  |  |  |  163|  18.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|  18.7k|}
sc_get_dnie_driver:
 2324|  16.1k|{
 2325|  16.1k|	return get_dnie_driver();
 2326|  16.1k|}
card-dnie.c:get_dnie_driver:
 2261|  16.1k|{
 2262|  16.1k|	sc_card_driver_t *iso_drv = sc_get_iso7816_driver();
 2263|       |
 2264|       |	/* memcpy() from standard iso7816 declared operations */
 2265|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2265:6): [True: 1, False: 16.1k]
  ------------------
 2266|      1|		iso_ops = iso_drv->ops;
 2267|  16.1k|	dnie_ops = *iso_drv->ops;
 2268|       |
 2269|       |	/* fill card specific function pointers */
 2270|       |	/* NULL means that function is not supported neither by DNIe nor iso7816.c */
 2271|       |	/* if pointer is omitted, default ISO7816 function will be used */
 2272|       |
 2273|       |	/* initialization */
 2274|  16.1k|	dnie_ops.match_card	= dnie_match_card;
 2275|  16.1k|	dnie_ops.init		= dnie_init;
 2276|  16.1k|	dnie_ops.finish		= dnie_finish;
 2277|       |
 2278|       |	/* iso7816-4 functions */
 2279|  16.1k|	dnie_ops.read_binary	= dnie_read_binary;
 2280|  16.1k|	dnie_ops.write_binary	= NULL;
 2281|  16.1k|	dnie_ops.update_binary	= NULL;
 2282|  16.1k|	dnie_ops.erase_binary	= NULL;
 2283|  16.1k|	dnie_ops.read_record	= NULL;
 2284|  16.1k|	dnie_ops.write_record	= NULL;
 2285|  16.1k|	dnie_ops.append_record	= NULL;
 2286|  16.1k|	dnie_ops.update_record	= NULL;
 2287|  16.1k|	dnie_ops.select_file	= dnie_select_file;
 2288|  16.1k|	dnie_ops.get_challenge	= dnie_get_challenge;
 2289|       |
 2290|       |	/* iso7816-8 functions */
 2291|  16.1k|	dnie_ops.verify		= NULL;
 2292|  16.1k|	dnie_ops.logout		= dnie_logout;
 2293|       |	/* dnie_ops.restore_security_env */
 2294|  16.1k|	dnie_ops.set_security_env = dnie_set_security_env;
 2295|  16.1k|	dnie_ops.decipher	= dnie_decipher;
 2296|  16.1k|	dnie_ops.compute_signature = dnie_compute_signature;
 2297|  16.1k|	dnie_ops.change_reference_data = NULL;
 2298|  16.1k|	dnie_ops.reset_retry_counter = NULL;
 2299|       |
 2300|       |	/* iso7816-9 functions */
 2301|  16.1k|	dnie_ops.create_file	= NULL;
 2302|  16.1k|	dnie_ops.delete_file	= NULL;
 2303|  16.1k|	dnie_ops.list_files	= dnie_list_files;
 2304|  16.1k|	dnie_ops.check_sw	= dnie_check_sw;
 2305|  16.1k|	dnie_ops.card_ctl	= dnie_card_ctl;
 2306|  16.1k|	dnie_ops.process_fci	= dnie_process_fci;
 2307|       |	/* dnie_ops.construct_fci */
 2308|  16.1k|	dnie_ops.pin_cmd	= dnie_pin_cmd;
 2309|  16.1k|	dnie_ops.get_data	= NULL;
 2310|  16.1k|	dnie_ops.put_data	= NULL;
 2311|  16.1k|	dnie_ops.delete_record	= NULL;
 2312|       |
 2313|  16.1k|	return &dnie_driver;
 2314|  16.1k|}
card-dnie.c:dnie_init:
  851|    440|{
  852|    440|	int res = SC_SUCCESS;
  ------------------
  |  |   28|    440|#define SC_SUCCESS				0
  ------------------
  853|    440|	sc_context_t *ctx = card->ctx;
  854|    440|	cwa_provider_t *provider = NULL;
  855|       |
  856|    440|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    440|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    440|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    440|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    440|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 440]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  857|       |
  858|       |	/* if recognized as terminated DNIe card, return error */
  859|    440|	if (card->type == SC_CARD_TYPE_DNIE_TERMINATED)
  ------------------
  |  Branch (859:6): [True: 4, False: 436]
  ------------------
  860|    440|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "DNIe card is terminated.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  861|       |
  862|       |	/* create and initialize cwa-dnie provider*/
  863|    436|	provider = dnie_get_cwa_provider(card);
  864|    436|	if (!provider)
  ------------------
  |  Branch (864:6): [True: 0, False: 436]
  ------------------
  865|    436|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  866|       |
  867|       |	/** Secure messaging initialization section **/
  868|    436|	memset(&(card->sm_ctx), 0, sizeof(sm_context_t));
  869|    436|	card->sm_ctx.ops.get_sm_apdu = dnie_sm_get_wrapped_apdu;
  870|    436|	card->sm_ctx.ops.free_sm_apdu = dnie_sm_free_wrapped_apdu;
  871|    436|	card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|    436|#define SM_MODE_NONE		0x0
  ------------------
  872|       |
  873|    436|	res = cwa_create_secure_channel(card, provider, CWA_SM_OFF);
  ------------------
  |  |   31|    436|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  874|    436|	if (res < 0)
  ------------------
  |  Branch (874:6): [True: 23, False: 413]
  ------------------
  875|     23|		free(provider);
  876|    436|	LOG_TEST_RET(card->ctx, res, "Failure resetting CWA secure channel.");
  ------------------
  |  |  174|    436|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    436|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    436|	int _ret = (r); \
  |  |  |  |  168|    436|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 23, False: 413]
  |  |  |  |  ------------------
  |  |  |  |  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|    436|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 413]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  877|       |
  878|       |	/* initialize private data */
  879|    413|	card->drv_data = calloc(1, sizeof(dnie_private_data_t));
  880|    413|	if (card->drv_data == NULL) {
  ------------------
  |  Branch (880:6): [True: 0, False: 413]
  ------------------
  881|      0|		free(provider);
  882|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  883|      0|	}
  884|       |
  885|       |#ifdef ENABLE_DNIE_UI
  886|       |	/* read environment from configuration file */
  887|       |	res = dnie_get_environment(card, &(GET_DNIE_UI_CTX(card)));
  888|       |	if (res != SC_SUCCESS) {
  889|       |		free(card->drv_data);
  890|       |		card->drv_data = NULL;
  891|       |		free(provider);
  892|       |		LOG_TEST_RET(card->ctx, res, "Failure reading DNIe environment.");
  893|       |	}
  894|       |#endif
  895|       |
  896|    413|	init_flags(card);
  897|       |
  898|    413|	GET_DNIE_PRIV_DATA(card)->cwa_provider = provider;
  ------------------
  |  |   97|    413|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  899|       |
  900|    413|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  901|    413|}
card-dnie.c:init_flags:
  718|    413|{
  719|    413|	unsigned long algoflags;
  720|       |	/* set up flags according documentation */
  721|    413|	card->name = DNIE_CHIP_SHORTNAME;
  ------------------
  |  |   68|    413|#define DNIE_CHIP_SHORTNAME "dnie"
  ------------------
  722|    413|	card->cla = 0x00;	/* default APDU class (interindustry) */
  723|    413|	card->caps |= SC_CARD_CAP_RNG;	/* we have a random number generator */
  ------------------
  |  |  550|    413|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  724|    413|	card->max_send_size = (255 - 12);	/* manual says 255, but we need 12 extra bytes when encoding */
  725|    413|	card->max_recv_size = 255;
  726|       |
  727|       |	/* RSA Support with PKCS1.5 padding */
  728|    413|	algoflags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  133|    413|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              	algoflags = SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    413|#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|    413|#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|    413|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  729|    413|	_sc_card_add_rsa_alg(card, 1024, algoflags, 0);
  730|    413|	_sc_card_add_rsa_alg(card, 1920, algoflags, 0);
  731|    413|	_sc_card_add_rsa_alg(card, 2048, algoflags, 0);
  732|    413|}
card-dnie.c:dnie_finish:
  913|    413|{
  914|    413|	int result = SC_SUCCESS;
  ------------------
  |  |   28|    413|#define SC_SUCCESS				0
  ------------------
  915|    413|	dnie_private_data_t *priv = NULL;
  916|    413|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    413|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    413|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    413|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    413|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 413]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  917|    413|	priv = GET_DNIE_PRIV_DATA(card);
  ------------------
  |  |   97|    413|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  918|    413|	if (priv) {
  ------------------
  |  Branch (918:6): [True: 413, False: 0]
  ------------------
  919|    413|		dnie_clear_cache(priv);
  920|       |		/* disable sm channel if established */
  921|    413|		result = cwa_create_secure_channel(card, priv->cwa_provider, CWA_SM_OFF);
  ------------------
  |  |   31|    413|#define CWA_SM_OFF        0x00	/** Disable SM channel */
  ------------------
  922|    413|		free(priv->cwa_provider);
  923|    413|		free(card->drv_data);
  924|    413|		card->drv_data = NULL;
  925|    413|	}
  926|    413|	LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  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|    404|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 404, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  927|    413|}
card-dnie.c:dnie_clear_cache:
  702|  3.71k|{
  703|  3.71k|	if (data == NULL) return;
  ------------------
  |  Branch (703:6): [True: 389, False: 3.32k]
  ------------------
  704|  3.32k|	if (data->cache != NULL)
  ------------------
  |  Branch (704:6): [True: 155, False: 3.17k]
  ------------------
  705|    155|		free(data->cache);
  706|       |	data->cache = NULL;
  707|  3.32k|	data->cachelen = 0;
  708|  3.32k|}
card-dnie.c:dnie_read_binary:
 1120|  3.78k|{
 1121|  3.78k|	size_t res = 0;
 1122|  3.78k|	int rc;
 1123|  3.78k|	sc_context_t *ctx = NULL;
 1124|       |	/* preliminary checks */
 1125|  3.78k|	if (!card || !card->ctx || !buf || (count <= 0))
  ------------------
  |  Branch (1125:6): [True: 0, False: 3.78k]
  |  Branch (1125:15): [True: 0, False: 3.78k]
  |  Branch (1125:29): [True: 0, False: 3.78k]
  |  Branch (1125:37): [True: 0, False: 3.78k]
  ------------------
 1126|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1127|  3.78k|	ctx = card->ctx;
 1128|       |
 1129|  3.78k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.78k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.78k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.78k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.78k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|  3.78k|	if (idx == 0 || GET_DNIE_PRIV_DATA(card)->cache == NULL) {
  ------------------
  |  |   97|  3.55k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  |  Branch (1130:6): [True: 222, False: 3.55k]
  |  Branch (1130:18): [True: 1.75k, False: 1.80k]
  ------------------
 1131|       |		/* on first block or no cache, try to fill */
 1132|  1.98k|		rc = dnie_fill_cache(card, flags);
 1133|  1.98k|		if (rc < 0) {
  ------------------
  |  Branch (1133:7): [True: 1.82k, False: 160]
  ------------------
 1134|  1.82k|			sc_log(ctx, "Cannot fill cache. using iso_read_binary()");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1135|  1.82k|			return iso_ops->read_binary(card, idx, buf, count, flags);
 1136|  1.82k|		}
 1137|  1.98k|	}
 1138|  1.96k|	if (idx >= GET_DNIE_PRIV_DATA(card)->cachelen)
  ------------------
  |  |   97|  1.96k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
  |  Branch (1138:6): [True: 155, False: 1.80k]
  ------------------
 1139|    155|		return 0;	/* at eof */
 1140|  1.80k|	res = MIN(count, GET_DNIE_PRIV_DATA(card)->cachelen - idx);	/* eval how many bytes to read */
  ------------------
  |  |   69|  1.80k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 1.66k, False: 136]
  |  |  ------------------
  ------------------
 1141|  1.80k|	memcpy(buf, GET_DNIE_PRIV_DATA(card)->cache + idx, res);	/* copy data from buffer */
  ------------------
  |  |   97|  1.80k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1142|  1.80k|	sc_log(ctx, "dnie_read_binary() '%zu' bytes", res);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 1143|  1.80k|	LOG_FUNC_RETURN(ctx, (int)res);
  ------------------
  |  |  164|  1.80k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.80k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.80k|	int _ret = r; \
  |  |  |  |  155|  1.80k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.80k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.80k|	} else { \
  |  |  |  |  159|  1.80k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.80k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.80k|	} \
  |  |  |  |  162|  1.80k|	return _ret; \
  |  |  |  |  163|  1.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1144|  1.80k|}
card-dnie.c:dnie_fill_cache:
  994|  1.98k|{
  995|  1.98k|	u8 tmp[MAX_RESP_BUFFER_SIZE];
  996|  1.98k|	sc_apdu_t apdu;
  997|  1.98k|	size_t count = 0;
  998|  1.98k|	size_t len = 0;
  999|  1.98k|	u8 *buffer = NULL;
 1000|  1.98k|	u8 *p;
 1001|  1.98k|	sc_context_t *ctx = NULL;
 1002|       |
 1003|  1.98k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1003:6): [True: 0, False: 1.98k]
  |  Branch (1003:15): [True: 0, False: 1.98k]
  ------------------
 1004|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1005|  1.98k|	ctx = card->ctx;
 1006|       |
 1007|  1.98k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.98k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.98k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.98k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.98k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.98k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1008|       |
 1009|       |	/* mark cache empty */
 1010|  1.98k|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|  1.98k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1011|       |
 1012|       |	/* initialize apdu */
 1013|  1.98k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x00, 0x00);
  ------------------
  |  |  292|  1.98k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1014|       |
 1015|       |	/* try to read_binary while data available but never long than 32767 */
 1016|  1.98k|	count = card->max_recv_size;
 1017|  3.91k|	for (len = 0; len < 0x7fff;) {
  ------------------
  |  Branch (1017:16): [True: 3.91k, False: 1]
  ------------------
 1018|  3.91k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.91k|#define SC_SUCCESS				0
  ------------------
 1019|       |		/* fill apdu */
 1020|  3.91k|		apdu.p1 = 0xff & (len >> 8);
 1021|  3.91k|		apdu.p2 = 0xff & len;
 1022|  3.91k|		apdu.le = count;
 1023|  3.91k|		apdu.resplen = MAX_RESP_BUFFER_SIZE;
  ------------------
  |  |   56|  3.91k|#define MAX_RESP_BUFFER_SIZE 2048
  ------------------
 1024|  3.91k|		apdu.resp = tmp;
 1025|       |		/* transmit apdu */
 1026|  3.91k|		r = sc_transmit_apdu(card, &apdu);
 1027|  3.91k|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  3.91k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1027:7): [True: 1.41k, False: 2.50k]
  ------------------
 1028|  1.41k|			free(buffer);
 1029|  1.41k|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1029:8): [True: 0, False: 1.41k]
  ------------------
 1030|      0|				free(apdu.resp);
 1031|  1.41k|			sc_log(ctx, "read_binary() APDU transmit failed");
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 1032|  1.41k|			LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  1.41k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.41k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.41k|	int _ret = r; \
  |  |  |  |  155|  1.41k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.41k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.41k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.41k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.41k|	return _ret; \
  |  |  |  |  163|  1.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1033|  1.41k|		}
 1034|  2.50k|		if (apdu.resplen == 0) {
  ------------------
  |  Branch (1034:7): [True: 782, False: 1.71k]
  ------------------
 1035|       |			/* on no data received, check if requested len is longer than
 1036|       |			 * available data in card. If so, ask just for remaining data */
 1037|    782|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1038|    782|			if (r == SC_ERROR_WRONG_LENGTH) {
  ------------------
  |  |   56|    782|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (1038:8): [True: 369, False: 413]
  ------------------
 1039|    369|				count = 0xff & apdu.sw2;
 1040|    369|				if (count != 0) {
  ------------------
  |  Branch (1040:9): [True: 368, False: 1]
  ------------------
 1041|    368|					if (apdu.resp != tmp)
  ------------------
  |  Branch (1041:10): [True: 0, False: 368]
  ------------------
 1042|      0|						free(apdu.resp);
 1043|    368|					continue;	/* read again with correct size */
 1044|    368|				}
 1045|      1|				goto read_done;	/* no more data to read */
 1046|    369|			}
 1047|    413|			if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    413|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1047:8): [True: 1, False: 412]
  ------------------
 1048|      1|				goto read_done;
 1049|    412|			free(buffer);
 1050|    412|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1050:8): [True: 0, False: 412]
  ------------------
 1051|      0|				free(apdu.resp);
 1052|    412|			LOG_FUNC_RETURN(ctx, r);	/* arriving here means response error */
  ------------------
  |  |  164|    412|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    412|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    412|	int _ret = r; \
  |  |  |  |  155|    412|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 412, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    412|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    409|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 409, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|    412|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    412|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    412|	return _ret; \
  |  |  |  |  163|    412|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1053|    412|		}
 1054|       |		/* copy received data into buffer. realloc() if not enough space */
 1055|  1.71k|		count = apdu.resplen;
 1056|  1.71k|		p = realloc(buffer, len + count);
 1057|  1.71k|		if (!p) {
  ------------------
  |  Branch (1057:7): [True: 0, False: 1.71k]
  ------------------
 1058|      0|			free(buffer);
 1059|      0|			free((void *)apdu.data);
 1060|      0|			if (apdu.resp != tmp)
  ------------------
  |  Branch (1060:8): [True: 0, False: 0]
  ------------------
 1061|      0|				free(apdu.resp);
 1062|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1063|      0|		}
 1064|  1.71k|		buffer = p;
 1065|  1.71k|		memcpy(buffer + len, apdu.resp, count);
 1066|  1.71k|		if (apdu.resp != tmp) {
  ------------------
  |  Branch (1066:7): [True: 0, False: 1.71k]
  ------------------
 1067|      0|			free(apdu.resp);
 1068|      0|			apdu.resp = tmp;
 1069|      0|		}
 1070|  1.71k|		len += count;
 1071|  1.71k|		if (count != card->max_recv_size)
  ------------------
  |  Branch (1071:7): [True: 154, False: 1.56k]
  ------------------
 1072|    154|			goto read_done;
 1073|  1.71k|	}
 1074|       |
 1075|    157| read_done:
 1076|    157| 	free((void *)apdu.data);
 1077|    157|	if (apdu.resp != tmp)
  ------------------
  |  Branch (1077:6): [True: 0, False: 157]
  ------------------
 1078|      0|		free(apdu.resp);
 1079|       |
 1080|    157|	if (dnie_is_compressed(card, buffer, len)) {
  ------------------
  |  Branch (1080:6): [True: 13, False: 144]
  ------------------
 1081|     13|		if (flags)
  ------------------
  |  Branch (1081:7): [True: 0, False: 13]
  ------------------
 1082|      0|			*flags |= SC_FILE_FLAG_COMPRESSED_ZLIB;
  ------------------
  |  |  231|      0|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
 1083|       |		/* Remove first 8 bytes with compression info*/
 1084|     13|		len -= 8;
 1085|     13|		p = malloc(len);
 1086|     13|		if (!p) {
  ------------------
  |  Branch (1086:7): [True: 0, False: 13]
  ------------------
 1087|      0|			free(buffer);
 1088|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1089|      0|		}
 1090|     13|		memcpy(p, buffer + 8, len);
 1091|     13|		free(buffer);
 1092|     13|		buffer = p;
 1093|     13|	}
 1094|       |
 1095|       |
 1096|       |	/* ok: as final step, set correct cache data into dnie_priv structures */
 1097|    157|	GET_DNIE_PRIV_DATA(card)->cache = buffer;
  ------------------
  |  |   97|    157|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1098|    157|	GET_DNIE_PRIV_DATA(card)->cachelen = len;
  ------------------
  |  |   97|    157|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1099|    157|	sc_log(ctx, "fill_cache() done. length '%zu' bytes", len);
  ------------------
  |  |   71|    157|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1100|    157|	LOG_FUNC_RETURN(ctx, (int)len);
  ------------------
  |  |  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: 15, False: 142]
  |  |  |  |  ------------------
  |  |  |  |  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|    142|	} else { \
  |  |  |  |  159|    142|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    142|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    142|	} \
  |  |  |  |  162|    157|	return _ret; \
  |  |  |  |  163|    157|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|    157|}
card-dnie.c:dnie_is_compressed:
  941|    157|{
  942|    157|#ifdef ENABLE_ZLIB
  943|    157|	size_t uncompressed = 0L;
  944|    157|	size_t compressed = 0L;
  945|       |
  946|    157|	if (!card || !card->ctx || !from || !len)
  ------------------
  |  Branch (946:6): [True: 0, False: 157]
  |  Branch (946:15): [True: 0, False: 157]
  |  Branch (946:29): [True: 2, False: 155]
  |  Branch (946:38): [True: 0, False: 155]
  ------------------
  947|      2|		return 0;
  948|    155|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    155|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    155|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    155|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    155|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 155]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  949|       |
  950|       |	/* if data size not enough for compression header assume uncompressed */
  951|    155|	if (len < 8)
  ------------------
  |  Branch (951:6): [True: 7, False: 148]
  ------------------
  952|      7|		goto compress_exit;
  953|       |	/* evaluate compressed an uncompressed sizes (little endian format) */
  954|    148|	uncompressed = lebytes2ulong(from);
  955|    148|	compressed = lebytes2ulong(from + 4);
  956|       |	/* if compressed size doesn't match data length assume not compressed */
  957|    148|	if (compressed != len - 8)
  ------------------
  |  Branch (957:6): [True: 101, False: 47]
  ------------------
  958|    101|		goto compress_exit;
  959|       |	/* if compressed size greater than uncompressed, assume uncompressed data */
  960|     47|	if (uncompressed < compressed)
  ------------------
  |  Branch (960:6): [True: 1, False: 46]
  ------------------
  961|      1|		goto compress_exit;
  962|       |	/* Do not try to allocate insane size if we receive bogus data */
  963|     46|	if (uncompressed > MAX_FILE_SIZE)
  ------------------
  |  |  220|     46|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (963:6): [True: 33, False: 13]
  ------------------
  964|     33|		goto compress_exit;
  965|       |
  966|     13|	sc_log(card->ctx, "Data seems to be compressed.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  967|     13|	return 1;
  968|    142|compress_exit:
  969|    142|#endif
  970|       |
  971|    142|	sc_log(card->ctx, "Data not compressed.");
  ------------------
  |  |   71|    142|#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|    142|	return 0;
  973|     46|}
card-dnie.c:dnie_select_file:
 1245|  3.27k|{
 1246|  3.27k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  3.27k|#define SC_SUCCESS				0
  ------------------
 1247|  3.27k|	sc_context_t *ctx = NULL;
 1248|  3.27k|	unsigned char tmp_path[sizeof(DNIE_MF_NAME)];
 1249|  3.27k|	size_t reminder = 0;
 1250|       |
 1251|  3.27k|	if (!card || !card->ctx || !in_path)
  ------------------
  |  Branch (1251:6): [True: 0, False: 3.27k]
  |  Branch (1251:15): [True: 0, False: 3.27k]
  |  Branch (1251:29): [True: 0, False: 3.27k]
  ------------------
 1252|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1253|  3.27k|	ctx = card->ctx;
 1254|       |
 1255|  3.27k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.27k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.27k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.27k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.27k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1256|       |
 1257|  3.27k|	switch (in_path->type) {
 1258|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1258:2): [True: 0, False: 3.27k]
  ------------------
 1259|       |		/* pathlen must be of len=2 */
 1260|       |		/*
 1261|       |		 * gscriptor shows that DNIe also handles
 1262|       |		 * Select child DF (p1=1) and Select EF (p1=2),
 1263|       |		 * but we'll use P1=0 as general solution for all cases
 1264|       |		 *
 1265|       |		 * According iso7816-4 sect 7.1.1  pathlen==0 implies
 1266|       |		 * select MF, but this case is not supported by DNIe
 1267|       |		 */
 1268|      0|		if (in_path->len != 2)
  ------------------
  |  Branch (1268:7): [True: 0, False: 0]
  ------------------
 1269|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1270|      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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1271|      0|		res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 0, file_out);
 1272|      0|		break;
 1273|    623|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    623|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1273:2): [True: 623, False: 2.65k]
  ------------------
 1274|    623|		sc_log_hex(ctx, "select_file(NAME)", in_path->value, in_path->len);
  ------------------
  |  |  129|    623|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    623|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1275|    623|		res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 4, file_out);
 1276|    623|		break;
 1277|  2.65k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  2.65k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (1277:2): [True: 2.65k, False: 623]
  ------------------
 1278|  2.65k|		if ((in_path->len == 0) || ((in_path->len & 1) != 0)) /* not divisible by 2 */
  ------------------
  |  Branch (1278:7): [True: 0, False: 2.65k]
  |  Branch (1278:30): [True: 0, False: 2.65k]
  ------------------
 1279|  2.65k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1280|       |
 1281|  2.65k|		sc_log_hex(ctx, "select_file(PATH): requested", in_path->value, in_path->len);
  ------------------
  |  |  129|  2.65k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  2.65k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1282|       |
 1283|       |		/* convert to SC_PATH_TYPE_FILE_ID */
 1284|  2.65k|		res = sc_lock(card); /* lock to ensure path traversal */
 1285|  2.65k|		LOG_TEST_RET(ctx, res, "sc_lock() failed");
  ------------------
  |  |  174|  2.65k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.65k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.65k|	int _ret = (r); \
  |  |  |  |  168|  2.65k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.65k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.65k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.65k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1286|  2.65k|		if (memcmp(in_path->value, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (1286:7): [True: 2.41k, False: 235]
  ------------------
 1287|       |			/* if MF, use the name as path */
 1288|  2.41k|			strcpy((char *)tmp_path, DNIE_MF_NAME);
  ------------------
  |  |   69|  2.41k|#define DNIE_MF_NAME "Master.File"
  ------------------
 1289|  2.41k|			sc_log_hex(ctx, "select_file(NAME): requested", tmp_path, sizeof(DNIE_MF_NAME) - 1);
  ------------------
  |  |  129|  2.41k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  2.41k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1290|  2.41k|			res = dnie_compose_and_send_apdu(card, tmp_path, sizeof(DNIE_MF_NAME) - 1, 4, file_out);
  ------------------
  |  |   69|  2.41k|#define DNIE_MF_NAME "Master.File"
  ------------------
 1291|  2.41k|			if (res != SC_SUCCESS) {
  ------------------
  |  |   28|  2.41k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1291:8): [True: 1.79k, False: 618]
  ------------------
 1292|  1.79k|				sc_unlock(card);
 1293|  1.79k|				LOG_TEST_RET(ctx, res, "select_file(NAME) failed");
  ------------------
  |  |  174|  1.79k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.79k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.79k|	int _ret = (r); \
  |  |  |  |  168|  1.79k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.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|  1.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.79k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.79k|		return _ret; \
  |  |  |  |  172|  1.79k|	} \
  |  |  |  |  173|  1.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1294|  1.79k|			}
 1295|    618|			tmp_path[2] = 0;
 1296|    618|			reminder = in_path->len - 2;
 1297|    618|		} else {
 1298|    235|			tmp_path[2] = 0;
 1299|    235|			reminder = in_path->len;
 1300|    235|		}
 1301|  1.24k|		while (reminder > 0) {
  ------------------
  |  Branch (1301:10): [True: 543, False: 701]
  ------------------
 1302|    543|			tmp_path[0] = in_path->value[in_path->len - reminder];
 1303|    543|			tmp_path[1] = in_path->value[1 + in_path->len - reminder];
 1304|    543|			sc_log(ctx, "select_file(PATH): requested:%s ", sc_dump_hex(tmp_path, 2));
  ------------------
  |  |   71|    543|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1305|    543|			res = dnie_compose_and_send_apdu(card, tmp_path, 2, 0, file_out);
 1306|    543|			if (res != SC_SUCCESS) {
  ------------------
  |  |   28|    543|#define SC_SUCCESS				0
  ------------------
  |  Branch (1306:8): [True: 152, False: 391]
  ------------------
 1307|    152|				sc_unlock(card);
 1308|    152|				LOG_TEST_RET(ctx, res, "select_file(PATH) failed");
  ------------------
  |  |  174|    152|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    152|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    152|	int _ret = (r); \
  |  |  |  |  168|    152|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 152, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    152|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    152|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    152|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    152|		return _ret; \
  |  |  |  |  172|    152|	} \
  |  |  |  |  173|    152|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1309|    152|			}
 1310|    391|			reminder -= 2;
 1311|    391|		}
 1312|    701|		sc_unlock(card);
 1313|    701|		break;
 1314|      0|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (1314:2): [True: 0, False: 3.27k]
  ------------------
 1315|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1316|      0|		break;
 1317|      0|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (1317:2): [True: 0, False: 3.27k]
  ------------------
 1318|       |		/* Hey!! Manual doesn't says anything on this, but
 1319|       |		 * gscriptor shows that this type is supported
 1320|       |		 */
 1321|      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__
  |  |  ------------------
  ------------------
 1322|       |		/* according iso7816-4 sect 7.1.1 shouldn't have any parameters */
 1323|      0|		if (in_path->len != 0)
  ------------------
  |  Branch (1323:7): [True: 0, False: 0]
  ------------------
 1324|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1325|      0|		res = dnie_compose_and_send_apdu(card, NULL, 0, 3, file_out);
 1326|      0|		break;
 1327|      0|	default:
  ------------------
  |  Branch (1327:2): [True: 0, False: 3.27k]
  ------------------
 1328|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1329|      0|		break;
 1330|  3.27k|	}
 1331|       |
 1332|       |	/* as last step clear data cache and return */
 1333|  1.32k|	dnie_clear_cache(GET_DNIE_PRIV_DATA(card));
  ------------------
  |  |   97|  1.32k|#define GET_DNIE_PRIV_DATA(card) ((dnie_private_data_t *) ((card)->drv_data))
  ------------------
 1334|  1.32k|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|  1.32k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.32k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.32k|	int _ret = r; \
  |  |  |  |  155|  1.32k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.32k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|    355|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 355, False: 969]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.32k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.32k|	return _ret; \
  |  |  |  |  163|  1.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|  1.32k|}
card-dnie.c:dnie_compose_and_send_apdu:
 1158|  3.58k|{
 1159|  3.58k|	int res = 0;
 1160|  3.58k|	sc_apdu_t apdu;
 1161|  3.58k|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
 1162|  3.58k|	sc_context_t *ctx = NULL;
 1163|       |
 1164|  3.58k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1164:6): [True: 0, False: 3.58k]
  |  Branch (1164:15): [True: 0, False: 3.58k]
  ------------------
 1165|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1166|  3.58k|	ctx = card->ctx;
 1167|       |
 1168|  3.58k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  3.58k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.58k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.58k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.58k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.58k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1169|       |
 1170|  3.58k|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0,
  ------------------
  |  |  294|  3.58k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1171|  3.58k|					sc_get_max_recv_size(card), pathlen,
 1172|  3.58k|					rbuf, sizeof(rbuf), path, pathlen);
 1173|  3.58k|	if (p1 == 3)
  ------------------
  |  Branch (1173:6): [True: 0, False: 3.58k]
  ------------------
 1174|      0|		apdu.cse= SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1175|       |
 1176|  3.58k|	if (file_out == NULL)
  ------------------
  |  Branch (1176:6): [True: 1.87k, False: 1.70k]
  ------------------
 1177|  1.87k|		apdu.cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  1.87k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1178|       |
 1179|  3.58k|	res = sc_transmit_apdu(card, &apdu);
 1180|  3.58k|	if ((res != SC_SUCCESS) || (file_out == NULL))
  ------------------
  |  |   28|  3.58k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1180:6): [True: 58, False: 3.52k]
  |  Branch (1180:29): [True: 1.84k, False: 1.68k]
  ------------------
 1181|  3.58k|		LOG_TEST_RET(ctx, res, "SelectFile() APDU transmit failed");
  ------------------
  |  |  174|  1.90k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.90k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.90k|	int _ret = (r); \
  |  |  |  |  168|  1.90k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 58, False: 1.84k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.90k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1182|  3.52k|	if (file_out == NULL) {
  ------------------
  |  Branch (1182:6): [True: 1.84k, False: 1.68k]
  ------------------
 1183|  1.84k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1183:7): [True: 0, False: 1.84k]
  ------------------
 1184|      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]
  |  |  ------------------
  ------------------
 1185|  1.84k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |  153|  1.84k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  1.84k|	int _ret = r; \
  |  |  155|  1.84k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.84k, False: 0]
  |  |  ------------------
  |  |  156|  1.84k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.14k, False: 701]
  |  |  ------------------
  |  |  157|  1.84k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.84k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  1.84k|	return _ret; \
  |  |  163|  1.84k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1186|  1.84k|				sc_check_sw(card, apdu.sw1, apdu.sw2));
 1187|  1.84k|	}
 1188|       |
 1189|       |	/* analyze response. if FCI, try to parse */
 1190|  1.68k|	res = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1191|  1.68k|	if (res != SC_SUCCESS) {
  ------------------
  |  |   28|  1.68k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1191:6): [True: 986, False: 694]
  ------------------
 1192|    986|		LOG_TEST_RET(ctx, res, "SelectFile() check_sw failed");
  ------------------
  |  |  174|    986|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    986|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    986|	int _ret = (r); \
  |  |  |  |  168|    986|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 986, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    986|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    986|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    986|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    986|		return _ret; \
  |  |  |  |  172|    986|	} \
  |  |  |  |  173|    986|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1193|    986|	}
 1194|    694|	if ((apdu.resplen < 2) || (apdu.resp[0] == 0x00)) {
  ------------------
  |  Branch (1194:6): [True: 21, False: 673]
  |  Branch (1194:28): [True: 10, False: 663]
  ------------------
 1195|     31|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     31|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     31|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     31|	int _ret = r; \
  |  |  |  |  155|     31|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     31|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     31|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     31|	return _ret; \
  |  |  |  |  163|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1196|     31|	}
 1197|       |
 1198|    663|	if (file_out) {
  ------------------
  |  Branch (1198:6): [True: 663, False: 0]
  ------------------
 1199|       |		/* finally process FCI response */
 1200|    663|		size_t len = apdu.resp[1];
 1201|    663|		sc_file_free(*file_out);
 1202|    663|		*file_out = sc_file_new();
 1203|    663|		if (*file_out == NULL) {
  ------------------
  |  Branch (1203:7): [True: 0, False: 663]
  ------------------
 1204|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1205|      0|		}
 1206|    663|		if (apdu.resplen - 2 < len || len < 1) {
  ------------------
  |  Branch (1206:7): [True: 31, False: 632]
  |  Branch (1206:33): [True: 24, False: 608]
  ------------------
 1207|     55|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     55|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     55|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     55|	int _ret = r; \
  |  |  |  |  155|     55|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 55, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     55|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 55, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     55|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     55|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     55|	return _ret; \
  |  |  |  |  163|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1208|     55|		}
 1209|    608|		res = card->ops->process_fci(card, *file_out, apdu.resp + 2, len);
 1210|    608|	}
 1211|    608|	LOG_FUNC_RETURN(ctx, res);
  ------------------
  |  |  164|    608|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    608|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    608|	int _ret = r; \
  |  |  |  |  155|    608|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 608, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    608|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 576]
  |  |  |  |  ------------------
  |  |  |  |  157|    608|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    608|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    608|	return _ret; \
  |  |  |  |  163|    608|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1212|    608|}
card-dnie.c:dnie_check_sw:
 1777|  7.79k|{
 1778|  7.79k|	int res = SC_SUCCESS;
  ------------------
  |  |   28|  7.79k|#define SC_SUCCESS				0
  ------------------
 1779|  7.79k|	int n = 0;
 1780|  7.79k|	if (!card || !card->ctx)
  ------------------
  |  Branch (1780:6): [True: 0, False: 7.79k]
  |  Branch (1780:15): [True: 0, False: 7.79k]
  ------------------
 1781|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1782|  7.79k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  7.79k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.79k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.79k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.79k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.79k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1783|       |
 1784|       |	/* check specific dnie errors */
 1785|  31.1k|	for (n = 0; dnie_errors[n].SWs != 0; n++) {
  ------------------
  |  Branch (1785:14): [True: 23.3k, False: 7.74k]
  ------------------
 1786|  23.3k|		if (dnie_errors[n].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (1786:7): [True: 55, False: 23.3k]
  ------------------
 1787|     55|			sc_log(card->ctx, "%s", dnie_errors[n].errorstr);
  ------------------
  |  |   71|     55|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1788|     55|			return dnie_errors[n].errorno;
 1789|     55|		}
 1790|  23.3k|	}
 1791|       |
 1792|       |	/* arriving here means check for supported iso error codes */
 1793|  7.74k|	res = iso_ops->check_sw(card, sw1, sw2);
 1794|  7.74k|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|  7.74k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.74k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.74k|	int _ret = r; \
  |  |  |  |  155|  7.74k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.74k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|  4.51k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.51k, False: 3.22k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.74k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.74k|	return _ret; \
  |  |  |  |  163|  7.74k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1795|  7.74k|}
card-dnie.c:dnie_card_ctl:
 1814|     33|{
 1815|     33|	int result = SC_SUCCESS;
  ------------------
  |  |   28|     33|#define SC_SUCCESS				0
  ------------------
 1816|     33|	if ((card == NULL) || (card->ctx == NULL))
  ------------------
  |  Branch (1816:6): [True: 0, False: 33]
  |  Branch (1816:24): [True: 0, False: 33]
  ------------------
 1817|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1818|     33|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1819|     33|	if (data == NULL) {
  ------------------
  |  Branch (1819:6): [True: 0, False: 33]
  ------------------
 1820|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1821|      0|	}
 1822|     33|	switch (request) {
 1823|       |		/* obtain lifecycle status by reading card->type */
 1824|     16|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1824:2): [True: 16, False: 17]
  ------------------
 1825|     16|		switch (card->type) {
  ------------------
  |  Branch (1825:11): [True: 16, False: 0]
  ------------------
 1826|      0|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (1826:3): [True: 0, False: 16]
  ------------------
 1827|      0|			result = SC_CARDCTRL_LIFECYCLE_ADMIN;
 1828|      0|			break;
 1829|     16|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (1829:3): [True: 16, False: 0]
  ------------------
 1830|     16|			result = SC_CARDCTRL_LIFECYCLE_USER;
 1831|     16|			break;
 1832|      0|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (1832:3): [True: 0, False: 16]
  ------------------
 1833|      0|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (1833:3): [True: 0, False: 16]
  ------------------
 1834|      0|			result = SC_CARDCTRL_LIFECYCLE_OTHER;
 1835|      0|			break;
 1836|     16|		}
 1837|     16|		*(int *)data = result;
 1838|     16|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1839|       |		/* call card to obtain serial number */
 1840|     17|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1840:2): [True: 17, False: 16]
  ------------------
 1841|     17|		result = dnie_get_serialnr(card, (sc_serial_number_t *) data);
 1842|     17|		LOG_FUNC_RETURN(card->ctx, result);
  ------------------
  |  |  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|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1843|      0|	case SC_CARDCTL_DNIE_GENERATE_KEY:
  ------------------
  |  Branch (1843:2): [True: 0, False: 33]
  ------------------
 1844|       |		/* some reports says that this card supports genkey */
 1845|      0|		result = dnie_generate_key(card, data);
 1846|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1847|      0|	case SC_CARDCTL_DNIE_GET_INFO:
  ------------------
  |  Branch (1847:2): [True: 0, False: 33]
  ------------------
 1848|       |		/* retrieve name, surname and eid number */
 1849|      0|		result = dnie_get_info(card, data);
 1850|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1851|      0|	default:
  ------------------
  |  Branch (1851:2): [True: 0, False: 33]
  ------------------
 1852|       |		/* default: unsupported function */
 1853|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1854|     33|	}
 1855|     33|}
card-dnie.c:dnie_get_serialnr:
  648|     17|{
  649|     17|	int result;
  650|     17|	sc_apdu_t apdu;
  651|     17|	u8 rbuf[MAX_RESP_BUFFER_SIZE];
  652|     17|	if ((card == NULL) || (card->ctx == NULL) || (serial == NULL))
  ------------------
  |  Branch (652:6): [True: 0, False: 17]
  |  Branch (652:24): [True: 0, False: 17]
  |  Branch (652:47): [True: 0, False: 17]
  ------------------
  653|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  654|       |
  655|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  656|     17|	if (card->type != SC_CARD_TYPE_DNIE_USER)
  ------------------
  |  Branch (656:6): [True: 0, False: 17]
  ------------------
  657|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  658|       |	/* if serial number is cached, use it */
  659|     17|	if (card->serialnr.len) {
  ------------------
  |  Branch (659:6): [True: 0, False: 17]
  ------------------
  660|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  661|      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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  662|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  663|      0|	}
  664|       |	/* not cached, retrieve it by mean of an APDU */
  665|       |	/* official driver read 0x11 bytes, but only uses 7. Manual says just 7 (for le) */
  666|     17|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xb8, 0x00, 0x00, 0x07, 0,
  ------------------
  |  |  292|     17|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  667|     17|					rbuf, sizeof(rbuf), NULL, 0);
  668|     17|	apdu.cla = 0x90;	/* proprietary cmd */
  669|       |	/* send apdu */
  670|     17|	result = sc_transmit_apdu(card, &apdu);
  671|     17|	if (result != SC_SUCCESS) {
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (671:6): [True: 2, False: 15]
  ------------------
  672|      2|		LOG_TEST_RET(card->ctx, result, "APDU transmit failed");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  673|      2|	}
  674|     15|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (674:6): [True: 12, False: 3]
  |  Branch (674:26): [True: 1, False: 2]
  ------------------
  675|     13|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     13|#define SC_ERROR_INTERNAL			-1400
  ------------------
  676|      2|	if (apdu.resplen < 7)
  ------------------
  |  Branch (676:6): [True: 1, False: 1]
  ------------------
  677|      1|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      1|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  678|       |	/* cache serial number */
  679|      1|	memcpy(card->serialnr.value, apdu.resp, 7 * sizeof(u8));
  680|      1|	card->serialnr.len = 7 * sizeof(u8);
  681|       |	/* TODO: fill Issuer Identification Number data with proper (ATR?) info */
  682|       |	/*
  683|       |	   card->serialnr.iin.mii=;
  684|       |	   card->serialnr.iin.country=;
  685|       |	   card->serialnr.iin.issuer_id=;
  686|       |	 */
  687|       |	/* copy and return serial number */
  688|      1|	memcpy(serial, &card->serialnr, sizeof(*serial));
  689|      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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  690|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  691|      1|}
card-dnie.c:dnie_process_fci:
 1952|    608|{
 1953|    608|	int res = SC_SUCCESS;
  ------------------
  |  |   28|    608|#define SC_SUCCESS				0
  ------------------
 1954|    608|	int *op = df_acl;
 1955|    608|	int n = 0;
 1956|    608|	sc_context_t *ctx = NULL;
 1957|    608|	if ((card == NULL) || (card->ctx == NULL) || (file == NULL) || buflen == 0)
  ------------------
  |  Branch (1957:6): [True: 0, False: 608]
  |  Branch (1957:24): [True: 0, False: 608]
  |  Branch (1957:47): [True: 0, False: 608]
  |  Branch (1957:65): [True: 0, False: 608]
  ------------------
 1958|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1959|    608|	ctx = card->ctx;
 1960|    608|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    608|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    608|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    608|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    608|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 608]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1961|       |	/* first of all, let iso do the hard work */
 1962|    608|	res = iso_ops->process_fci(card, file, buf, buflen);
 1963|    608|	LOG_TEST_RET(ctx, res, "iso7816_process_fci() failed");
  ------------------
  |  |  174|    608|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    608|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    608|	int _ret = (r); \
  |  |  |  |  168|    608|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 608]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    608|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 608]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1964|       |	/* if tag 0x85 is received, then file->prop_attr_len should be filled
 1965|       |	 * by sc_file_set_prop_attr() code. So check and set data according manual
 1966|       |	 * Note errata at pg 35 of Manual  about DF identifier (should be 0x38) */
 1967|    608|	if (file->prop_attr_len == 0) {	/* no proprietary tag (0x85) received */
  ------------------
  |  Branch (1967:6): [True: 224, False: 384]
  ------------------
 1968|    224|		res = SC_SUCCESS;
  ------------------
  |  |   28|    224|#define SC_SUCCESS				0
  ------------------
 1969|    224|		goto dnie_process_fci_end;
 1970|    224|	}
 1971|       |	/* at least 10 bytes should be received */
 1972|    384|	if (file->prop_attr_len < 10) {
  ------------------
  |  Branch (1972:6): [True: 10, False: 374]
  ------------------
 1973|     10|		res = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     10|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1974|     10|		goto dnie_process_fci_end;
 1975|     10|	}
 1976|       |	/* byte 0 denotes file type */
 1977|    374|	switch (file->prop_attr[0]) {
 1978|     38|	case 0x01:		/* EF for plain files */
  ------------------
  |  Branch (1978:2): [True: 38, False: 336]
  ------------------
 1979|     38|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     38|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1980|     38|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     38|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1981|     38|		break;
 1982|     74|	case 0x15:		/* EF for keys: linear variable simple TLV */
  ------------------
  |  Branch (1982:2): [True: 74, False: 300]
  ------------------
 1983|     74|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     74|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1984|       |		/* pin file 3F000000 has also this EF type */
 1985|     74|		if ( ( file->prop_attr[2] == 0x00 ) && (file->prop_attr[3] == 0x00 ) ) {
  ------------------
  |  Branch (1985:8): [True: 33, False: 41]
  |  Branch (1985:42): [True: 18, False: 15]
  ------------------
 1986|     18|			sc_log(ctx,"Processing pin EF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1987|     18|			break;
 1988|     18|		}
 1989|       |		/* FCI response for Keys EF returns 3 additional bytes */
 1990|     56|		if (file->prop_attr_len < 13) {
  ------------------
  |  Branch (1990:7): [True: 11, False: 45]
  ------------------
 1991|     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__
  |  |  ------------------
  ------------------
 1992|     11|			res = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     11|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1993|     11|			goto dnie_process_fci_end;
 1994|     11|		}
 1995|     45|		break;
 1996|    220|	case 0x24:		/* EF for compressed certificates */
  ------------------
  |  Branch (1996:2): [True: 220, False: 154]
  ------------------
 1997|    220|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    220|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1998|    220|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    220|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1999|       |		/* evaluate real length by reading first 8 bytes from file */
 2000|    220|		res = dnie_read_header(card);
 2001|       |		/* Hey!, we need pin to read certificates... */
 2002|    220|		if (res == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|    220|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (2002:7): [True: 1, False: 219]
  ------------------
 2003|      1|			goto dnie_process_fci_end;
 2004|    219|		if (res <= 0) {
  ------------------
  |  Branch (2004:7): [True: 212, False: 7]
  ------------------
 2005|    212|			sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2006|    212|					"Cannot evaluate uncompressed size. use fci length");
 2007|    212|		} else {
 2008|      7|			sc_log(ctx, "Storing uncompressed size '%d' into fci",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2009|      7|					res);
 2010|      7|			file->prop_attr[3] = (u8) ((res >> 8) & 0xff);
 2011|      7|			file->prop_attr[4] = (u8) (res & 0xff);
 2012|      7|		}
 2013|    219|		break;
 2014|     32|	case 0x38:		/* Errata: manual page 35 says wrong 0x34 */
  ------------------
  |  Branch (2014:2): [True: 32, False: 342]
  ------------------
 2015|     32|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     32|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2016|     32|		break;
 2017|     10|	default:
  ------------------
  |  Branch (2017:2): [True: 10, False: 364]
  ------------------
 2018|     10|		res = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     10|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2019|     10|		goto dnie_process_fci_end;
 2020|    374|	}
 2021|       |
 2022|       |	/* bytes 1 and 2 stores file ID */
 2023|    352|	file->id = ( ( 0xff & (int)file->prop_attr[1] ) << 8 ) |
 2024|    352|			( 0xff & (int)file->prop_attr[2] ) ;
 2025|       |
 2026|       |	/* bytes 3 and 4 states file length */
 2027|    352|	file->size = ( ( 0xff & (int)file->prop_attr[3] ) << 8 ) |
 2028|    352|			( 0xff & (int)file->prop_attr[4] ) ;
 2029|       |
 2030|       |	/* bytes 5 to 9 states security attributes */
 2031|       |	/* NOTE:
 2032|       |	 * seems that these 5 bytes are handled according iso7816-9 sect 8.
 2033|       |	 * but sadly that each card uses their own bits :-(
 2034|       |	 * Moreover: Manual talks on 5 bytes, but official driver only uses 4
 2035|       |	 * No info available (yet), so copy code from card-jcos.c / card-flex.c
 2036|       |	 * card drivers and pray... */
 2037|    352|	op = (file->type == SC_FILE_TYPE_DF) ? df_acl : ef_acl;
  ------------------
  |  |  214|    352|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (2037:7): [True: 32, False: 320]
  ------------------
 2038|  2.11k|	for (n = 0; n < 5; n++) {
  ------------------
  |  Branch (2038:14): [True: 1.76k, False: 352]
  ------------------
 2039|  1.76k|		int key_ref = 0;
 2040|  1.76k|		if (*(op + n) == -1)
  ------------------
  |  Branch (2040:7): [True: 352, False: 1.40k]
  ------------------
 2041|    352|			continue;	/* unused entry: skip */
 2042|  1.40k|		key_ref = file->prop_attr[5 + n] & 0x0F;
 2043|  1.40k|		switch (0xF0 & file->prop_attr[5 + n]) {
 2044|    417|		case 0x00:
  ------------------
  |  Branch (2044:3): [True: 417, False: 991]
  ------------------
 2045|    417|			sc_file_add_acl_entry(file, *(op + n), SC_AC_NONE,
  ------------------
  |  |  150|    417|#define SC_AC_NONE			0x00000000
  ------------------
 2046|    417|					SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    417|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2047|    417|			break;
 2048|     95|		case 0x10:
  ------------------
  |  Branch (2048:3): [True: 95, False: 1.31k]
  ------------------
 2049|       |			/* this tag is omitted in official code
 2050|       |			 * case 0x20:
 2051|       |			 */
 2052|    236|		case 0x30:
  ------------------
  |  Branch (2052:3): [True: 141, False: 1.26k]
  ------------------
 2053|    236|			sc_file_add_acl_entry(file, *(op + n), SC_AC_CHV, key_ref);
  ------------------
  |  |  151|    236|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2054|    236|			break;
 2055|    124|		case 0x40:
  ------------------
  |  Branch (2055:3): [True: 124, False: 1.28k]
  ------------------
 2056|    124|			sc_file_add_acl_entry(file, *(op + n), SC_AC_TERM, key_ref);
  ------------------
  |  |  152|    124|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
 2057|    124|			break;
 2058|    189|		case 0xF0:
  ------------------
  |  Branch (2058:3): [True: 189, False: 1.21k]
  ------------------
 2059|    189|			sc_file_add_acl_entry(file, *(op + n), SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    189|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              			sc_file_add_acl_entry(file, *(op + n), SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    189|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2060|    189|			break;
 2061|    442|		default:
  ------------------
  |  Branch (2061:3): [True: 442, False: 966]
  ------------------
 2062|    442|			sc_file_add_acl_entry(file, *(op + n), SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    442|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              			sc_file_add_acl_entry(file, *(op + n), SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    442|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2063|    442|			break;
 2064|  1.40k|		}
 2065|  1.40k|	}
 2066|       |	/* NOTE: Following bytes are described at DNIe manual pg 36, but No
 2067|       |	 * documentation about what to do with following data is provided...
 2068|       |	 * logs suggest that they are neither generated nor handled.
 2069|       |
 2070|       |	 * UPDATE: these additional bytes are received when FileDescriptor tag
 2071|       |	 * is 0x15 (EF for keys)
 2072|       |	 */
 2073|    352|	if (file->prop_attr[0] == 0x15) {
  ------------------
  |  Branch (2073:6): [True: 63, False: 289]
  ------------------
 2074|     63|		sc_log(card->ctx, "Processing flags for Cryptographic key files");
  ------------------
  |  |   71|     63|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2075|       |		/* byte 10 (if present) shows Control Flags for security files */
 2076|       |		/* bytes 11 and 12 (if present) states Control bytes for
 2077|       |		 * RSA crypto files */
 2078|       |		/* TODO: write when know what to do */
 2079|     63|	}
 2080|    352|	res = SC_SUCCESS;	/* arriving here means success */
  ------------------
  |  |   28|    352|#define SC_SUCCESS				0
  ------------------
 2081|    608| dnie_process_fci_end:
 2082|    608|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|    608|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    608|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    608|	int _ret = r; \
  |  |  |  |  155|    608|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 608, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    608|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 576]
  |  |  |  |  ------------------
  |  |  |  |  157|    608|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    608|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    608|	return _ret; \
  |  |  |  |  163|    608|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2083|    608|}
card-dnie.c:dnie_read_header:
 1875|    220|{
 1876|    220|	sc_apdu_t apdu;
 1877|    220|	int r;
 1878|    220|	u8 buf[MAX_RESP_BUFFER_SIZE];
 1879|    220|	unsigned long uncompressed = 0L;
 1880|    220|	unsigned long compressed = 0L;
 1881|    220|	sc_context_t *ctx = NULL;
 1882|       |
 1883|    220|	if (!card || !card->ctx)
  ------------------
  |  Branch (1883:6): [True: 0, False: 220]
  |  Branch (1883:15): [True: 0, False: 220]
  ------------------
 1884|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1885|    220|	ctx = card->ctx;
 1886|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1887|       |
 1888|       |	/* initialize apdu */
 1889|    220|	dnie_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x00, 0x00, 8, 0,
  ------------------
  |  |  292|    220|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1890|    220|					buf, MAX_RESP_BUFFER_SIZE, NULL, 0);
  ------------------
  |  |   56|    220|#define MAX_RESP_BUFFER_SIZE 2048
  ------------------
 1891|       |	/* transmit apdu */
 1892|    220|	r = sc_transmit_apdu(card, &apdu);
 1893|    220|	LOG_TEST_RET(ctx, r, "read_header() APDU transmit 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: 14, False: 206]
  |  |  |  |  ------------------
  |  |  |  |  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|    220|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 206]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1894|    206|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1895|    206|	LOG_TEST_RET(ctx, r, "read_header() 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: 149, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  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|    206|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1896|       |	/* check response */
 1897|     57|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1897:6): [True: 25, False: 32]
  ------------------
 1898|     25|		goto header_notcompressed;
 1899|     32|	uncompressed = lebytes2ulong(apdu.resp);
 1900|     32|	compressed = lebytes2ulong(apdu.resp + 4);
 1901|     32|	if (uncompressed < compressed)
  ------------------
  |  Branch (1901:6): [True: 6, False: 26]
  ------------------
 1902|      6|		goto header_notcompressed;
 1903|     26|	if (uncompressed > 32767)
  ------------------
  |  Branch (1903:6): [True: 19, False: 7]
  ------------------
 1904|     19|		goto header_notcompressed;
 1905|       |	/* ok: assume data is correct */
 1906|      7|	sc_log(ctx, "read_header: uncompressed file size is %lu", uncompressed);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1907|      7|	return (int)(0x7FFF & uncompressed);
 1908|       |
 1909|     50| header_notcompressed:
 1910|     50|	sc_log(ctx, "response doesn't match compressed file header");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1911|     50|	return 0;
 1912|     26|}
card-dnie.c:dnie_pin_cmd:
 2197|     16|{
 2198|     16|	int res = SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
 2199|     16|	int lc = SC_CARDCTRL_LIFECYCLE_USER;
 2200|       |
 2201|     16|	if ((card == NULL) || (card->ctx == NULL) || (data == NULL))
  ------------------
  |  Branch (2201:6): [True: 0, False: 16]
  |  Branch (2201:24): [True: 0, False: 16]
  |  Branch (2201:47): [True: 0, False: 16]
  ------------------
 2202|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2203|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2204|       |
 2205|       |	/*
 2206|       |	* some flags and settings from documentation
 2207|       |	* No (easy) way to handle pinpad through SM, so disable it
 2208|       |	*/
 2209|     16|	data->flags &= ~SC_PIN_CMD_NEED_PADDING; /* no pin padding */
  ------------------
  |  |  422|     16|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 2210|     16|	data->flags &= ~SC_PIN_CMD_USE_PINPAD;	 /* cannot handle pinpad */
  ------------------
  |  |  421|     16|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
 2211|       |
 2212|       |	/* ensure that card is in USER Lifecycle */
 2213|     16|	res = dnie_card_ctl(card, SC_CARDCTL_LIFECYCLE_GET, &lc);
 2214|     16|	LOG_TEST_RET(card->ctx, res, "Cannot get card LC status");
  ------------------
  |  |  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: 0, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2215|     16|	if (lc != SC_CARDCTRL_LIFECYCLE_USER) {
  ------------------
  |  Branch (2215:6): [True: 0, False: 16]
  ------------------
 2216|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2217|      0|	}
 2218|       |
 2219|       |	/* only allow changes on CHV pin ) */
 2220|     16|	switch (data->pin_type) {
 2221|     16|	case SC_AC_CHV:	/* Card Holder Verifier */
  ------------------
  |  |  151|     16|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2221:2): [True: 16, False: 0]
  ------------------
 2222|     16|		break;
 2223|      0|	case SC_AC_TERM:	/* Terminal auth */
  ------------------
  |  |  152|      0|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  |  Branch (2223:2): [True: 0, False: 16]
  ------------------
 2224|      0|	case SC_AC_PRO:	/* SM auth */
  ------------------
  |  |  153|      0|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  |  Branch (2224:2): [True: 0, False: 16]
  ------------------
 2225|      0|	case SC_AC_AUT:	/* Key auth */
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2225:2): [True: 0, False: 16]
  ------------------
 2226|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2227|      0|	default:
  ------------------
  |  Branch (2227:2): [True: 0, False: 16]
  ------------------
 2228|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2229|     16|	}
 2230|       |	/* This DNIe driver only supports VERIFY operation */
 2231|     16|	switch (data->cmd) {
 2232|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2232:2): [True: 0, False: 16]
  ------------------
 2233|      0|		res = dnie_pin_verify(card, data);
 2234|      0|		break;
 2235|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2235:2): [True: 0, False: 16]
  ------------------
 2236|      0|		res = dnie_pin_change(card, data);
 2237|      0|		break;
 2238|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2238:2): [True: 0, False: 16]
  ------------------
 2239|     16|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|     16|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2239:2): [True: 16, False: 0]
  ------------------
 2240|     16|		res= SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     16|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2241|     16|		break;
 2242|      0|	default:
  ------------------
  |  Branch (2242:2): [True: 0, False: 16]
  ------------------
 2243|      0|		res= SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2244|      0|		break;
 2245|     16|	}
 2246|       |	/* return result */
 2247|     16|	LOG_FUNC_RETURN(card->ctx, res);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     16|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     16|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     16|	return _ret; \
  |  |  |  |  163|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2248|     16|}

sc_get_dtrust_driver:
 1059|  16.1k|{
 1060|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1060:6): [True: 1, False: 16.1k]
  ------------------
 1061|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1062|       |
 1063|  16.1k|	dtrust_ops = *iso_ops;
 1064|  16.1k|	dtrust_ops.match_card = dtrust_match_card;
 1065|  16.1k|	dtrust_ops.init = dtrust_init;
 1066|  16.1k|	dtrust_ops.finish = dtrust_finish;
 1067|  16.1k|	dtrust_ops.pin_cmd = dtrust_pin_cmd;
 1068|  16.1k|	dtrust_ops.set_security_env = dtrust_set_security_env;
 1069|  16.1k|	dtrust_ops.compute_signature = dtrust_compute_signature;
 1070|  16.1k|	dtrust_ops.decipher = dtrust_decipher;
 1071|  16.1k|	dtrust_ops.logout = dtrust_logout;
 1072|       |
 1073|  16.1k|	return &dtrust_drv;
 1074|  16.1k|}
card-dtrust.c:dtrust_match_card:
  231|  15.0k|{
  232|  15.0k|	if (_sc_match_atr(card, dtrust_atrs, &card->type) < 0)
  ------------------
  |  Branch (232:6): [True: 14.9k, False: 67]
  ------------------
  233|  14.9k|		return 0;
  234|       |
  235|     67|	if (_dtrust_match_cardos(card) != SC_SUCCESS)
  ------------------
  |  |   28|     67|#define SC_SUCCESS				0
  ------------------
  |  Branch (235:6): [True: 66, False: 1]
  ------------------
  236|     66|		return 0;
  237|       |
  238|      1|	if (_dtrust_match_profile(card) != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (238:6): [True: 1, False: 0]
  ------------------
  239|      1|		return 0;
  240|       |
  241|      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__
  |  |  ------------------
  ------------------
  242|       |
  243|      0|	return 1;
  244|      1|}
card-dtrust.c:_dtrust_match_cardos:
  113|     67|{
  114|     67|	int r;
  115|     67|	size_t prodlen;
  116|     67|	u8 buf[32];
  117|       |
  118|       |	/* check OS version */
  119|     67|	r = sc_get_data(card, 0x0182, buf, 32);
  120|     67|	LOG_TEST_RET(card->ctx, r, "OS version check failed");
  ------------------
  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|     34|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (122:6): [True: 27, False: 7]
  ------------------
  123|     27|		if (r != 2 || buf[0] != 0xc9 || buf[1] != 0x04)
  ------------------
  |  Branch (123:7): [True: 6, False: 21]
  |  Branch (123:17): [True: 1, False: 20]
  |  Branch (123:35): [True: 5, False: 15]
  ------------------
  124|     12|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     12|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  125|     27|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (125:13): [True: 7, False: 0]
  ------------------
  126|      7|		if (r != 2 || buf[0] != 0xcb || buf[1] != 0x01)
  ------------------
  |  Branch (126:7): [True: 4, False: 3]
  |  Branch (126:17): [True: 1, False: 2]
  |  Branch (126:35): [True: 1, False: 1]
  ------------------
  127|      6|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      6|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  128|      7|	}
  129|       |
  130|       |	/* check product name */
  131|     16|	r = sc_get_data(card, 0x0180, buf, 32);
  132|     16|	LOG_TEST_RET(card->ctx, r, "Product name check failed");
  ------------------
  |  |  174|     16|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     16|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     16|	int _ret = (r); \
  |  |  |  |  168|     16|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  133|       |
  134|     13|	prodlen = (size_t)r;
  135|     13|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (135:6): [True: 13, False: 0]
  ------------------
  136|     13|		if (prodlen != strlen("CardOS V5.4     2019") + 1 || memcmp(buf, "CardOS V5.4     2019", prodlen))
  ------------------
  |  Branch (136:7): [True: 6, False: 7]
  |  Branch (136:56): [True: 6, False: 1]
  ------------------
  137|     12|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     12|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  138|     13|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (138:13): [True: 0, False: 0]
  ------------------
  139|      0|		if (prodlen != strlen("CardOS V6.0 2021") + 1 || memcmp(buf, "CardOS V6.0 2021", prodlen))
  ------------------
  |  Branch (139:7): [True: 0, False: 0]
  |  Branch (139:52): [True: 0, False: 0]
  ------------------
  140|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  141|      0|	}
  142|       |
  143|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  144|     13|}
card-dtrust.c:_dtrust_match_profile:
  148|      1|{
  149|      1|	sc_path_t cia_path;
  150|      1|	int r;
  151|      1|	u8 buf[SC_MAX_APDU_BUFFER_SIZE];
  152|      1|	size_t slen, plen;
  153|      1|	const u8 *sp, *pp;
  154|      1|	static char name[64];
  155|       |
  156|      1|	sc_format_path("5032", &cia_path);
  157|      1|	cia_path.aid.len = sizeof(cia_path.aid.value);
  158|      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);
  159|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  160|       |
  161|      1|	r = sc_select_file(card, &cia_path, NULL);
  162|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|      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 */
  ------------------
  165|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  166|       |
  167|      0|	sp = sc_asn1_find_tag(card->ctx, buf, r, 0x30, &slen);
  168|      0|	if (sp == NULL)
  ------------------
  |  Branch (168:6): [True: 0, False: 0]
  ------------------
  169|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  170|       |
  171|       |	/* check vendor */
  172|      0|	pp = sc_asn1_find_tag(card->ctx, sp, slen, 0x0c, &plen);
  173|      0|	if (pp == NULL)
  ------------------
  |  Branch (173:6): [True: 0, False: 0]
  ------------------
  174|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  175|       |
  176|      0|	if (plen != 16 || memcmp(pp, "D-TRUST GmbH (C)", 16))
  ------------------
  |  Branch (176:6): [True: 0, False: 0]
  |  Branch (176:20): [True: 0, False: 0]
  ------------------
  177|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  178|       |
  179|       |	/* check profile */
  180|      0|	pp = sc_asn1_find_tag(card->ctx, sp, slen, 0x80, &plen);
  181|      0|	if (pp == NULL)
  ------------------
  |  Branch (181:6): [True: 0, False: 0]
  ------------------
  182|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  183|       |
  184|       |	/*
  185|       |	 * The profile string contains (two) additional characters. They depend
  186|       |	 * on the production process, but aren't relevant for determining the
  187|       |	 * card profile.
  188|       |	 */
  189|      0|	if (card->type == SC_CARD_TYPE_DTRUST_V4_1_STD) {
  ------------------
  |  Branch (189:6): [True: 0, False: 0]
  ------------------
  190|      0|		if (plen >= 27 && !memcmp(pp, "D-TRUST Card 4.1 Std. RSA 2", 27))
  ------------------
  |  Branch (190:7): [True: 0, False: 0]
  |  Branch (190:21): [True: 0, False: 0]
  ------------------
  191|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_1_STD;
  192|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 4.1 Multi ECC 2", 28))
  ------------------
  |  Branch (192:12): [True: 0, False: 0]
  |  Branch (192:26): [True: 0, False: 0]
  ------------------
  193|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_1_MULTI;
  194|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 4.1 M100 ECC 2", 27))
  ------------------
  |  Branch (194:12): [True: 0, False: 0]
  |  Branch (194:26): [True: 0, False: 0]
  ------------------
  195|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_1_M100;
  196|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 4.4 Std. RSA 2", 27))
  ------------------
  |  Branch (196:12): [True: 0, False: 0]
  |  Branch (196:26): [True: 0, False: 0]
  ------------------
  197|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_4_STD;
  198|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 4.4 Multi ECC 2", 28))
  ------------------
  |  Branch (198:12): [True: 0, False: 0]
  |  Branch (198:26): [True: 0, False: 0]
  ------------------
  199|      0|			card->type = SC_CARD_TYPE_DTRUST_V4_4_MULTI;
  200|      0|		else
  201|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  202|      0|	} else if (card->type == SC_CARD_TYPE_DTRUST_V5_1_STD) {
  ------------------
  |  Branch (202:13): [True: 0, False: 0]
  ------------------
  203|      0|		if (plen >= 27 && !memcmp(pp, "D-TRUST Card 5.1 Std. RSA 2", 27))
  ------------------
  |  Branch (203:7): [True: 0, False: 0]
  |  Branch (203:21): [True: 0, False: 0]
  ------------------
  204|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_1_STD;
  205|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 5.1 Multi ECC 2", 28))
  ------------------
  |  Branch (205:12): [True: 0, False: 0]
  |  Branch (205:26): [True: 0, False: 0]
  ------------------
  206|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_1_MULTI;
  207|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 5.1 M100 ECC 2", 27))
  ------------------
  |  Branch (207:12): [True: 0, False: 0]
  |  Branch (207:26): [True: 0, False: 0]
  ------------------
  208|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_1_M100;
  209|      0|		else if (plen >= 27 && !memcmp(pp, "D-TRUST Card 5.4 Std. RSA 2", 27))
  ------------------
  |  Branch (209:12): [True: 0, False: 0]
  |  Branch (209:26): [True: 0, False: 0]
  ------------------
  210|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_4_STD;
  211|      0|		else if (plen >= 28 && !memcmp(pp, "D-TRUST Card 5.4 Multi ECC 2", 28))
  ------------------
  |  Branch (211:12): [True: 0, False: 0]
  |  Branch (211:26): [True: 0, False: 0]
  ------------------
  212|      0|			card->type = SC_CARD_TYPE_DTRUST_V5_4_MULTI;
  213|      0|		else
  214|      0|			return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  215|      0|	}
  216|       |
  217|      0|	slen = MIN(plen, sizeof(name) - 1);
  ------------------
  |  |   69|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  218|      0|	memcpy(name, pp, slen);
  219|      0|	name[slen] = '\0';
  220|      0|	card->name = name;
  221|       |
  222|      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__
  |  |  ------------------
  ------------------
  223|       |
  224|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  225|      0|}

sc_get_edo_driver:
  327|  16.1k|struct sc_card_driver* sc_get_edo_driver(void) {
  328|  16.1k|	edo_ops = *sc_get_iso7816_driver()->ops;
  329|  16.1k|	edo_ops.match_card = edo_match_card;
  330|  16.1k|	edo_ops.init = edo_init;
  331|  16.1k|	edo_ops.select_file = edo_select_file;
  332|  16.1k|	edo_ops.set_security_env = edo_set_security_env;
  333|  16.1k|	edo_ops.compute_signature = edo_compute_signature;
  334|  16.1k|	edo_ops.logout = edo_logout;
  335|       |
  336|  16.1k|	return &edo_drv;
  337|  16.1k|}
card-edo.c:edo_match_card:
   61|  7.78k|static int edo_match_card(sc_card_t* card) {
   62|  7.78k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
   63|  7.78k|	if (_sc_match_atr(card, edo_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (63:6): [True: 0, False: 7.78k]
  ------------------
   64|      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__
  |  |  ------------------
  ------------------
   65|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   66|      0|	}
   67|  7.78k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7.78k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   68|  7.78k|}

sc_get_entersafe_driver:
 1615|  16.1k|{
 1616|  16.1k|	return sc_get_driver();
 1617|  16.1k|}
card-entersafe.c:sc_get_driver:
 1588|  16.1k|{
 1589|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1590|       |
 1591|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1591:6): [True: 1, False: 16.1k]
  ------------------
 1592|      1|		iso_ops = iso_drv->ops;
 1593|       |
 1594|  16.1k|	entersafe_ops = *iso_drv->ops;
 1595|  16.1k|	entersafe_ops.match_card = entersafe_match_card;
 1596|  16.1k|	entersafe_ops.init = entersafe_init;
 1597|  16.1k|	entersafe_ops.finish = entersafe_finish;
 1598|  16.1k|	entersafe_ops.read_binary = entersafe_read_binary;
 1599|  16.1k|	entersafe_ops.write_binary = NULL;
 1600|  16.1k|	entersafe_ops.update_binary = entersafe_update_binary;
 1601|  16.1k|	entersafe_ops.select_file = entersafe_select_file;
 1602|  16.1k|	entersafe_ops.restore_security_env = entersafe_restore_security_env;
 1603|  16.1k|	entersafe_ops.set_security_env = entersafe_set_security_env;
 1604|  16.1k|	entersafe_ops.decipher = entersafe_decipher;
 1605|  16.1k|	entersafe_ops.compute_signature = entersafe_compute_signature;
 1606|  16.1k|	entersafe_ops.create_file = entersafe_create_file;
 1607|       |	entersafe_ops.delete_file = NULL;
 1608|  16.1k|	entersafe_ops.pin_cmd = entersafe_pin_cmd;
 1609|  16.1k|	entersafe_ops.card_ctl = entersafe_card_ctl_2048;
 1610|  16.1k|	entersafe_ops.process_fci = entersafe_process_fci;
 1611|  16.1k|	return &entersafe_drv;
 1612|  16.1k|}
card-entersafe.c:entersafe_match_card:
  135|  9.76k|{
  136|  9.76k|	int i;
  137|  9.76k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.76k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.76k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.76k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.76k]
  |  |  ------------------
  ------------------
  138|       |
  139|  9.76k|	i = _sc_match_atr(card, entersafe_atrs, &card->type);
  140|  9.76k|	if (i < 0)
  ------------------
  |  Branch (140:6): [True: 9.61k, False: 150]
  ------------------
  141|  9.61k|		return 0;
  142|       |
  143|    150|	return 1;
  144|  9.76k|}
card-entersafe.c:entersafe_init:
  147|    150|{
  148|    150|	unsigned int flags;
  149|       |
  150|    150|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    150|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    150|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    150|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 150]
  |  |  ------------------
  ------------------
  151|       |
  152|    150|	card->name = "entersafe";
  153|    150|	card->cla  = 0x00;
  154|    150|	card->drv_data = NULL;
  155|       |
  156|    150|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |   93|    150|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    150|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    150|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  157|       |
  158|    150|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  159|    150|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  160|    150|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  161|    150|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  162|       |
  163|    150|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    150|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  164|       |
  165|       |	/* we need read_binary&friends with max 224 bytes per read */
  166|    150|	card->max_send_size = 224;
  167|    150|	card->max_recv_size = 224;
  168|    150|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    150|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    150|	int _ret = r; \
  |  |  155|    150|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 150, False: 0]
  |  |  ------------------
  |  |  156|    150|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 150]
  |  |  ------------------
  |  |  157|    150|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    150|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    150|	return _ret; \
  |  |  163|    150|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  169|    150|}
card-entersafe.c:entersafe_finish:
  173|    150|{
  174|    150|	if (card->drv_data) {
  ------------------
  |  Branch (174:6): [True: 0, False: 150]
  ------------------
  175|      0|		free(card->drv_data);
  176|      0|		card->drv_data = NULL;
  177|      0|	}
  178|    150|	return SC_SUCCESS;
  ------------------
  |  |   28|    150|#define SC_SUCCESS				0
  ------------------
  179|    150|}
card-entersafe.c:entersafe_read_binary:
  437|    956|{
  438|    956|	sc_apdu_t apdu;
  439|    956|	u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  440|    956|	int r;
  441|       |
  442|    956|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    956|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    956|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    956|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 956]
  |  |  ------------------
  ------------------
  443|       |
  444|    956|	if (count > card->max_recv_size)
  ------------------
  |  Branch (444:6): [True: 0, False: 956]
  ------------------
  445|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  446|    956|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0xFF, idx & 0xFF);
  ------------------
  |  |  292|    956|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  447|       |
  448|    956|	apdu.cla = idx > 0x7fff ? 0x80 : 0x00;
  ------------------
  |  Branch (448:13): [True: 0, False: 956]
  ------------------
  449|    956|	apdu.le = count;
  450|    956|	apdu.resplen = count;
  451|    956|	apdu.resp = recvbuf;
  452|       |
  453|    956|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
  454|    956|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    956|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    956|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    956|	int _ret = (r); \
  |  |  |  |  168|    956|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 948]
  |  |  |  |  ------------------
  |  |  |  |  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|    956|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 948]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|    948|	if (apdu.resplen == 0)
  ------------------
  |  Branch (455:6): [True: 87, False: 861]
  ------------------
  456|     87|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|     87|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     87|	int _ret = r; \
  |  |  155|     87|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 87, False: 0]
  |  |  ------------------
  |  |  156|     87|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     87|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 87, False: 0]
  |  |  ------------------
  |  |  157|     87|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     87|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     87|	return _ret; \
  |  |  163|     87|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  457|    861|	if (apdu.resplen > count)
  ------------------
  |  Branch (457:6): [True: 0, False: 861]
  ------------------
  458|      0|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  459|    861|	memcpy(buf, recvbuf, apdu.resplen);
  460|       |
  461|    861|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, (int)apdu.resplen);
  ------------------
  |  |  153|    861|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    861|	int _ret = r; \
  |  |  155|    861|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 861]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    861|	} else { \
  |  |  159|    861|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    861|			"returning with: %d\n", _ret); \
  |  |  161|    861|	} \
  |  |  162|    861|	return _ret; \
  |  |  163|    861|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  462|    861|}
card-entersafe.c:entersafe_transmit_apdu:
  380|  1.11k|{
  381|  1.11k|	u8 *cipher_data = NULL, *mac_data = NULL;
  382|  1.11k|	size_t cipher_data_size, mac_data_size, blocks;
  383|  1.11k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.11k|#define SC_SUCCESS				0
  ------------------
  384|  1.11k|	u8 *sbuf = NULL;
  385|  1.11k|	size_t ssize = 0;
  386|       |
  387|  1.11k|	if (card == NULL || apdu == NULL)
  ------------------
  |  Branch (387:6): [True: 0, False: 1.11k]
  |  Branch (387:22): [True: 0, False: 1.11k]
  ------------------
  388|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  389|       |
  390|  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]
  |  |  ------------------
  ------------------
  391|       |
  392|  1.11k|	if ((cipher || mac) && (!key || (keylen != 8 && keylen != 16)))
  ------------------
  |  Branch (392:7): [True: 0, False: 1.11k]
  |  Branch (392:17): [True: 0, False: 1.11k]
  |  Branch (392:26): [True: 0, False: 0]
  |  Branch (392:35): [True: 0, False: 0]
  |  Branch (392:50): [True: 0, False: 0]
  ------------------
  393|      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]
  |  |  ------------------
  ------------------
  394|       |
  395|  1.11k|	r = sc_apdu_get_octets(card->ctx, apdu, &sbuf, &ssize, SC_PROTO_RAW);
  ------------------
  |  |  354|  1.11k|#define SC_PROTO_RAW		0x00001000
  ------------------
  396|  1.11k|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|  1.11k|#define SC_SUCCESS				0
  ------------------
  |  Branch (396:6): [True: 1.11k, False: 0]
  ------------------
  397|  1.11k|		sc_apdu_log(card->ctx, sbuf, ssize, 1);
  ------------------
  |  |  291|  1.11k|	sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, is_outgoing != 0 ? "Outgoing APDU" : "Incoming APDU", data, len)
  |  |  ------------------
  |  |  |  |  127|  2.23k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (127:65): [True: 1.11k, Folded]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|  1.11k|	if (sbuf)
  ------------------
  |  Branch (398:6): [True: 1.11k, False: 0]
  ------------------
  399|  1.11k|		free(sbuf);
  400|       |
  401|  1.11k|	if (cipher) {
  ------------------
  |  Branch (401:6): [True: 0, False: 1.11k]
  ------------------
  402|      0|		blocks = (apdu->lc + 2) / 8 + 1;
  403|      0|		cipher_data_size = blocks * 8;
  404|      0|		cipher_data = malloc(cipher_data_size);
  405|      0|		if (!cipher_data) {
  ------------------
  |  Branch (405:7): [True: 0, False: 0]
  ------------------
  406|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  407|      0|			goto out;
  408|      0|		}
  409|       |
  410|      0|		if ((r = entersafe_cipher_apdu(card, apdu, key, keylen, cipher_data, cipher_data_size)) < 0)
  ------------------
  |  Branch (410:7): [True: 0, False: 0]
  ------------------
  411|      0|			goto out;
  412|      0|	}
  413|  1.11k|	if (mac) {
  ------------------
  |  Branch (413:6): [True: 0, False: 1.11k]
  ------------------
  414|      0|		mac_data_size = apdu->lc + 4;
  415|      0|		mac_data = malloc(mac_data_size);
  416|      0|		if (!mac_data) {
  ------------------
  |  Branch (416:7): [True: 0, False: 0]
  ------------------
  417|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  418|      0|			goto out;
  419|      0|		}
  420|      0|		r = entersafe_mac_apdu(card, apdu, key, keylen, mac_data, mac_data_size);
  421|      0|		if (r < 0)
  ------------------
  |  Branch (421:7): [True: 0, False: 0]
  ------------------
  422|      0|			goto out;
  423|      0|	}
  424|       |
  425|  1.11k|	r = sc_transmit_apdu(card, apdu);
  426|       |
  427|  1.11k|out:
  428|  1.11k|	free(cipher_data);
  429|  1.11k|	free(mac_data);
  430|       |
  431|  1.11k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 14, False: 1.10k]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  432|  1.11k|}
card-entersafe.c:entersafe_select_file:
  604|    694|{
  605|    694|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (605:6): [True: 0, False: 694]
  |  Branch (605:22): [True: 0, False: 694]
  ------------------
  606|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  607|    694|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    694|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    694|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    694|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 694]
  |  |  ------------------
  ------------------
  608|       |
  609|    694|	switch (in_path->type) {
  610|      0|		case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (610:3): [True: 0, False: 694]
  ------------------
  611|      0|			if (in_path->len != 2)
  ------------------
  |  Branch (611:8): [True: 0, False: 0]
  ------------------
  612|      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]
  |  |  ------------------
  ------------------
  613|      0|			return entersafe_select_fid(card,in_path->value[0], in_path->value[1], file_out);
  614|    331|		case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    331|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (614:3): [True: 331, False: 363]
  ------------------
  615|    331|			return entersafe_select_aid(card, in_path, file_out);
  616|    363|		case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    363|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (616:3): [True: 363, False: 331]
  ------------------
  617|    363|			return entersafe_select_path(card, in_path->value, in_path->len, file_out);
  618|      0|		default:
  ------------------
  |  Branch (618:3): [True: 0, False: 694]
  ------------------
  619|      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]
  |  |  ------------------
  ------------------
  620|    694|	}
  621|    694|}
card-entersafe.c:entersafe_select_fid:
  515|    523|{
  516|    523|	int r;
  517|    523|	sc_file_t *file = NULL;
  518|    523|	sc_path_t path;
  519|       |
  520|    523|	memset(&path, 0, sizeof(sc_path_t));
  521|       |
  522|    523|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    523|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  523|    523|	path.value[0] = id_hi;
  524|    523|	path.value[1] = id_lo;
  525|    523|	path.len = 2;
  526|       |
  527|    523|	r = iso_ops->select_file(card, &path, &file);
  528|    523|	if (r < 0)
  ------------------
  |  Branch (528:6): [True: 219, False: 304]
  ------------------
  529|    219|		sc_file_free(file);
  530|    523|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    523|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    523|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    523|	int _ret = (r); \
  |  |  |  |  168|    523|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 219, False: 304]
  |  |  |  |  ------------------
  |  |  |  |  169|    219|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    219|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    219|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    219|		return _ret; \
  |  |  |  |  172|    219|	} \
  |  |  |  |  173|    523|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 304]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  531|       |
  532|    304|	if (file_out)
  ------------------
  |  Branch (532:6): [True: 125, False: 179]
  ------------------
  533|    125|		*file_out = file;
  534|    179|	else
  535|    179|		sc_file_free(file);
  536|       |
  537|    304|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  153|    304|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    304|	int _ret = r; \
  |  |  155|    304|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 304, False: 0]
  |  |  ------------------
  |  |  156|    304|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 304]
  |  |  ------------------
  |  |  157|    304|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    304|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    304|	return _ret; \
  |  |  163|    304|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  538|    304|}
card-entersafe.c:entersafe_select_aid:
  543|    331|{
  544|    331|	int r;
  545|       |
  546|    331|	r = iso_ops->select_file(card, in_path, file_out);
  547|    331|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    331|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    331|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    331|	int _ret = (r); \
  |  |  |  |  168|    331|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 305, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  169|    305|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    305|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    305|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    305|		return _ret; \
  |  |  |  |  172|    305|	} \
  |  |  |  |  173|    331|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  548|       |
  549|     26|	if (file_out) {
  ------------------
  |  Branch (549:6): [True: 0, False: 26]
  ------------------
  550|      0|		sc_file_t *file = *file_out;
  551|      0|		if (file == NULL)
  ------------------
  |  Branch (551:7): [True: 0, False: 0]
  ------------------
  552|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  553|      0|		if (in_path->len > sizeof(file->name))
  ------------------
  |  Branch (553:7): [True: 0, False: 0]
  ------------------
  554|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  555|       |
  556|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  557|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  558|      0|		file->path.len = 0;
  559|      0|		file->size = 0;
  560|       |		/* AID */
  561|      0|		memcpy(file->name, in_path->value, in_path->len);
  562|      0|		file->namelen = in_path->len;
  563|      0|		file->id = 0x0000;
  564|      0|	}
  565|     26|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  566|     26|}
card-entersafe.c:entersafe_select_path:
  571|    363|{
  572|    363|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
  573|    363|	const u8 *path = pathbuf;
  574|    363|	size_t pathlen = len;
  575|    363|	unsigned int i;
  576|    363|	int r;
  577|       |
  578|    363|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (578:6): [True: 0, False: 363]
  |  Branch (578:26): [True: 2, False: 361]
  |  Branch (578:41): [True: 1, False: 360]
  ------------------
  579|      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]
  |  |  ------------------
  ------------------
  580|       |
  581|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
  582|    360|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (582:6): [True: 19, False: 341]
  |  Branch (582:23): [True: 2, False: 17]
  |  Branch (582:42): [True: 1, False: 16]
  ------------------
  583|      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]
  |  |  ------------------
  ------------------
  584|       |
  585|       |	/* unify path (the first FID should be MF) */
  586|    357|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (586:6): [True: 12, False: 345]
  |  Branch (586:25): [True: 3, False: 342]
  ------------------
  587|     15|		n_pathbuf[0] = 0x3f;
  588|     15|		n_pathbuf[1] = 0x00;
  589|     15|		memcpy(n_pathbuf + 2, path, pathlen);
  590|     15|		path = n_pathbuf;
  591|     15|		pathlen += 2;
  592|     15|	}
  593|       |
  594|    523|	for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (594:14): [True: 367, False: 156]
  ------------------
  595|    367|		r = entersafe_select_fid(card, path[i], path[i + 1], NULL);
  596|    367|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|    367|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    367|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    367|	int _ret = (r); \
  |  |  |  |  168|    367|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 201, False: 166]
  |  |  |  |  ------------------
  |  |  |  |  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|    367|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 166]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  597|    367|	}
  598|    156|	return entersafe_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
  599|    357|}
card-entersafe.c:entersafe_pin_cmd:
  902|      7|{
  903|      7|	int r;
  904|      7|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  905|      7|	entersafe_init_pin_info(&data->pin1, 0);
  906|      7|	entersafe_init_pin_info(&data->pin2, 1);
  907|      7|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|      7|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  908|       |
  909|      7|	if (data->cmd != SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|      7|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (909:6): [True: 7, False: 0]
  ------------------
  910|      7|		r = iso_ops->pin_cmd(card, data);
  911|      7|		sc_log(card->ctx, "Verify rv:%i", r);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  912|      7|	} else {
  913|      0|		{ /*verify*/
  914|      0|			sc_apdu_t apdu;
  915|      0|			u8 sbuf[0x10] = {0};
  916|       |
  917|      0|			if (data->pin1.len > sizeof(sbuf)) {
  ------------------
  |  Branch (917:8): [True: 0, False: 0]
  ------------------
  918|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  919|      0|			}
  920|       |
  921|      0|			memcpy(sbuf, data->pin1.data, data->pin1.len);
  922|      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
  ------------------
  923|      0|			apdu.lc = apdu.datalen = sizeof(sbuf);
  924|      0|			apdu.data = sbuf;
  925|       |
  926|      0|			r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
  927|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  928|      0|		}
  929|       |
  930|      0|		{ /*change*/
  931|      0|			sc_apdu_t apdu;
  932|      0|			u8 sbuf[0x12] = {0};
  933|       |
  934|      0|			if (data->pin2.len + 2 > sizeof(sbuf)) {
  ------------------
  |  Branch (934:8): [True: 0, False: 0]
  ------------------
  935|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  936|      0|			}
  937|       |
  938|      0|			sbuf[0] = 0x33;
  939|      0|			sbuf[1] = 0x00;
  940|      0|			memcpy(sbuf + 2, data->pin2.data, data->pin2.len);
  941|      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
  ------------------
  942|      0|			apdu.cla = 0x84;
  943|      0|			apdu.lc = apdu.datalen = sizeof(sbuf);
  944|      0|			apdu.data = sbuf;
  945|       |
  946|      0|			r = entersafe_transmit_apdu(card, &apdu, key_maintain, sizeof(key_maintain), 1, 1);
  947|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  948|      0|		}
  949|      0|	}
  950|      7|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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]
  |  |  ------------------
  ------------------
  951|      7|}
card-entersafe.c:entersafe_init_pin_info:
  892|     14|{
  893|     14|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     14|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  894|     14|	pin->min_length = 4;
  895|     14|	pin->max_length = 16;
  896|     14|	pin->pad_length = 16;
  897|     14|	pin->offset     = 5 + num * 16;
  898|     14|	pin->pad_char   = 0x00;
  899|     14|}
card-entersafe.c:entersafe_card_ctl_2048:
 1557|    159|{
 1558|    159|	sc_entersafe_create_data *tmp = (sc_entersafe_create_data *)ptr;
 1559|       |
 1560|    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]
  |  |  ------------------
  ------------------
 1561|       |
 1562|    159|	switch (cmd) {
 1563|      0|		case SC_CARDCTL_ENTERSAFE_CREATE_FILE:
  ------------------
  |  Branch (1563:3): [True: 0, False: 159]
  ------------------
 1564|      0|			if (tmp->type == SC_ENTERSAFE_MF_DATA)
  ------------------
  |  |  666|      0|#define	SC_ENTERSAFE_MF_DATA	0x01
  ------------------
  |  Branch (1564:8): [True: 0, False: 0]
  ------------------
 1565|      0|				return entersafe_create_mf(card, tmp);
 1566|      0|			else if (tmp->type == SC_ENTERSAFE_DF_DATA)
  ------------------
  |  |  667|      0|#define SC_ENTERSAFE_DF_DATA	0x02
  ------------------
  |  Branch (1566:13): [True: 0, False: 0]
  ------------------
 1567|      0|				return entersafe_create_df(card, tmp);
 1568|      0|			else if (tmp->type == SC_ENTERSAFE_EF_DATA)
  ------------------
  |  |  668|      0|#define SC_ENTERSAFE_EF_DATA	0x04
  ------------------
  |  Branch (1568:13): [True: 0, False: 0]
  ------------------
 1569|      0|				return entersafe_create_ef(card, tmp);
 1570|      0|			else
 1571|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1572|      0|		case SC_CARDCTL_ENTERSAFE_WRITE_KEY:
  ------------------
  |  Branch (1572:3): [True: 0, False: 159]
  ------------------
 1573|      0|			return entersafe_write_key(card, (sc_entersafe_wkey_data *)ptr);
 1574|      0|		case SC_CARDCTL_ENTERSAFE_GENERATE_KEY:
  ------------------
  |  Branch (1574:3): [True: 0, False: 159]
  ------------------
 1575|      0|			return entersafe_gen_key(card, (sc_entersafe_gen_key_data *)ptr);
 1576|      0|		case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (1576:3): [True: 0, False: 159]
  ------------------
 1577|      0|			return entersafe_erase_card(card);
 1578|    159|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1578:3): [True: 159, False: 0]
  ------------------
 1579|    159|			return entersafe_get_serialnr(card, (sc_serial_number_t *)ptr);
 1580|      0|		case SC_CARDCTL_ENTERSAFE_PREINSTALL_KEYS:
  ------------------
  |  Branch (1580:3): [True: 0, False: 159]
  ------------------
 1581|      0|			return entersafe_preinstall_keys(card, entersafe_preinstall_rsa_2048);
 1582|      0|		default:
  ------------------
  |  Branch (1582:3): [True: 0, False: 159]
  ------------------
 1583|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1584|    159|	}
 1585|    159|}
card-entersafe.c:entersafe_get_serialnr:
 1382|    159|{
 1383|    159|	int	r;
 1384|    159|	sc_apdu_t apdu;
 1385|    159|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1386|       |
 1387|    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]
  |  |  ------------------
  ------------------
 1388|    159|	if (serial == NULL)
  ------------------
  |  Branch (1388:6): [True: 0, False: 159]
  ------------------
 1389|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1390|       |
 1391|    159|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xEA, 0x00, 0x00);
  ------------------
  |  |  292|    159|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1392|    159|	apdu.cla = 0x80;
 1393|    159|	apdu.resp = rbuf;
 1394|    159|	apdu.resplen = sizeof(rbuf);
 1395|    159|	apdu.le = 0x08;
 1396|       |
 1397|    159|	r = entersafe_transmit_apdu(card, &apdu, 0, 0, 0, 0);
 1398|    159|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 6, False: 153]
  |  |  |  |  ------------------
  |  |  |  |  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|    159|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 153]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1399|    153|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "EnterSafe get SN failed");
  ------------------
  |  |  174|    153|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    153|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    153|	int _ret = (r); \
  |  |  |  |  168|    153|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 137, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|    153|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1400|     16|	if (apdu.resplen != 8)
  ------------------
  |  Branch (1400:6): [True: 11, False: 5]
  ------------------
 1401|     16|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Invalid length of SN");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1402|       |
 1403|      5|	card->serialnr.len = serial->len = 8;
 1404|      5|	memcpy(card->serialnr.value, rbuf, 8);
 1405|      5|	memcpy(serial->value, rbuf, 8);
 1406|       |
 1407|      5|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_SUCCESS);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1408|      5|}
card-entersafe.c:entersafe_process_fci:
  491|    192|{
  492|    192|	int r;
  493|       |
  494|    192|	if (file == NULL)
  ------------------
  |  Branch (494:6): [True: 0, False: 192]
  ------------------
  495|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  496|    192|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    192|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    192|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    192|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 192]
  |  |  ------------------
  ------------------
  497|       |
  498|    192|	r = iso_ops->process_fci(card, file, buf, buflen);
  499|    192|	LOG_TEST_RET(card->ctx, r, "Process fci failed");
  ------------------
  |  |  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: 0, False: 192]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    192|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 192]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  500|       |
  501|    192|	if (file->namelen) {
  ------------------
  |  Branch (501:6): [True: 19, False: 173]
  ------------------
  502|     19|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     19|#define SC_FILE_TYPE_DF			0x04
  ------------------
  503|     19|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|     19|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  504|    173|	} else {
  505|    173|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    173|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  506|    173|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    173|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  507|    173|	}
  508|       |
  509|    192|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    192|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    192|	int _ret = r; \
  |  |  155|    192|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 192, False: 0]
  |  |  ------------------
  |  |  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|    192|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    192|	return _ret; \
  |  |  163|    192|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  510|    192|}

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

epass2003_refresh:
  934|  1.38k|{
  935|  1.38k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.38k|#define SC_SUCCESS				0
  ------------------
  936|  1.38k|	epass2003_exdata *exdata = NULL;
  937|       |
  938|  1.38k|	if (!card->drv_data)
  ------------------
  |  Branch (938:6): [True: 0, False: 1.38k]
  ------------------
  939|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  940|       |
  941|  1.38k|	exdata = (epass2003_exdata *)card->drv_data;
  942|       |
  943|  1.38k|	if (exdata->sm) {
  ------------------
  |  Branch (943:6): [True: 1.05k, False: 328]
  ------------------
  944|       |		/* Hold the reader lock so that no other process can establish its own session in the
  945|       |		 * middle of the handshake. */
  946|  1.05k|		card->sm_ctx.sm_mode = 0;
  947|  1.05k|		r = sc_lock(card);
  948|  1.05k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.05k|#define SC_SUCCESS				0
  ------------------
  |  Branch (948:7): [True: 1.05k, False: 0]
  ------------------
  949|  1.05k|			r = mutual_auth(card, g_init_key_enc, g_init_key_mac);
  950|  1.05k|			sc_unlock(card);
  951|  1.05k|		}
  952|  1.05k|		LOG_TEST_RET(card->ctx, r, "mutual_auth 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: 1.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  953|      0|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  954|      0|	}
  955|       |
  956|    328|	return r;
  957|  1.38k|}
sec_attr_to_entry:
 2482|  2.81k|{
 2483|  2.81k|	int i;
 2484|  2.81k|	int found = 0;
 2485|       |
 2486|  2.81k|	unsigned int method;
 2487|  2.81k|	unsigned long  keyref;
 2488|       |
 2489|  2.81k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.81k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.81k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.81k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.81k]
  |  |  ------------------
  ------------------
 2490|       |
 2491|  2.81k|	switch (file->sec_attr[index]) {
 2492|    118|	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_EVERYONE):
  ------------------
  |  |  739|    118|#define EPASS2003_AC_MAC_NOLESS		0x90
  ------------------
              	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_EVERYONE):
  ------------------
  |  |  734|    118|#define EPASS2003_AC_EVERYONE		0x00
  ------------------
  |  Branch (2492:2): [True: 118, False: 2.69k]
  ------------------
 2493|    118|		method = SC_AC_NONE;
  ------------------
  |  |  150|    118|#define SC_AC_NONE			0x00000000
  ------------------
 2494|    118|		keyref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    118|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2495|    118|		break;
 2496|    113|	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER):
  ------------------
  |  |  739|    113|#define EPASS2003_AC_MAC_NOLESS		0x90
  ------------------
              	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER):
  ------------------
  |  |  735|    113|#define EPASS2003_AC_USER		0x06
  ------------------
  |  Branch (2496:2): [True: 113, False: 2.69k]
  ------------------
 2497|    113|		method = SC_AC_CHV;
  ------------------
  |  |  151|    113|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2498|    113|		keyref = 1;
 2499|    113|		break;
 2500|  2.58k|	default:
  ------------------
  |  Branch (2500:2): [True: 2.58k, False: 231]
  ------------------
 2501|  2.58k|		sc_log(card->ctx, "Unknown value 0x%2.2x in file->sec_attr[%d]", file->sec_attr[index], index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2502|  2.58k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  2.58k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 2503|  2.58k|		keyref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  2.58k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2504|  2.58k|		break;
 2505|  2.81k|	}
 2506|       |
 2507|  95.6k|	for (i = 0; i < (int)(sizeof(sec_attr_to_acl_entry) / sizeof(sec_attr_to_acl_entries_t)); i++) {
  ------------------
  |  Branch (2507:14): [True: 92.7k, False: 2.81k]
  ------------------
 2508|  92.7k|		const sec_attr_to_acl_entries_t *e = &sec_attr_to_acl_entry[i];
 2509|       |
 2510|  92.7k|		if (index == e->index && file->type == e->file_type
  ------------------
  |  Branch (2510:7): [True: 7.18k, False: 85.6k]
  |  Branch (2510:28): [True: 1.66k, False: 5.51k]
  ------------------
 2511|  1.66k|				&& file->ef_structure == e->file_ef_structure) {
  ------------------
  |  Branch (2511:8): [True: 350, False: 1.31k]
  ------------------
 2512|       |				/* may add multiple entries */
 2513|    350|			sc_file_add_acl_entry(file, e->op, method, keyref);
 2514|    350|			found++;
 2515|    350|		}
 2516|  92.7k|	}
 2517|  2.81k|	if (found != 1) {
  ------------------
  |  Branch (2517:6): [True: 2.55k, False: 256]
  ------------------
 2518|  2.55k|		sc_log(card->ctx,"found %d entries ", found);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2519|  2.55k|	}
 2520|       |
 2521|  2.81k|	return 0;
 2522|  2.81k|}
sc_get_epass2003_driver:
 3592|  16.1k|{
 3593|  16.1k|	return sc_get_driver();
 3594|  16.1k|}
card-epass2003.c:mutual_auth:
  904|  1.05k|{
  905|  1.05k|	struct sc_context *ctx = card->ctx;
  906|  1.05k|	int r;
  907|  1.05k|	unsigned char result[256] = {0};
  908|  1.05k|	unsigned char ran_key[8] = {0};
  909|  1.05k|	epass2003_exdata *exdata = NULL;
  910|       |
  911|  1.05k|	if (!card->drv_data)
  ------------------
  |  Branch (911:6): [True: 0, False: 1.05k]
  ------------------
  912|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  913|  1.05k|	exdata = (epass2003_exdata *)card->drv_data;
  914|       |
  915|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  916|       |
  917|  1.05k|	r = gen_init_key(card, key_enc, key_mac, result, exdata->smtype);
  918|  1.05k|	LOG_TEST_RET(ctx, r, "gen_init_key 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: 1.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  919|      0|	if (exdata->bFipsCertification) {
  ------------------
  |  Branch (919:6): [True: 0, False: 0]
  ------------------
  920|      0|		memcpy(ran_key, &result[12+1], 8);
  921|      0|	} else {
  922|      0|		memcpy(ran_key, &result[12], 8);
  923|      0|	}
  924|       |
  925|      0|	r = verify_init_key(card, ran_key, exdata->smtype);
  926|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  927|       |
  928|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  929|      0|}
card-epass2003.c:gen_init_key:
  687|  1.05k|{
  688|  1.05k|	int r;
  689|  1.05k|	struct sc_apdu apdu;
  690|  1.05k|	unsigned char data[256] = {0};
  691|  1.05k|	unsigned char tmp_sm;
  692|  1.05k|	unsigned char isFips;
  693|  1.05k|	unsigned long blocksize = 0;
  694|  1.05k|	unsigned char cryptogram[256] = {0}; /* host cryptogram */
  695|  1.05k|	unsigned char iv[16] = {0};
  696|  1.05k|	epass2003_exdata *exdata = NULL;
  697|       |
  698|  1.05k|	if (!card->drv_data)
  ------------------
  |  Branch (698:6): [True: 0, False: 1.05k]
  ------------------
  699|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  700|       |
  701|  1.05k|	exdata = (epass2003_exdata *)card->drv_data;
  702|  1.05k|	isFips = exdata->bFipsCertification;
  703|       |
  704|  1.05k|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  705|       |
  706|  1.05k|	if (1 != RAND_bytes(g_random, sizeof(g_random)))
  ------------------
  |  Branch (706:6): [True: 0, False: 1.05k]
  ------------------
  707|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  708|       |
  709|  1.05k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x50, 0x00, 0x00);
  ------------------
  |  |  294|  1.05k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  710|  1.05k|	apdu.cla = 0x80;
  711|  1.05k|	apdu.lc = apdu.datalen = sizeof(g_random);
  712|  1.05k|	apdu.data = g_random;	/* host random */
  713|  1.05k|	if (isFips)
  ------------------
  |  Branch (713:6): [True: 35, False: 1.02k]
  ------------------
  714|     35|		apdu.le = apdu.resplen = 29;
  715|  1.02k|	else
  716|  1.02k|		apdu.le = apdu.resplen = 28;
  717|       |
  718|  1.05k|	apdu.resp = result;	/* card random is result[12~19] */
  719|       |
  720|  1.05k|	tmp_sm = exdata->sm;
  721|  1.05k|	exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|  1.05k|#define SM_PLAIN				0x00
  ------------------
  722|  1.05k|	r = epass2003_transmit_apdu(card, &apdu);
  723|  1.05k|	exdata->sm = tmp_sm;
  724|  1.05k|	LOG_TEST_RET(card->ctx, r, "APDU gen_init_key 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: 30, False: 1.02k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  725|       |
  726|  1.02k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  727|  1.02k|	LOG_TEST_RET(card->ctx, r, "gen_init_key failed");
  ------------------
  |  |  174|  1.02k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.02k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.02k|	int _ret = (r); \
  |  |  |  |  168|  1.02k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 978, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  169|    978|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    978|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    978|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    978|		return _ret; \
  |  |  |  |  172|    978|	} \
  |  |  |  |  173|  1.02k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  728|       |
  729|       |	/* Step 1 - Generate Derivation data */
  730|     50|	if (isFips) {
  ------------------
  |  Branch (730:6): [True: 15, False: 35]
  ------------------
  731|     15|		memset(data, 0x00, 15);
  732|     15|		data[11] = 0x04;
  733|     15|		data[14] = 0x80;
  734|     15|		data[15] = 0x01;
  735|     15|		memcpy(&data[16], g_random, 8);
  736|     15|		memcpy(&data[24], &result[12 + 1], 8);
  737|     35|	} else {
  738|     35|		memcpy(data, &result[16], 4);
  739|     35|		memcpy(&data[4], g_random, 4);
  740|     35|		memcpy(&data[8], &result[12], 4);
  741|     35|		memcpy(&data[12], &g_random[4], 4);
  742|     35|	}
  743|       |
  744|       |	/* Step 2,3 - Create S-ENC/S-MAC Session Key */
  745|     50|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|     50|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (745:6): [True: 25, False: 25]
  ------------------
  746|     25|		if (isFips) {
  ------------------
  |  Branch (746:7): [True: 15, False: 10]
  ------------------
  747|     15|			r = aes128_encrypt_cmac(card, key_enc, 128, data, 32, exdata->sk_enc);
  748|     15|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac enc failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  749|     15|			memset(&data[11], 0x06, 1);
  750|     15|			r = aes128_encrypt_cmac(card, key_mac, 128, data, 32, exdata->sk_mac);
  751|     15|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac mac  failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|     15|		} else {
  753|     10|			r = aes128_encrypt_ecb(card, key_enc, 16, data, 16, exdata->sk_enc);
  754|     10|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_ecb 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  755|     10|			r = aes128_encrypt_ecb(card, key_mac, 16, data, 16, exdata->sk_mac);
  756|     10|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_ecb 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  757|     10|		}
  758|     25|	} else {
  759|     25|		r = des3_encrypt_ecb(card, key_enc, 16, data, 16, exdata->sk_enc);
  760|     25|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_ecb failed");
  ------------------
  |  |  174|     25|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     25|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     25|	int _ret = (r); \
  |  |  |  |  168|     25|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 25]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  761|     25|		r = des3_encrypt_ecb(card, key_mac, 16, data, 16, exdata->sk_mac);
  762|     25|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_ecb failed");
  ------------------
  |  |  174|     25|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     25|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     25|	int _ret = (r); \
  |  |  |  |  168|     25|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     25|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 25]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  763|     25|	}
  764|       |
  765|     50|	if (isFips) {
  ------------------
  |  Branch (765:6): [True: 15, False: 35]
  ------------------
  766|     15|		data[11] = 0x00;
  767|     15|		data[14] = 0x40;
  768|     35|	} else {
  769|     35|		memcpy(data, g_random, 8);
  770|     35|		memcpy(&data[8], &result[12], 8);
  771|     35|		data[16] = 0x80;
  772|     35|		blocksize = (key_type == KEY_TYPE_AES ? 16 : 8);
  ------------------
  |  |   80|     35|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (772:16): [True: 10, False: 25]
  ------------------
  773|     35|		memset(&data[17], 0x00, blocksize - 1);
  774|     35|	}
  775|       |
  776|       |	/* calculate host cryptogram */
  777|     50|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|     50|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (777:6): [True: 25, False: 25]
  ------------------
  778|     25|		if (isFips) {
  ------------------
  |  Branch (778:7): [True: 15, False: 10]
  ------------------
  779|     15|			r = aes128_encrypt_cmac(card, exdata->sk_enc, 128, data, 32, cryptogram);
  780|     15|		} else {
  781|     10|			r = aes128_encrypt_cbc(card, exdata->sk_enc, 16, iv, data, 16 + blocksize, cryptogram);
  782|     10|		}
  783|     25|	} else {
  784|     25|		r = des3_encrypt_cbc(card, exdata->sk_enc, 16, iv, data, 16 + blocksize, cryptogram);
  785|     25|	}
  786|       |
  787|     50|	LOG_TEST_RET(card->ctx, r, "calculate host cryptogram failed");
  ------------------
  |  |  174|     50|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     50|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     50|	int _ret = (r); \
  |  |  |  |  168|     50|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  788|       |
  789|       |	/* verify card cryptogram */
  790|     50|	if (isFips) {
  ------------------
  |  Branch (790:6): [True: 15, False: 35]
  ------------------
  791|     15|		if (0 != memcmp(&cryptogram[0], &result[20+1], 8))
  ------------------
  |  Branch (791:7): [True: 15, False: 0]
  ------------------
  792|     15|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  793|     35|	} else {
  794|     35|		if (0 != memcmp(&cryptogram[16], &result[20], 8))
  ------------------
  |  Branch (794:7): [True: 35, False: 0]
  ------------------
  795|     35|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|     35|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     35|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     35|	int _ret = r; \
  |  |  |  |  155|     35|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 35, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     35|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     35|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 35, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     35|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     35|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     35|	return _ret; \
  |  |  |  |  163|     35|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  796|     35|	}
  797|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  798|      0|}
card-epass2003.c:epass2003_transmit_apdu:
 1722|  1.05k|{
 1723|  1.05k|	int r;
 1724|       |
 1725|  1.05k|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1726|       |
 1727|  1.05k|	r = sc_transmit_apdu_t(card, apdu);
 1728|  1.05k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.05k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.05k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.05k|	int _ret = (r); \
  |  |  |  |  168|  1.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 30, False: 1.02k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1729|       |
 1730|  1.02k|	return r;
 1731|  1.05k|}
card-epass2003.c:sc_transmit_apdu_t:
  276|  2.58k|{
  277|  2.58k|	size_t resplen = apdu->resplen;
  278|  2.58k|	int r = sc_transmit_apdu(card, apdu);
  279|  2.58k|	if ((0x69 == apdu->sw1 && 0x85 == apdu->sw2) || (0x69 == apdu->sw1 && 0x88 == apdu->sw2)) {
  ------------------
  |  Branch (279:7): [True: 61, False: 2.51k]
  |  Branch (279:28): [True: 12, False: 49]
  |  Branch (279:51): [True: 49, False: 2.51k]
  |  Branch (279:72): [True: 17, False: 32]
  ------------------
  280|     29|		epass2003_refresh(card);
  281|       |		/* renew old resplen */
  282|     29|		apdu->resplen = resplen;
  283|     29|		r = sc_transmit_apdu(card, apdu);
  284|     29|	}
  285|  2.58k|	return r;
  286|  2.58k|}
card-epass2003.c:aes128_encrypt_cmac:
  423|     52|{
  424|     52|	size_t mactlen = 0;
  425|     52|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     52|#define SC_ERROR_INTERNAL			-1400
  ------------------
  426|       |#if OPENSSL_VERSION_NUMBER < 0x30000000L
  427|       |	CMAC_CTX *ctx = CMAC_CTX_new();
  428|       |	if (ctx == NULL) {
  429|       |		return SC_ERROR_INTERNAL;
  430|       |	}
  431|       |
  432|       |	if (!CMAC_Init(ctx, key, keysize / 8, EVP_aes_128_cbc(), NULL)) {
  433|       |		goto err;
  434|       |	}
  435|       |	if (!CMAC_Update(ctx, input, length)) {
  436|       |		goto err;
  437|       |	}
  438|       |	if (!CMAC_Final(ctx, output, &mactlen)) {
  439|       |		goto err;
  440|       |	}
  441|       |	r = SC_SUCCESS;
  442|       |err:
  443|       |	CMAC_CTX_free(ctx);
  444|       |#else
  445|     52|	EVP_MAC *mac = EVP_MAC_fetch(card->ctx->ossl3ctx->libctx, "cmac", NULL);
  446|     52|	if (mac == NULL) {
  ------------------
  |  Branch (446:6): [True: 0, False: 52]
  ------------------
  447|      0|		return r;
  448|      0|	}
  449|       |
  450|     52|	OSSL_PARAM params[2] = {0};
  451|     52|	params[0] = OSSL_PARAM_construct_utf8_string("cipher","aes-128-cbc", 0);
  452|     52|	params[1] = OSSL_PARAM_construct_end();
  453|       |
  454|     52|	EVP_MAC_CTX *ctx = EVP_MAC_CTX_new(mac);
  455|     52|	if (ctx == NULL) {
  ------------------
  |  Branch (455:6): [True: 0, False: 52]
  ------------------
  456|      0|		EVP_MAC_CTX_free(ctx);
  457|      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__
  |  |  ------------------
  ------------------
  458|      0|		return r;
  459|      0|	}
  460|     52|	if (!EVP_MAC_init(ctx, (const unsigned char *)key, keysize / 8, params)) {
  ------------------
  |  Branch (460:6): [True: 0, False: 52]
  ------------------
  461|      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__
  |  |  ------------------
  ------------------
  462|      0|		goto err;
  463|      0|	}
  464|     52|	if (!EVP_MAC_update(ctx, input, length)) {
  ------------------
  |  Branch (464:6): [True: 0, False: 52]
  ------------------
  465|      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__
  |  |  ------------------
  ------------------
  466|      0|		goto err;
  467|      0|	}
  468|     52|	if (!EVP_MAC_final(ctx, output, &mactlen, 16)) {
  ------------------
  |  Branch (468:6): [True: 0, False: 52]
  ------------------
  469|      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__
  |  |  ------------------
  ------------------
  470|      0|		goto err;
  471|      0|	}
  472|     52|	r = SC_SUCCESS;
  ------------------
  |  |   28|     52|#define SC_SUCCESS				0
  ------------------
  473|     52|err:
  474|     52|	EVP_MAC_CTX_free(ctx);
  475|     52|	EVP_MAC_free(mac);
  476|     52|#endif
  477|     52|	return r;
  478|     52|}
card-epass2003.c:aes128_encrypt_ecb:
  483|     20|{
  484|     20|	unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
  485|     20|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-ECB");
  ------------------
  |  |  106|     20|#define sc_evp_cipher(ctx, alg) _sc_evp_cipher((ctx)->ossl3ctx, alg)
  ------------------
  486|     20|	int r;
  487|     20|	r = openssl_enc(alg, key, iv, input, length, output);
  488|     20|	sc_evp_cipher_free(alg);
  489|     20|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
  |  Branch (489:6): [True: 0, False: 20]
  ------------------
  490|      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__
  |  |  ------------------
  ------------------
  491|     20|	return r;
  492|     20|}
card-epass2003.c:openssl_enc:
  291|    764|{
  292|    764|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    764|#define SC_ERROR_INTERNAL			-1400
  ------------------
  293|    764|	EVP_CIPHER_CTX * ctx = NULL;
  294|    764|	int outl = 0;
  295|    764|	int outl_tmp = 0;
  296|    764|	unsigned char iv_tmp[EVP_MAX_IV_LENGTH] = {0};
  297|       |
  298|    764|	memcpy(iv_tmp, iv, EVP_MAX_IV_LENGTH);
  299|    764|	ctx = EVP_CIPHER_CTX_new();
  300|    764|	if (ctx == NULL)
  ------------------
  |  Branch (300:6): [True: 0, False: 764]
  ------------------
  301|      0|		goto out;
  302|       |
  303|    764|	if (!EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp) || !EVP_CIPHER_CTX_set_padding(ctx, 0))
  ------------------
  |  Branch (303:6): [True: 0, False: 764]
  |  Branch (303:61): [True: 0, False: 764]
  ------------------
  304|      0|		goto out;
  305|       |
  306|    764|	if (!EVP_EncryptUpdate(ctx, output, &outl, input, (int)length))
  ------------------
  |  Branch (306:6): [True: 0, False: 764]
  ------------------
  307|      0|		goto out;
  308|       |
  309|    764|	if (!EVP_EncryptFinal_ex(ctx, output + outl, &outl_tmp))
  ------------------
  |  Branch (309:6): [True: 0, False: 764]
  ------------------
  310|      0|		goto out;
  311|       |
  312|    764|	r = SC_SUCCESS;
  ------------------
  |  |   28|    764|#define SC_SUCCESS				0
  ------------------
  313|    764|out:
  314|    764|	EVP_CIPHER_CTX_free(ctx);
  315|    764|	return r;
  316|    764|}
card-epass2003.c:des3_encrypt_ecb:
  526|     50|{
  527|     50|	unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
  528|     50|	unsigned char bKey[24] = {0};
  529|     50|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-EDE3");
  ------------------
  |  |  106|     50|#define sc_evp_cipher(ctx, alg) _sc_evp_cipher((ctx)->ossl3ctx, alg)
  ------------------
  530|     50|	int r;
  531|       |
  532|     50|	if (keysize == 16) {
  ------------------
  |  Branch (532:6): [True: 50, False: 0]
  ------------------
  533|     50|		memcpy(&bKey[0], key, 16);
  534|     50|		memcpy(&bKey[16], key, 8);
  535|     50|	} else {
  536|      0|		memcpy(&bKey[0], key, 24);
  537|      0|	}
  538|       |
  539|     50|	r = openssl_enc(alg, bKey, iv, input, length, output);
  540|     50|	sc_evp_cipher_free(alg);
  541|     50|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     50|#define SC_SUCCESS				0
  ------------------
  |  Branch (541:6): [True: 0, False: 50]
  ------------------
  542|      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__
  |  |  ------------------
  ------------------
  543|     50|	return r;
  544|     50|}
card-epass2003.c:aes128_encrypt_cbc:
  498|     34|{
  499|     34|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-CBC");
  ------------------
  |  |  106|     34|#define sc_evp_cipher(ctx, alg) _sc_evp_cipher((ctx)->ossl3ctx, alg)
  ------------------
  500|     34|	int r;
  501|     34|	r = openssl_enc(alg, key, iv, input, length, output);
  502|     34|	sc_evp_cipher_free(alg);
  503|     34|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
  |  Branch (503:6): [True: 0, False: 34]
  ------------------
  504|      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__
  |  |  ------------------
  ------------------
  505|     34|	return r;
  506|     34|}
card-epass2003.c:des3_encrypt_cbc:
  550|    222|{
  551|    222|	unsigned char bKey[24] = {0};
  552|    222|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-EDE3-CBC");
  ------------------
  |  |  106|    222|#define sc_evp_cipher(ctx, alg) _sc_evp_cipher((ctx)->ossl3ctx, alg)
  ------------------
  553|    222|	int r;
  554|       |
  555|    222|	if (keysize == 16) {
  ------------------
  |  Branch (555:6): [True: 222, False: 0]
  ------------------
  556|    222|		memcpy(&bKey[0], key, 16);
  557|    222|		memcpy(&bKey[16], key, 8);
  558|    222|	} else {
  559|      0|		memcpy(&bKey[0], key, 24);
  560|      0|	}
  561|       |
  562|    222|	r = openssl_enc(EVP_des_ede3_cbc(), bKey, iv, input, length, output);
  563|    222|	sc_evp_cipher_free(alg);
  564|    222|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    222|#define SC_SUCCESS				0
  ------------------
  |  Branch (564:6): [True: 0, False: 222]
  ------------------
  565|      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__
  |  |  ------------------
  ------------------
  566|    222|	return r;
  567|    222|}
card-epass2003.c:sc_get_driver:
 3558|  16.1k|{
 3559|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3560|       |
 3561|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (3561:6): [True: 1, False: 16.1k]
  ------------------
 3562|      1|		iso_ops = iso_drv->ops;
 3563|       |
 3564|  16.1k|	epass2003_ops = *iso_ops;
 3565|       |
 3566|  16.1k|	epass2003_ops.match_card = epass2003_match_card;
 3567|  16.1k|	epass2003_ops.init = epass2003_init;
 3568|  16.1k|	epass2003_ops.finish = epass2003_finish;
 3569|  16.1k|	epass2003_ops.write_binary = NULL;
 3570|  16.1k|	epass2003_ops.write_record = NULL;
 3571|  16.1k|	epass2003_ops.select_file = epass2003_select_file;
 3572|       |	epass2003_ops.get_response = NULL;
 3573|  16.1k|	epass2003_ops.restore_security_env = epass2003_restore_security_env;
 3574|  16.1k|	epass2003_ops.set_security_env = epass2003_set_security_env;
 3575|  16.1k|	epass2003_ops.decipher = epass2003_decipher;
 3576|  16.1k|	epass2003_ops.compute_signature = epass2003_decipher;
 3577|  16.1k|	epass2003_ops.create_file = epass2003_create_file;
 3578|  16.1k|	epass2003_ops.delete_file = epass2003_delete_file;
 3579|  16.1k|	epass2003_ops.list_files = epass2003_list_files;
 3580|  16.1k|	epass2003_ops.card_ctl = epass2003_card_ctl;
 3581|  16.1k|	epass2003_ops.process_fci = epass2003_process_fci;
 3582|  16.1k|	epass2003_ops.construct_fci = epass2003_construct_fci;
 3583|  16.1k|	epass2003_ops.pin_cmd = epass2003_pin_cmd;
 3584|  16.1k|	epass2003_ops.check_sw = epass2003_check_sw;
 3585|  16.1k|	epass2003_ops.get_challenge = epass2003_get_challenge;
 3586|  16.1k|	epass2003_ops.logout = epass2003_logout;
 3587|  16.1k|	epass2003_ops.card_reader_lock_obtained = epass2003_card_reader_lock_obtained;
 3588|  16.1k|	return &epass2003_drv;
 3589|  16.1k|}
card-epass2003.c:epass2003_match_card:
 1774|  9.61k|{
 1775|  9.61k|	int r;
 1776|       |
 1777|  9.61k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  9.61k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.61k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.61k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.61k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.61k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1778|  9.61k|	r = _sc_match_atr(card, epass2003_atrs, &card->type);
 1779|  9.61k|	if (r < 0)
  ------------------
  |  Branch (1779:6): [True: 9.09k, False: 522]
  ------------------
 1780|  9.09k|		return 0;
 1781|       |
 1782|    522|	return 1;
 1783|  9.61k|}
card-epass2003.c:epass2003_init:
 1788|    522|{
 1789|    522|	unsigned int flags;
 1790|    522|	unsigned int ext_flags;
 1791|    522|	unsigned char data[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1792|    522|	size_t datalen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    522|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1793|    522|	epass2003_exdata *exdata = NULL;
 1794|    522|	void *old_drv_data = card->drv_data;
 1795|       |
 1796|    522|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    522|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    522|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    522|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    522|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 522]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1797|       |
 1798|    522|	card->name = "epass2003";
 1799|    522|	card->cla = 0x00;
 1800|    522|	exdata = (epass2003_exdata *)calloc(1, sizeof(epass2003_exdata));
 1801|    522|	if (!exdata)
  ------------------
  |  Branch (1801:6): [True: 0, False: 522]
  ------------------
 1802|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1803|       |
 1804|    522|	card->drv_data = exdata;
 1805|       |
 1806|    522|	exdata->sm = SM_SCP01;
  ------------------
  |  |   92|    522|#define SM_SCP01				0x01
  ------------------
 1807|       |
 1808|       |	/* decide FIPS/Non-FIPS mode */
 1809|    522|	if (SC_SUCCESS != get_data(card, 0x86, data, datalen)) {
  ------------------
  |  |   28|    522|#define SC_SUCCESS				0
  ------------------
  |  Branch (1809:6): [True: 12, False: 510]
  ------------------
 1810|     12|		free(exdata);
 1811|     12|		card->drv_data = old_drv_data;
 1812|     12|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     12|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1813|     12|	}
 1814|       |
 1815|    510|	if (memcmp(&data[32], "\x87\x01\x01", 3) == 0 && memcmp(&data[0], "\x80\x01\x01", 3) == 0) {
  ------------------
  |  Branch (1815:6): [True: 9, False: 501]
  |  Branch (1815:51): [True: 7, False: 2]
  ------------------
 1816|      7|		exdata->bFipsCertification = 0x01;
 1817|    503|	} else {
 1818|    503|		exdata->bFipsCertification = 0x00;
 1819|    503|	}
 1820|       |
 1821|    510|	if (0x01 == data[2])
  ------------------
  |  Branch (1821:6): [True: 77, False: 433]
  ------------------
 1822|     77|		exdata->smtype = KEY_TYPE_AES;
  ------------------
  |  |   80|     77|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
 1823|    433|	else
 1824|    433|		exdata->smtype = KEY_TYPE_DES;
  ------------------
  |  |   81|    433|#define KEY_TYPE_DES	0x02	/* Non-FIPS mode */
  ------------------
 1825|       |
 1826|    510|	if (0x84 == data[14]) {
  ------------------
  |  Branch (1826:6): [True: 304, False: 206]
  ------------------
 1827|    304|		if (0x00 == data[16]) {
  ------------------
  |  Branch (1827:7): [True: 299, False: 5]
  ------------------
 1828|    299|			exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|    299|#define SM_PLAIN				0x00
  ------------------
 1829|    299|		}
 1830|    304|	}
 1831|       |
 1832|       |	/* mutual authentication */
 1833|    510|	card->max_recv_size = 0xD8;
 1834|    510|	card->max_send_size = 0xE8;
 1835|       |
 1836|    510|	card->sm_ctx.ops.open = epass2003_refresh;
 1837|    510|	card->sm_ctx.ops.get_sm_apdu = epass2003_sm_get_wrapped_apdu;
 1838|    510|	card->sm_ctx.ops.free_sm_apdu = epass2003_sm_free_wrapped_apdu;
 1839|       |
 1840|       |	/* FIXME (VT): rather then set/unset 'g_sm', better to implement filter for APDUs to be wrapped */
 1841|    510|	epass2003_refresh(card);
 1842|       |
 1843|    510|	card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|    510|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1844|       |
 1845|    510|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |   93|    510|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    510|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    510|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1846|       |
 1847|    510|	_sc_card_add_rsa_alg(card, 512, flags, 0);
 1848|    510|	_sc_card_add_rsa_alg(card, 768, flags, 0);
 1849|    510|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1850|    510|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1851|       |
 1852|       |	//set EC Alg Flags
 1853|    510|	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|    510|#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|    510|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    510|#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|    510|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    510|#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|    510|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    510|#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|    510|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1854|    510|	ext_flags = 0;
 1855|    510|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1856|       |
 1857|    510|	card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  550|    510|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    510|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
 1858|       |
 1859|    510|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    510|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    510|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    510|	int _ret = r; \
  |  |  |  |  155|    510|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 510, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    510|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 510]
  |  |  |  |  ------------------
  |  |  |  |  157|    510|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    510|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    510|	return _ret; \
  |  |  |  |  163|    510|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1860|    510|}
card-epass2003.c:get_data:
 1736|    541|{
 1737|    541|	int r;
 1738|    541|	struct sc_apdu apdu;
 1739|    541|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1740|    541|	size_t resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    541|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1741|    541|	epass2003_exdata *exdata = NULL;
 1742|       |
 1743|    541|	if (!card->drv_data)
  ------------------
  |  Branch (1743:6): [True: 0, False: 541]
  ------------------
 1744|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1745|       |
 1746|    541|	exdata = (epass2003_exdata *)card->drv_data;
 1747|       |
 1748|    541|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    541|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    541|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    541|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    541|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 541]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1749|       |
 1750|    541|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, type);
  ------------------
  |  |  292|    541|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1751|    541|	apdu.resp = resp;
 1752|    541|	apdu.le = 0;
 1753|    541|	apdu.resplen = resplen;
 1754|    541|	if (0x86 == type) {
  ------------------
  |  Branch (1754:6): [True: 522, False: 19]
  ------------------
 1755|       |		/* No SM temporarily */
 1756|    522|		unsigned char tmp_sm = exdata->sm;
 1757|    522|		exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|    522|#define SM_PLAIN				0x00
  ------------------
 1758|    522|		r = sc_transmit_apdu(card, &apdu);
 1759|    522|		exdata->sm = tmp_sm;
 1760|    522|	} else {
 1761|     19|		r = sc_transmit_apdu_t(card, &apdu);
 1762|     19|	}
 1763|    541|	LOG_TEST_RET(card->ctx, r, "APDU get_data failed");
  ------------------
  |  |  174|    541|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    541|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    541|	int _ret = (r); \
  |  |  |  |  168|    541|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 540]
  |  |  |  |  ------------------
  |  |  |  |  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|    541|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 540]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1764|    540|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1765|    540|	LOG_TEST_RET(card->ctx, r, "get_data failed");
  ------------------
  |  |  174|    540|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    540|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    540|	int _ret = (r); \
  |  |  |  |  168|    540|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 511]
  |  |  |  |  ------------------
  |  |  |  |  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|    540|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 511]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1766|       |
 1767|    511|	memcpy(data, resp, datalen);
 1768|    511|	return r;
 1769|    540|}
card-epass2003.c:epass2003_sm_get_wrapped_apdu:
 1665|  2.63k|{
 1666|  2.63k|	struct sc_context *ctx = card->ctx;
 1667|  2.63k|	struct sc_apdu *apdu = NULL;
 1668|  2.63k|	int rv;
 1669|       |
 1670|  2.63k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.63k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.63k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1671|  2.63k|	if (!plain || !sm_apdu)
  ------------------
  |  Branch (1671:6): [True: 0, False: 2.63k]
  |  Branch (1671:16): [True: 0, False: 2.63k]
  ------------------
 1672|  2.63k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1673|       |
 1674|       |	/* A command rejected with 6988 has not been executed and can be sent again in a new
 1675|       |	 * session, except EXTERNAL AUTHENTICATE: its cryptogram is computed over the preceding
 1676|       |	 * GET CHALLENGE, which re-establishing secure messaging does not preserve. */
 1677|  2.63k|	if (plain->ins != 0x82)
  ------------------
  |  Branch (1677:6): [True: 2.63k, False: 8]
  ------------------
 1678|  2.63k|		plain->flags |= SC_APDU_FLAGS_RETRY_WITH_SM_OPEN;
  ------------------
  |  |  317|  2.63k|#define SC_APDU_FLAGS_RETRY_WITH_SM_OPEN 0x00000020UL
  ------------------
 1679|       |
 1680|  2.63k|	*sm_apdu = NULL;
 1681|       |	//construct new SM apdu from original apdu
 1682|  2.63k|	apdu = calloc(1, sizeof(struct sc_apdu));
 1683|  2.63k|	if (!apdu) {
  ------------------
  |  Branch (1683:6): [True: 0, False: 2.63k]
  ------------------
 1684|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1685|      0|		goto err;
 1686|      0|	}
 1687|  2.63k|	apdu->data = calloc (1, SC_MAX_EXT_APDU_BUFFER_SIZE);
  ------------------
  |  |   37|  2.63k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1688|  2.63k|	if (!apdu->data) {
  ------------------
  |  Branch (1688:6): [True: 0, False: 2.63k]
  ------------------
 1689|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1690|      0|		goto err;
 1691|      0|	}
 1692|  2.63k|	apdu->resp = calloc (1, SC_MAX_EXT_APDU_BUFFER_SIZE);
  ------------------
  |  |   37|  2.63k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1693|  2.63k|	if (!apdu->resp) {
  ------------------
  |  Branch (1693:6): [True: 0, False: 2.63k]
  ------------------
 1694|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1695|      0|		goto err;
 1696|      0|	}
 1697|  2.63k|	apdu->datalen = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|  2.63k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1698|  2.63k|	apdu->resplen = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|  2.63k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1699|       |
 1700|  2.63k|	rv = epass2003_sm_wrap_apdu(card, plain, apdu);
 1701|  2.63k|	if (rv) {
  ------------------
  |  Branch (1701:6): [True: 0, False: 2.63k]
  ------------------
 1702|      0|		rv = epass2003_sm_free_wrapped_apdu(card, NULL, &apdu);
 1703|      0|		if (rv < 0)
  ------------------
  |  Branch (1703:7): [True: 0, False: 0]
  ------------------
 1704|      0|			goto err;
 1705|      0|	}
 1706|       |
 1707|  2.63k|	*sm_apdu = apdu;
 1708|  2.63k|	apdu = NULL;
 1709|  2.63k|err:
 1710|  2.63k|	if (apdu) {
  ------------------
  |  Branch (1710:6): [True: 0, False: 2.63k]
  ------------------
 1711|      0|		free((unsigned char *) apdu->data);
 1712|      0|		free(apdu->resp);
 1713|      0|		free(apdu);
 1714|      0|		apdu = NULL;
 1715|      0|	}
 1716|  2.63k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.63k|	int _ret = r; \
  |  |  |  |  155|  2.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.63k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.63k|	return _ret; \
  |  |  |  |  163|  2.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1717|  2.63k|}
card-epass2003.c:epass2003_sm_wrap_apdu:
 1324|  2.63k|{
 1325|  2.63k|	unsigned char buf[4096] = {0}; /* APDU buffer */
 1326|  2.63k|	size_t buf_len = sizeof(buf);
 1327|  2.63k|	epass2003_exdata *exdata = NULL;
 1328|       |
 1329|  2.63k|	if (!card->drv_data)
  ------------------
  |  Branch (1329:6): [True: 0, False: 2.63k]
  ------------------
 1330|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1331|       |
 1332|  2.63k|	exdata = (epass2003_exdata *)card->drv_data;
 1333|       |
 1334|  2.63k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.63k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.63k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1335|       |
 1336|  2.63k|	if (exdata->sm)
  ------------------
  |  Branch (1336:6): [True: 212, False: 2.42k]
  ------------------
 1337|    212|		plain->cla |= 0x0C;
 1338|       |
 1339|  2.63k|	sm->cse = plain->cse;
 1340|  2.63k|	sm->cla = plain->cla;
 1341|  2.63k|	sm->ins = plain->ins;
 1342|  2.63k|	sm->p1 = plain->p1;
 1343|  2.63k|	sm->p2 = plain->p2;
 1344|  2.63k|	sm->lc = plain->lc;
 1345|  2.63k|	sm->le = plain->le;
 1346|  2.63k|	sm->control = plain->control;
 1347|  2.63k|	sm->flags = plain->flags;
 1348|       |
 1349|  2.63k|	switch (sm->cla & 0x0C) {
 1350|  2.42k|	case 0x00:
  ------------------
  |  Branch (1350:2): [True: 2.42k, False: 212]
  ------------------
 1351|  2.42k|	case 0x04:
  ------------------
  |  Branch (1351:2): [True: 0, False: 2.63k]
  ------------------
 1352|  2.42k|		sm->datalen = plain->datalen;
 1353|  2.42k|		memcpy((void *)sm->data, plain->data, plain->datalen);
 1354|  2.42k|		sm->resplen = plain->resplen;
 1355|  2.42k|		memcpy(sm->resp, plain->resp, plain->resplen);
 1356|  2.42k|		break;
 1357|    212|	case 0x0C:
  ------------------
  |  Branch (1357:2): [True: 212, False: 2.42k]
  ------------------
 1358|    212|		memset(buf, 0, sizeof(buf));
 1359|    212|		if (0 != encode_apdu(card, plain, sm, buf, &buf_len))
  ------------------
  |  Branch (1359:7): [True: 0, False: 212]
  ------------------
 1360|      0|			return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      0|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1361|    212|		break;
 1362|    212|	default:
  ------------------
  |  Branch (1362:2): [True: 0, False: 2.63k]
  ------------------
 1363|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
 1364|  2.63k|	}
 1365|       |
 1366|  2.63k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.63k|#define SC_SUCCESS				0
  ------------------
 1367|  2.63k|}
card-epass2003.c:encode_apdu:
 1227|    212|{
 1228|    212|	size_t block_size = 0;
 1229|    212|	unsigned char dataTLV[4096] = {0};
 1230|    212|	size_t data_tlv_len = 0;
 1231|    212|	unsigned char le_tlv[256] = {0};
 1232|    212|	size_t le_tlv_len = 0;
 1233|    212|	size_t mac_tlv_len = 10;
 1234|    212|	size_t tmp_lc = 0;
 1235|    212|	size_t tmp_le = 0;
 1236|    212|	size_t expected_total_len;
 1237|    212|	unsigned char mac_tlv[256] = {0};
 1238|    212|	epass2003_exdata *exdata = NULL;
 1239|       |
 1240|    212|	mac_tlv[0] = 0x8E;
 1241|    212|	mac_tlv[1] = 8;
 1242|       |	/* size_t plain_le = 0; */
 1243|    212|	if (!card->drv_data)
  ------------------
  |  Branch (1243:6): [True: 0, False: 212]
  ------------------
 1244|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1245|    212|	exdata = (epass2003_exdata*)card->drv_data;
 1246|    212|	block_size = (KEY_TYPE_DES == exdata->smtype ? 16 : 8);
  ------------------
  |  |   81|    212|#define KEY_TYPE_DES	0x02	/* Non-FIPS mode */
  ------------------
  |  Branch (1246:16): [True: 197, False: 15]
  ------------------
 1247|       |
 1248|    212|	sm->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|    212|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1249|    212|	apdu_buf[0] = (unsigned char)plain->cla;
 1250|    212|	apdu_buf[1] = (unsigned char)plain->ins;
 1251|    212|	apdu_buf[2] = (unsigned char)plain->p1;
 1252|    212|	apdu_buf[3] = (unsigned char)plain->p2;
 1253|       |	/* plain_le = plain->le; */
 1254|       |	/* padding */
 1255|    212|	if (exdata->bFipsCertification && plain->lc == 0 && apdu_buf[1] == 0x82 && apdu_buf[2] == 0x01) {
  ------------------
  |  Branch (1255:6): [True: 7, False: 205]
  |  Branch (1255:36): [True: 0, False: 7]
  |  Branch (1255:54): [True: 0, False: 0]
  |  Branch (1255:77): [True: 0, False: 0]
  ------------------
 1256|      0|		apdu_buf[4] = 0x00;
 1257|    212|	} else {
 1258|    212|		apdu_buf[4] = 0x80;
 1259|    212|	}
 1260|    212|	memset(&apdu_buf[5], 0x00, block_size - 5);
 1261|       |
 1262|       |	/* Data -> Data' */
 1263|    212|	if (plain->lc != 0)
  ------------------
  |  Branch (1263:6): [True: 212, False: 0]
  ------------------
 1264|    212|		if (0 != construct_data_tlv(card, plain, apdu_buf, dataTLV, &data_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1264:7): [True: 0, False: 212]
  ------------------
 1265|      0|			return -1;
 1266|       |
 1267|    212|	if (plain->le != 0 || (plain->le == 0 && plain->resplen != 0))
  ------------------
  |  Branch (1267:6): [True: 0, False: 212]
  |  Branch (1267:25): [True: 212, False: 0]
  |  Branch (1267:43): [True: 212, False: 0]
  ------------------
 1268|    212|		if (0 != construct_le_tlv(plain, apdu_buf, data_tlv_len, le_tlv,
  ------------------
  |  Branch (1268:7): [True: 0, False: 212]
  ------------------
 1269|    212|				     &le_tlv_len, exdata->smtype))
 1270|      0|			return -1;
 1271|       |
 1272|    212|	if (exdata->bFipsCertification && plain->lc == 0 && apdu_buf[1] == 0x82 && apdu_buf[2] == 0x01) {
  ------------------
  |  Branch (1272:6): [True: 7, False: 205]
  |  Branch (1272:36): [True: 0, False: 7]
  |  Branch (1272:54): [True: 0, False: 0]
  |  Branch (1272:77): [True: 0, False: 0]
  ------------------
 1273|      0|		if (0 != construct_mac_tlv_case1(card, apdu_buf, data_tlv_len, le_tlv_len, mac_tlv, &mac_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1273:7): [True: 0, False: 0]
  ------------------
 1274|      0|			return -1;
 1275|    212|	} else {
 1276|    212|		if (0 != construct_mac_tlv(card, apdu_buf, data_tlv_len, le_tlv_len, mac_tlv, &mac_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1276:7): [True: 0, False: 212]
  ------------------
 1277|      0|			return -1;
 1278|    212|	}
 1279|       |
 1280|    212|	memset(apdu_buf + 4, 0, *apdu_buf_len - 4);
 1281|    212|	sm->lc = sm->datalen = data_tlv_len + le_tlv_len + mac_tlv_len;
 1282|    212|	if (sm->lc > 0xFF) {
  ------------------
  |  Branch (1282:6): [True: 0, False: 212]
  ------------------
 1283|      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
  |  |  ------------------
  ------------------
 1284|      0|		apdu_buf[4] = (unsigned char)((sm->lc) / 0x10000);
 1285|      0|		apdu_buf[5] = (unsigned char)(((sm->lc) / 0x100) % 0x100);
 1286|      0|		apdu_buf[6] = (unsigned char)((sm->lc) % 0x100);
 1287|      0|		tmp_lc = 3;
 1288|    212|	} else {
 1289|    212|		apdu_buf[4] = (unsigned char)sm->lc;
 1290|    212|		tmp_lc = 1;
 1291|    212|	}
 1292|       |
 1293|       |	/* 2 is for Le extension in the worst case */
 1294|    212|	expected_total_len = 4 + tmp_lc + data_tlv_len + le_tlv_len + mac_tlv_len + 2;
 1295|       |
 1296|    212|	if (expected_total_len > *apdu_buf_len) {
  ------------------
  |  Branch (1296:6): [True: 0, False: 212]
  ------------------
 1297|      0|	    return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1298|      0|	}
 1299|       |
 1300|    212|	memcpy(apdu_buf + 4 + tmp_lc, dataTLV, data_tlv_len);
 1301|    212|	memcpy(apdu_buf + 4 + tmp_lc + data_tlv_len, le_tlv, le_tlv_len);
 1302|    212|	memcpy(apdu_buf + 4 + tmp_lc + data_tlv_len + le_tlv_len, mac_tlv, mac_tlv_len);
 1303|    212|	memcpy((unsigned char *)sm->data, apdu_buf + 4 + tmp_lc, sm->datalen);
 1304|    212|	*apdu_buf_len = 0;
 1305|       |
 1306|    212|	if (4 == le_tlv_len) {
  ------------------
  |  Branch (1306:6): [True: 0, False: 212]
  ------------------
 1307|      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
  |  |  ------------------
  ------------------
 1308|      0|		*(apdu_buf + 4 + tmp_lc + sm->lc) = (unsigned char)(plain->le / 0x100);
 1309|      0|		*(apdu_buf + 4 + tmp_lc + sm->lc + 1) = (unsigned char)(plain->le % 0x100);
 1310|      0|		tmp_le = 2;
 1311|    212|	} else if (3 == le_tlv_len) {
  ------------------
  |  Branch (1311:13): [True: 212, False: 0]
  ------------------
 1312|    212|		*(apdu_buf + 4 + tmp_lc + sm->lc) = (unsigned char)plain->le;
 1313|    212|		tmp_le = 1;
 1314|    212|	}
 1315|       |
 1316|    212|	*apdu_buf_len += 4 + tmp_lc + data_tlv_len + le_tlv_len + mac_tlv_len + tmp_le;
 1317|       |	/* sm->le = calc_le(plain_le); */
 1318|    212|	return 0;
 1319|    212|}
card-epass2003.c:construct_data_tlv:
  975|    212|{
  976|    212|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    212|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (976:23): [True: 15, False: 197]
  ------------------
  977|    212|	unsigned char pad[4096] = {0};
  978|    212|	size_t pad_len;
  979|    212|	size_t tlv_more;	/* increased tlv length */
  980|    212|	unsigned char iv[16] = {0};
  981|    212|	epass2003_exdata *exdata = NULL;
  982|    212|	int r = 0;
  983|       |
  984|    212|	if (!card->drv_data)
  ------------------
  |  Branch (984:6): [True: 0, False: 212]
  ------------------
  985|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  986|       |
  987|    212|	exdata = (epass2003_exdata *)card->drv_data;
  988|       |
  989|       |	/* we encrypt the pad buffer and then write it to the apdu_buf at offset block_size + tlv_more */
  990|    212|	if (apdu->lc >= sizeof(pad) - block_size - 5)
  ------------------
  |  Branch (990:6): [True: 0, False: 212]
  ------------------
  991|    212|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  992|    212|				"ePass2003 secure messaging APDU data too large");
  993|       |
  994|       |	/* padding */
  995|    212|	apdu_buf[block_size] = 0x87;
  996|    212|	memcpy(pad, apdu->data, apdu->lc);
  997|    212|	pad[apdu->lc] = 0x80;
  998|    212|	if ((apdu->lc + 1) % block_size)
  ------------------
  |  Branch (998:6): [True: 212, False: 0]
  ------------------
  999|    212|		pad_len = ((apdu->lc + 1) / block_size + 1) * block_size;
 1000|      0|	else
 1001|      0|		pad_len = apdu->lc + 1;
 1002|       |
 1003|       |	/* encode Lc' */
 1004|    212|	if (pad_len > 0x7E) {
  ------------------
  |  Branch (1004:6): [True: 0, False: 212]
  ------------------
 1005|       |		/* Lc' > 0x7E, use extended APDU */
 1006|      0|		apdu_buf[block_size + 1] = 0x82;
 1007|      0|		apdu_buf[block_size + 2] = (unsigned char)((pad_len + 1) / 0x100);
 1008|      0|		apdu_buf[block_size + 3] = (unsigned char)((pad_len + 1) % 0x100);
 1009|      0|		apdu_buf[block_size + 4] = 0x01;
 1010|      0|		tlv_more = 5;
 1011|    212|	} else {
 1012|    212|		apdu_buf[block_size + 1] = (unsigned char)pad_len + 1;
 1013|    212|		apdu_buf[block_size + 2] = 0x01;
 1014|    212|		tlv_more = 3;
 1015|    212|	}
 1016|    212|	memcpy(data_tlv, &apdu_buf[block_size], tlv_more);
 1017|       |
 1018|       |	/* encrypt Data */
 1019|    212|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|    212|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1019:6): [True: 15, False: 197]
  ------------------
 1020|     15|		r = aes128_encrypt_cbc(card, exdata->sk_enc, 16, iv, pad, pad_len, apdu_buf + block_size + tlv_more);
 1021|     15|		LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cbc failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1022|    197|	} else {
 1023|    197|		r = des3_encrypt_cbc(card, exdata->sk_enc, 16, iv, pad, pad_len, apdu_buf + block_size + tlv_more);
 1024|    197|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_cbc 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|    197|	}
 1026|       |
 1027|    212|	memcpy(data_tlv + tlv_more, apdu_buf + block_size + tlv_more, pad_len);
 1028|    212|	*data_tlv_len = tlv_more + pad_len;
 1029|    212|	return 0;
 1030|    212|}
card-epass2003.c:construct_le_tlv:
 1037|    212|{
 1038|    212|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    212|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1038:23): [True: 15, False: 197]
  ------------------
 1039|       |
 1040|    212|	*(apdu_buf + block_size + data_tlv_len) = 0x97;
 1041|    212|	if (apdu->le > 0x7F) {
  ------------------
  |  Branch (1041:6): [True: 0, False: 212]
  ------------------
 1042|       |		/* Le' > 0x7E, use extended APDU */
 1043|      0|		*(apdu_buf + block_size + data_tlv_len + 1) = 2;
 1044|      0|		*(apdu_buf + block_size + data_tlv_len + 2) = (unsigned char)(apdu->le / 0x100);
 1045|      0|		*(apdu_buf + block_size + data_tlv_len + 3) = (unsigned char)(apdu->le % 0x100);
 1046|      0|		memcpy(le_tlv, apdu_buf + block_size + data_tlv_len, 4);
 1047|      0|		*le_tlv_len = 4;
 1048|    212|	} else {
 1049|    212|		*(apdu_buf + block_size + data_tlv_len + 1) = 1;
 1050|    212|		*(apdu_buf + block_size + data_tlv_len + 2) = (unsigned char)apdu->le;
 1051|    212|		memcpy(le_tlv, apdu_buf + block_size + data_tlv_len, 3);
 1052|    212|		*le_tlv_len = 3;
 1053|    212|	}
 1054|    212|	return 0;
 1055|    212|}
card-epass2003.c:des_encrypt_cbc:
  596|    438|{
  597|    438|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-CBC");
  ------------------
  |  |  106|    438|#define sc_evp_cipher(ctx, alg) _sc_evp_cipher((ctx)->ossl3ctx, alg)
  ------------------
  598|    438|	int r;
  599|       |
  600|    438|	r = openssl_enc(alg, key, iv, input, length, output);
  601|    438|	sc_evp_cipher_free(alg);
  602|    438|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    438|#define SC_SUCCESS				0
  ------------------
  |  Branch (602:6): [True: 0, False: 438]
  ------------------
  603|      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__
  |  |  ------------------
  ------------------
  604|    438|	return r;
  605|    438|}
card-epass2003.c:des_decrypt_cbc:
  611|    219|{
  612|    219|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-CBC");
  ------------------
  |  |  106|    219|#define sc_evp_cipher(ctx, alg) _sc_evp_cipher((ctx)->ossl3ctx, alg)
  ------------------
  613|    219|	int r;
  614|       |
  615|    219|	r = openssl_dec(alg, key, iv, input, length, output);
  616|    219|	sc_evp_cipher_free(alg);
  617|    219|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    219|#define SC_SUCCESS				0
  ------------------
  |  Branch (617:6): [True: 0, False: 219]
  ------------------
  618|      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__
  |  |  ------------------
  ------------------
  619|    219|	return r;
  620|    219|}
card-epass2003.c:openssl_dec:
  321|    219|{
  322|    219|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    219|#define SC_ERROR_INTERNAL			-1400
  ------------------
  323|    219|	EVP_CIPHER_CTX * ctx = NULL;
  324|    219|	int outl = 0;
  325|    219|	int outl_tmp = 0;
  326|    219|	unsigned char iv_tmp[EVP_MAX_IV_LENGTH] = {0};
  327|       |
  328|    219|	memcpy(iv_tmp, iv, EVP_MAX_IV_LENGTH);
  329|    219|	ctx = EVP_CIPHER_CTX_new();
  330|    219|	if (ctx == NULL)
  ------------------
  |  Branch (330:6): [True: 0, False: 219]
  ------------------
  331|      0|		goto out;
  332|       |
  333|    219|	if (!EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
  ------------------
  |  Branch (333:6): [True: 0, False: 219]
  ------------------
  334|    219|			!EVP_CIPHER_CTX_set_padding(ctx, 0))
  ------------------
  |  Branch (334:4): [True: 0, False: 219]
  ------------------
  335|      0|		goto out;
  336|       |
  337|    219|	if (!EVP_DecryptUpdate(ctx, output, &outl, input, (int)length))
  ------------------
  |  Branch (337:6): [True: 0, False: 219]
  ------------------
  338|      0|		goto out;
  339|       |
  340|    219|	if (!EVP_DecryptFinal_ex(ctx, output + outl, &outl_tmp))
  ------------------
  |  Branch (340:6): [True: 0, False: 219]
  ------------------
  341|      0|		goto out;
  342|       |
  343|    219|	r = SC_SUCCESS;
  ------------------
  |  |   28|    219|#define SC_SUCCESS				0
  ------------------
  344|    219|out:
  345|    219|	EVP_CIPHER_CTX_free(ctx);
  346|    219|	return r;
  347|    219|}
card-epass2003.c:construct_mac_tlv:
 1062|    212|{
 1063|    212|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    212|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1063:23): [True: 15, False: 197]
  ------------------
 1064|    212|	unsigned char mac[4096] = {0};
 1065|    212|	size_t mac_len;
 1066|    212|	unsigned char icv[16] = {0};
 1067|    212|	int r ;
 1068|    212|	int i = (KEY_TYPE_AES == key_type ? 15 : 7);
  ------------------
  |  |   80|    212|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1068:11): [True: 15, False: 197]
  ------------------
 1069|    212|	epass2003_exdata *exdata = NULL;
 1070|       |
 1071|    212|	if (!card->drv_data)
  ------------------
  |  Branch (1071:6): [True: 0, False: 212]
  ------------------
 1072|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1073|       |
 1074|    212|	exdata = (epass2003_exdata *)card->drv_data;
 1075|       |
 1076|    212|	if (data_tlv_len + le_tlv_len + block_size + 1 > sizeof(mac)) {
  ------------------
  |  Branch (1076:6): [True: 0, False: 212]
  ------------------
 1077|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1078|      0|	}
 1079|       |
 1080|    212|	if (0 == data_tlv_len && 0 == le_tlv_len) {
  ------------------
  |  Branch (1080:6): [True: 0, False: 212]
  |  Branch (1080:27): [True: 0, False: 0]
  ------------------
 1081|      0|		mac_len = block_size;
 1082|    212|	} else {
 1083|       |		/* padding */
 1084|    212|		*(apdu_buf + block_size + data_tlv_len + le_tlv_len) = 0x80;
 1085|    212|		if ((data_tlv_len + le_tlv_len + 1) % block_size) {
  ------------------
  |  Branch (1085:7): [True: 212, False: 0]
  ------------------
 1086|    212|			mac_len = (((data_tlv_len + le_tlv_len + 1) / block_size) +
 1087|    212|					1) * block_size + block_size;
 1088|    212|		} else {
 1089|      0|			mac_len = data_tlv_len + le_tlv_len + 1 + block_size;
 1090|      0|		}
 1091|    212|		memset((apdu_buf + block_size + data_tlv_len + le_tlv_len + 1),
 1092|    212|		       0, (mac_len - (data_tlv_len + le_tlv_len + 1)));
 1093|    212|	}
 1094|       |
 1095|       |	/* increase icv */
 1096|    212|	for (; i >= 0; i--) {
  ------------------
  |  Branch (1096:9): [True: 212, False: 0]
  ------------------
 1097|    212|		if (exdata->icv_mac[i] == 0xff) {
  ------------------
  |  Branch (1097:7): [True: 0, False: 212]
  ------------------
 1098|      0|			exdata->icv_mac[i] = 0;
 1099|    212|		} else {
 1100|    212|			exdata->icv_mac[i]++;
 1101|    212|			break;
 1102|    212|		}
 1103|    212|	}
 1104|       |
 1105|       |	/* calculate MAC */
 1106|    212|	memset(icv, 0, sizeof(icv));
 1107|    212|	memcpy(icv, exdata->icv_mac, 16);
 1108|    212|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|    212|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1108:6): [True: 15, False: 197]
  ------------------
 1109|     15|		if (exdata->bFipsCertification) {
  ------------------
  |  Branch (1109:7): [True: 7, False: 8]
  ------------------
 1110|    119|			for (int i = 0; i < 16; i++) {
  ------------------
  |  Branch (1110:20): [True: 112, False: 7]
  ------------------
 1111|    112|				apdu_buf[i] = apdu_buf[i] ^ icv[i];
 1112|    112|			}
 1113|      7|			r = aes128_encrypt_cmac(card, exdata->sk_mac, 128, apdu_buf, data_tlv_len + le_tlv_len + block_size, mac);
 1114|      7|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac failed");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|      7|			memcpy(mac_tlv + 2, &mac[0 /*ulmacLen-16*/], 8);
 1116|     35|			for (int j = 0; j < 4; j++) {
  ------------------
  |  Branch (1116:20): [True: 28, False: 7]
  ------------------
 1117|     28|				apdu_buf[j] = apdu_buf[j] ^ icv[j];
 1118|     28|			}
 1119|      8|		} else {
 1120|      8|			r = aes128_encrypt_cbc(card, exdata->sk_mac, 16, icv, apdu_buf, mac_len, mac);
 1121|      8|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cbc failed");
  ------------------
  |  |  174|      8|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      8|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      8|	int _ret = (r); \
  |  |  |  |  168|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1122|      8|			memcpy(mac_tlv + 2, &mac[mac_len - 16], 8);
 1123|      8|		}
 1124|    197|	} else {
 1125|    197|		unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
 1126|    197|		unsigned char tmp[8] = {0};
 1127|    197|		r = des_encrypt_cbc(card, exdata->sk_mac, 8, icv, apdu_buf, mac_len, mac);
 1128|    197|		LOG_TEST_RET(card->ctx, r, "des_encrypt_cbc 1 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1129|    197|		r = des_decrypt_cbc(card, &exdata->sk_mac[8], 8, iv, &mac[mac_len - 8], 8, tmp);
 1130|    197|		LOG_TEST_RET(card->ctx, r, "des_decrypt_cbc 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|    197|		memset(iv, 0x00, sizeof iv);
 1132|    197|		r = des_encrypt_cbc(card, exdata->sk_mac, 8, iv, tmp, 8, mac_tlv + 2);
 1133|    197|		LOG_TEST_RET(card->ctx, r, "des_encrypt_cbc 2 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1134|    197|	}
 1135|       |
 1136|    212|	*mac_tlv_len = 2 + 8;
 1137|    212|	return 0;
 1138|    212|}
card-epass2003.c:epass2003_sm_free_wrapped_apdu:
 1633|  2.63k|{
 1634|  2.63k|	struct sc_context *ctx = card->ctx;
 1635|  2.63k|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|  2.63k|#define SC_SUCCESS				0
  ------------------
 1636|       |
 1637|  2.63k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.63k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.63k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1638|  2.63k|	if (!sm_apdu)
  ------------------
  |  Branch (1638:6): [True: 0, False: 2.63k]
  ------------------
 1639|  2.63k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1640|  2.63k|	if (!(*sm_apdu))
  ------------------
  |  Branch (1640:6): [True: 0, False: 2.63k]
  ------------------
 1641|  2.63k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1642|       |
 1643|       |
 1644|  2.63k|	if (plain)
  ------------------
  |  Branch (1644:6): [True: 2.63k, False: 0]
  ------------------
 1645|  2.63k|		rv = epass2003_sm_unwrap_apdu(card, *sm_apdu, plain);
 1646|       |
 1647|  2.63k|	if ((*sm_apdu)->data) {
  ------------------
  |  Branch (1647:6): [True: 2.63k, False: 0]
  ------------------
 1648|  2.63k|		unsigned char * p = (unsigned char *)((*sm_apdu)->data);
 1649|  2.63k|		free(p);
 1650|  2.63k|	}
 1651|  2.63k|	if ((*sm_apdu)->resp) {
  ------------------
  |  Branch (1651:6): [True: 2.63k, False: 0]
  ------------------
 1652|  2.63k|		free((*sm_apdu)->resp);
 1653|  2.63k|	}
 1654|       |
 1655|  2.63k|	free(*sm_apdu);
 1656|  2.63k|	*sm_apdu = NULL;
 1657|       |
 1658|  2.63k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.63k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.63k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.63k|	int _ret = r; \
  |  |  |  |  155|  2.63k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.63k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|    211|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 211, False: 2.42k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.63k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.63k|	return _ret; \
  |  |  |  |  163|  2.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1659|  2.63k|}
card-epass2003.c:epass2003_sm_unwrap_apdu:
 1581|  2.63k|{
 1582|  2.63k|	int r;
 1583|  2.63k|	size_t len = 0;
 1584|  2.63k|	epass2003_exdata *exdata = NULL;
 1585|       |
 1586|  2.63k|	if (!card->drv_data)
  ------------------
  |  Branch (1586:6): [True: 0, False: 2.63k]
  ------------------
 1587|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1588|       |
 1589|  2.63k|	exdata = (epass2003_exdata *)card->drv_data;
 1590|       |
 1591|  2.63k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.63k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.63k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1592|       |
 1593|       |	/* verify MAC, and check if SW1,2 match SW1,2 encapsulated in SM */
 1594|  2.63k|	if (exdata->sm) {
  ------------------
  |  Branch (1594:6): [True: 212, False: 2.42k]
  ------------------
 1595|    212|		if (epass2003_check_response_mac_and_sw(card, sm)) {
  ------------------
  |  Branch (1595:7): [True: 211, False: 1]
  ------------------
 1596|    211|			sc_log(card->ctx, "MAC or SW incorrect");
  ------------------
  |  |   71|    211|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1597|       |			/* The card answers 6988 in plain when our session keys are no longer valid,
 1598|       |			 * e.g. because another process has established its own session. Let
 1599|       |			 * sc_sm_single_transmit() re-establish secure messaging and retry. */
 1600|    211|			if (sc_check_sw(card, sm->sw1, sm->sw2) == SC_ERROR_INCORRECT_SM_OBJECTS)
  ------------------
  |  |  128|    211|#define SC_ERROR_INCORRECT_SM_OBJECTS		-1613
  ------------------
  |  Branch (1600:8): [True: 4, False: 207]
  ------------------
 1601|      4|				return SC_ERROR_INCORRECT_SM_OBJECTS;
  ------------------
  |  |  128|      4|#define SC_ERROR_INCORRECT_SM_OBJECTS		-1613
  ------------------
 1602|    207|			return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    207|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1603|    211|		}
 1604|    212|	}
 1605|  2.42k|	r = sc_check_sw(card, sm->sw1, sm->sw2);
 1606|  2.42k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.42k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1606:6): [True: 1.30k, False: 1.12k]
  ------------------
 1607|  1.30k|		if (exdata->sm) {
  ------------------
  |  Branch (1607:7): [True: 0, False: 1.30k]
  ------------------
 1608|      0|			len = plain->resplen;
 1609|      0|			if (0 != decrypt_response(card, sm->resp, sm->resplen, plain->resp, &len))
  ------------------
  |  Branch (1609:8): [True: 0, False: 0]
  ------------------
 1610|      0|				return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      0|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1611|  1.30k|		} else {
 1612|  1.30k|			if (sm->resplen > 0) {
  ------------------
  |  Branch (1612:8): [True: 1.15k, False: 146]
  ------------------
 1613|  1.15k|				if (!plain->resp || plain->resplen < sm->resplen)
  ------------------
  |  Branch (1613:9): [True: 0, False: 1.15k]
  |  Branch (1613:25): [True: 0, False: 1.15k]
  ------------------
 1614|      0|					return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1615|  1.15k|				memcpy(plain->resp, sm->resp, sm->resplen);
 1616|  1.15k|			}
 1617|  1.30k|			len = sm->resplen;
 1618|  1.30k|		}
 1619|  1.30k|	}
 1620|       |
 1621|  2.42k|	plain->resplen = len;
 1622|  2.42k|	plain->sw1 = sm->sw1;
 1623|  2.42k|	plain->sw2 = sm->sw2;
 1624|       |
 1625|  2.42k|	sc_log(card->ctx, "unwrapped APDU: resplen %zu, SW %02X%02X", plain->resplen, plain->sw1, plain->sw2);
  ------------------
  |  |   71|  2.42k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1626|  2.42k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.42k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.42k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.42k|	int _ret = r; \
  |  |  |  |  155|  2.42k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.42k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.42k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.42k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.42k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.42k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.42k|	return _ret; \
  |  |  |  |  163|  2.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1627|  2.42k|}
card-epass2003.c:epass2003_check_response_mac_and_sw:
 1404|    212|{
 1405|    212|	unsigned char iv[16];
 1406|    212|	unsigned char *data = NULL, *mac = NULL;
 1407|    212|	size_t blocksize, mac_len;
 1408|    212|	int ret = -1;
 1409|    212|	unsigned int cla = 0, tag = 0;
 1410|    212|	size_t taglen = 0;
 1411|    212|	const u8 *p = sm->resp;
 1412|    212|	const u8 *tag_start;
 1413|    212|	const u8 *mac_val;
 1414|    212|	size_t left = sm->resplen;
 1415|    212|	epass2003_exdata *exdata;
 1416|    212|	unsigned char *in = sm->resp;
 1417|    212|	size_t inlen = sm->resplen;
 1418|       |
 1419|       |	/* card/ctx/drv_data is already checked by caller */
 1420|    212|	exdata = (epass2003_exdata *)card->drv_data;
 1421|       |
 1422|       |	/* The SM must contain at least TLV encoded SW and MAC fields. */
 1423|    212|	if (inlen < 14)
  ------------------
  |  Branch (1423:6): [True: 81, False: 131]
  ------------------
 1424|     81|		return ret;
 1425|       |
 1426|       |	/* Optional DO 0x87 */
 1427|    131|	tag_start = p;
 1428|    131|	if (SC_SUCCESS != epass2003_sm_read_tag(card, &p, left, &cla, &tag, &taglen) || p == NULL)
  ------------------
  |  |   28|    131|#define SC_SUCCESS				0
  ------------------
  |  Branch (1428:6): [True: 11, False: 120]
  |  Branch (1428:82): [True: 3, False: 117]
  ------------------
 1429|     14|		return ret;
 1430|    117|	left -= (p - tag_start);
 1431|    117|	if (taglen > left)
  ------------------
  |  Branch (1431:6): [True: 0, False: 117]
  ------------------
 1432|      0|		return ret;
 1433|       |
 1434|    117|	if ((cla | tag) == 0x87) {
  ------------------
  |  Branch (1434:6): [True: 28, False: 89]
  ------------------
 1435|     28|		p += taglen;
 1436|     28|		left -= taglen;
 1437|       |
 1438|       |		/* Read next tag (must be DO 0x99) */
 1439|     28|		tag_start = p;
 1440|     28|		if (SC_SUCCESS != epass2003_sm_read_tag(card, &p, left, &cla, &tag, &taglen) || p == NULL)
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  |  Branch (1440:7): [True: 5, False: 23]
  |  Branch (1440:83): [True: 2, False: 21]
  ------------------
 1441|      7|			return ret;
 1442|     21|		left -= (p - tag_start);
 1443|     21|		if (taglen > left)
  ------------------
  |  Branch (1443:7): [True: 0, False: 21]
  ------------------
 1444|      0|			return ret;
 1445|     21|	}
 1446|       |
 1447|       |	/* compare BER-TLV encoded SW (TAG 0x99) and raw SW */
 1448|    110|	if ((cla | tag) != 0x99 || taglen != 2)
  ------------------
  |  Branch (1448:6): [True: 50, False: 60]
  |  Branch (1448:29): [True: 5, False: 55]
  ------------------
 1449|     55|		return ret;
 1450|     55|	if (sm->sw1 != p[0] || sm->sw2 != p[1])
  ------------------
  |  Branch (1450:6): [True: 3, False: 52]
  |  Branch (1450:25): [True: 6, False: 46]
  ------------------
 1451|      9|		return ret;
 1452|       |
 1453|     46|	p += taglen;
 1454|     46|	left -= taglen;
 1455|       |
 1456|       |	/* no documentation/real hardware to test, the response is accepted without MAC check */
 1457|     46|	if (exdata->bFipsCertification) {
  ------------------
  |  Branch (1457:6): [True: 0, False: 46]
  ------------------
 1458|      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__
  |  |  ------------------
  ------------------
 1459|      0|		return 0;
 1460|      0|	}
 1461|       |
 1462|       |	/* Next tag must be DO 0x8E */
 1463|     46|	tag_start = p;
 1464|     46|	if (SC_SUCCESS != epass2003_sm_read_tag(card, &p, left, &cla, &tag, &taglen) || p == NULL)
  ------------------
  |  |   28|     46|#define SC_SUCCESS				0
  ------------------
  |  Branch (1464:6): [True: 2, False: 44]
  |  Branch (1464:82): [True: 2, False: 42]
  ------------------
 1465|      4|		return ret;
 1466|     42|	left -= (p - tag_start);
 1467|     42|	if (taglen > left)
  ------------------
  |  Branch (1467:6): [True: 0, False: 42]
  ------------------
 1468|      0|		return ret;
 1469|       |
 1470|     42|	if ((cla | tag) != 0x8e || taglen != 8)
  ------------------
  |  Branch (1470:6): [True: 16, False: 26]
  |  Branch (1470:29): [True: 3, False: 23]
  ------------------
 1471|     19|		return ret;
 1472|     23|	mac_val = p;
 1473|       |
 1474|     23|	if (KEY_TYPE_AES == exdata->smtype)
  ------------------
  |  |   80|     23|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1474:6): [True: 1, False: 22]
  ------------------
 1475|      1|		blocksize = 16;
 1476|     22|	else
 1477|     22|		blocksize = 8;
 1478|       |
 1479|     23|	mac_len = tag_start - in;
 1480|     23|	if (NULL == (data = calloc(1, mac_len + blocksize)))
  ------------------
  |  Branch (1480:6): [True: 0, False: 23]
  ------------------
 1481|      0|		goto end;
 1482|     23|	if (NULL == (mac = malloc(mac_len + blocksize)))
  ------------------
  |  Branch (1482:6): [True: 0, False: 23]
  ------------------
 1483|      0|		goto end;
 1484|       |
 1485|       |	/* copy response to buffer and append padding */
 1486|     23|	memcpy(data, in, mac_len);
 1487|     23|	data[mac_len++] = 0x80;
 1488|       |
 1489|     23|	if (mac_len % blocksize)
  ------------------
  |  Branch (1489:6): [True: 23, False: 0]
  ------------------
 1490|     23|		mac_len += (blocksize - (mac_len % blocksize));
 1491|       |
 1492|       |	/* calculate MAC */
 1493|     23|	memcpy(iv, exdata->icv_mac, blocksize);
 1494|       |
 1495|     23|	if (KEY_TYPE_AES == exdata->smtype) {
  ------------------
  |  |   80|     23|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1495:6): [True: 1, False: 22]
  ------------------
 1496|      1|		if (aes128_encrypt_cbc(card, exdata->sk_mac, 16, iv, data, mac_len, mac))
  ------------------
  |  Branch (1496:7): [True: 0, False: 1]
  ------------------
 1497|      0|			goto end;
 1498|     22|	} else {
 1499|     22|		uint8_t tmp[8];
 1500|     22|		uint8_t iv0[EVP_MAX_IV_LENGTH];
 1501|     22|		if (des_encrypt_cbc(card, exdata->sk_mac, 8, iv, data, mac_len, mac))
  ------------------
  |  Branch (1501:7): [True: 0, False: 22]
  ------------------
 1502|      0|			goto end;
 1503|     22|		memset(iv0, 0, EVP_MAX_IV_LENGTH);
 1504|     22|		if (des_decrypt_cbc(card, &exdata->sk_mac[8], 8, iv0, &mac[mac_len - 8], 8, tmp))
  ------------------
  |  Branch (1504:7): [True: 0, False: 22]
  ------------------
 1505|      0|			goto end;
 1506|     22|		memset(iv0, 0, EVP_MAX_IV_LENGTH);
 1507|     22|		if (des_encrypt_cbc(card, exdata->sk_mac, 8, iv0, tmp, 8, &mac[mac_len - 8]))
  ------------------
  |  Branch (1507:7): [True: 0, False: 22]
  ------------------
 1508|      0|			goto end;
 1509|     22|	}
 1510|       |	/* compare MAC */
 1511|     23|	if (!memcmp(mac_val, mac + mac_len - blocksize, 8))
  ------------------
  |  Branch (1511:6): [True: 1, False: 22]
  ------------------
 1512|      1|		ret = 0;
 1513|     23|end:
 1514|     23|	if (data)
  ------------------
  |  Branch (1514:6): [True: 23, False: 0]
  ------------------
 1515|     23|		free(data);
 1516|     23|	if (mac)
  ------------------
  |  Branch (1516:6): [True: 23, False: 0]
  ------------------
 1517|     23|		free(mac);
 1518|     23|	return ret;
 1519|     23|}
card-epass2003.c:epass2003_sm_read_tag:
 1372|    205|{
 1373|    205|	const u8 *p;
 1374|       |
 1375|    205|	if (!buf || !*buf)
  ------------------
  |  Branch (1375:6): [True: 0, False: 205]
  |  Branch (1375:14): [True: 0, False: 205]
  ------------------
 1376|      0|		return sc_asn1_read_tag(buf, buflen, cla_out, tag_out, taglen);
 1377|       |
 1378|    205|	p = *buf;
 1379|    205|	if (buflen >= 3 && p[0] == 0x87 && (p[1] & 0x80) && p[2] == 0x01 && p[1] != 0x82) {
  ------------------
  |  Branch (1379:6): [True: 203, False: 2]
  |  Branch (1379:21): [True: 37, False: 166]
  |  Branch (1379:37): [True: 31, False: 6]
  |  Branch (1379:54): [True: 24, False: 7]
  |  Branch (1379:70): [True: 23, False: 1]
  ------------------
 1380|       |		/*
 1381|       |		 * Workaround for EPASS2003 firmware bug:
 1382|       |		 * Instead of (correct) TLV 87 81 81 [01 .. ..], incorrect TLV 87 81 [01 .. ..]
 1383|       |		 * is returned (0x81 is encoded as a short-form length).
 1384|       |		 */
 1385|     23|		size_t len = p[1];
 1386|     23|		if (buflen - 2 < len) {
  ------------------
  |  Branch (1386:7): [True: 2, False: 21]
  ------------------
 1387|      2|			*buf = NULL;
 1388|      2|			return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|      2|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1389|      2|		}
 1390|     21|		sc_log(card->ctx, "Workaround for wrong BER-TLV in SM response");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1391|     21|		*cla_out = (p[0] & SC_ASN1_TAG_CLASS) | (p[0] & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  208|     21|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              		*cla_out = (p[0] & SC_ASN1_TAG_CLASS) | (p[0] & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  214|     21|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1392|     21|		*tag_out = p[0] & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  215|     21|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
 1393|     21|		*taglen = len;
 1394|     21|		*buf = p + 2;
 1395|     21|		return SC_SUCCESS;
  ------------------
  |  |   28|     21|#define SC_SUCCESS				0
  ------------------
 1396|     23|	}
 1397|       |
 1398|    182|	return sc_asn1_read_tag(buf, buflen, cla_out, tag_out, taglen);
 1399|    205|}
card-epass2003.c:epass2003_finish:
 1864|    510|{
 1865|    510|	epass2003_exdata *exdata = (epass2003_exdata *)card->drv_data;
 1866|       |
 1867|    510|	if (exdata) {
  ------------------
  |  Branch (1867:6): [True: 510, False: 0]
  ------------------
 1868|    510|		sc_file_free(exdata->cur_df_file);
 1869|    510|		free(exdata);
 1870|    510|	}
 1871|    510|	return SC_SUCCESS;
  ------------------
  |  |   28|    510|#define SC_SUCCESS				0
  ------------------
 1872|    510|}
card-epass2003.c:epass2003_select_file:
 2233|  2.57k|{
 2234|  2.57k|	int r;
 2235|       |
 2236|  2.57k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.57k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.57k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.57k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.57k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.57k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2237|       |
 2238|  2.57k|	r = epass2003_sm_restart(card);
 2239|  2.57k|	LOG_TEST_RET(card->ctx, r, "Can not re-establish SM");
  ------------------
  |  |  174|  2.57k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.57k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.57k|	int _ret = (r); \
  |  |  |  |  168|  2.57k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 843, False: 1.73k]
  |  |  |  |  ------------------
  |  |  |  |  169|    843|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    843|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    843|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    843|		return _ret; \
  |  |  |  |  172|    843|	} \
  |  |  |  |  173|  2.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.73k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2240|       |
 2241|  1.73k|	switch (in_path->type) {
 2242|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (2242:2): [True: 0, False: 1.73k]
  ------------------
 2243|      0|		if (in_path->len != 2)
  ------------------
  |  Branch (2243:7): [True: 0, False: 0]
  ------------------
 2244|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2245|      0|		return epass2003_select_file_id(card, in_path->value[0], in_path->value[1], file_out);
 2246|    576|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    576|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2246:2): [True: 576, False: 1.15k]
  ------------------
 2247|    576|		r = epass2003_select_aid(card, in_path, file_out);
 2248|       |		/* the path of a DF selected by its name is not known */
 2249|    576|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|    576|#define SC_SUCCESS				0
  ------------------
  |  Branch (2249:7): [True: 63, False: 513]
  ------------------
 2250|     63|			epass2003_forget_cur_df(card);
 2251|    576|		return r;
 2252|  1.15k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  1.15k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (2252:2): [True: 1.15k, False: 576]
  ------------------
 2253|  1.15k|		return epass2003_select_path(card, in_path->value, in_path->len, file_out);
 2254|      0|	default:
  ------------------
  |  Branch (2254:2): [True: 0, False: 1.73k]
  ------------------
 2255|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2256|  1.73k|	}
 2257|  1.73k|}
card-epass2003.c:epass2003_sm_restart:
  963|  2.61k|{
  964|  2.61k|	epass2003_exdata *exdata = (epass2003_exdata *)card->drv_data;
  965|       |
  966|  2.61k|	if (exdata && exdata->sm && card->sm_ctx.sm_mode == SM_MODE_NONE)
  ------------------
  |  |   43|  1.05k|#define SM_MODE_NONE		0x0
  ------------------
  |  Branch (966:6): [True: 2.61k, False: 0]
  |  Branch (966:16): [True: 1.05k, False: 1.55k]
  |  Branch (966:30): [True: 843, False: 212]
  ------------------
  967|    843|		return epass2003_refresh(card);
  968|  1.76k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.76k|#define SC_SUCCESS				0
  ------------------
  969|  2.61k|}
card-epass2003.c:epass2003_select_fid:
 2063|  1.50k|{
 2064|  1.50k|	int r;
 2065|  1.50k|	sc_file_t *file = NULL;
 2066|  1.50k|	sc_path_t path;
 2067|       |
 2068|  1.50k|	memset(&path, 0, sizeof(path));
 2069|  1.50k|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  1.50k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 2070|  1.50k|	path.value[0] = id_hi;
 2071|  1.50k|	path.value[1] = id_lo;
 2072|  1.50k|	path.len = 2;
 2073|       |
 2074|  1.50k|	r = epass2003_select_fid_(card, &path, &file);
 2075|  1.50k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.50k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.50k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.50k|	int _ret = (r); \
  |  |  |  |  168|  1.50k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 839, False: 664]
  |  |  |  |  ------------------
  |  |  |  |  169|    839|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    839|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    839|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    839|		return _ret; \
  |  |  |  |  172|    839|	} \
  |  |  |  |  173|  1.50k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 664]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2076|       |
 2077|    664|	if (file_out) {
  ------------------
  |  Branch (2077:6): [True: 664, False: 0]
  ------------------
 2078|    664|		*file_out = file;
 2079|    664|	} else {
 2080|      0|		sc_file_free(file);
 2081|      0|	}
 2082|       |
 2083|    664|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    664|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    664|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    664|	int _ret = r; \
  |  |  |  |  155|    664|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 664, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    664|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 664]
  |  |  |  |  ------------------
  |  |  |  |  157|    664|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    664|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    664|	return _ret; \
  |  |  |  |  163|    664|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2084|    664|}
card-epass2003.c:epass2003_select_fid_:
 1930|  1.50k|{
 1931|  1.50k|	struct sc_apdu apdu;
 1932|  1.50k|	u8 buf[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1933|  1.50k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
 1934|  1.50k|	int r;
 1935|  1.50k|	size_t pathlen;
 1936|  1.50k|	sc_file_t *file = NULL;
 1937|       |
 1938|  1.50k|	if (!in_path || in_path->len > sizeof(pathbuf))
  ------------------
  |  Branch (1938:6): [True: 0, False: 1.50k]
  |  Branch (1938:18): [True: 0, False: 1.50k]
  ------------------
 1939|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1940|       |
 1941|  1.50k|	r = epass2003_hook_path(in_path, 1);
 1942|  1.50k|	LOG_TEST_RET(card->ctx, r, "Can not hook path");
  ------------------
  |  |  174|  1.50k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.50k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.50k|	int _ret = (r); \
  |  |  |  |  168|  1.50k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.50k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.50k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.50k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1943|       |
 1944|  1.50k|	memcpy(path, in_path->value, in_path->len);
 1945|  1.50k|	pathlen = in_path->len;
 1946|       |
 1947|  1.50k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.50k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1948|       |
 1949|  1.50k|	switch (in_path->type) {
 1950|  1.50k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  1.50k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1950:2): [True: 1.50k, False: 0]
  ------------------
 1951|  1.50k|		apdu.p1 = 0;
 1952|  1.50k|		if (pathlen != 2)
  ------------------
  |  Branch (1952:7): [True: 0, False: 1.50k]
  ------------------
 1953|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1954|  1.50k|		break;
 1955|  1.50k|	default:
  ------------------
  |  Branch (1955:2): [True: 0, False: 1.50k]
  ------------------
 1956|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1957|  1.50k|	}
 1958|  1.50k|	apdu.p2 = 0;		/* first record, return FCI */
 1959|  1.50k|	apdu.lc = pathlen;
 1960|  1.50k|	apdu.data = path;
 1961|  1.50k|	apdu.datalen = pathlen;
 1962|       |
 1963|  1.50k|	if (file_out != NULL) {
  ------------------
  |  Branch (1963:6): [True: 1.50k, False: 0]
  ------------------
 1964|  1.50k|		apdu.resp = buf;
 1965|  1.50k|		apdu.resplen = sizeof(buf);
 1966|  1.50k|		apdu.le = 0;
 1967|  1.50k|	} else {
 1968|      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 (1968:14): [True: 0, False: 0]
  ------------------
 1969|      0|	}
 1970|       |
 1971|  1.50k|	if (path[0] == 0x29) {	/* TODO:0x29 accords with FID prefix in profile  */
  ------------------
  |  Branch (1971:6): [True: 7, False: 1.49k]
  ------------------
 1972|       |		/* Not allowed to select private key file, so fake fci. */
 1973|       |		/* 62 16 82 02 11 00 83 02 29 00 85 02 08 00 86 08 FF 90 90 90 FF FF FF FF */
 1974|      7|		apdu.resplen = 0x18;
 1975|      7|		memcpy(apdu.resp,
 1976|      7|		       "\x6f\x16\x82\x02\x11\x00\x83\x02\x29\x00\x85\x02\x08\x00\x86\x08\xff\x90\x90\x90\xff\xff\xff\xff",
 1977|      7|		       apdu.resplen);
 1978|      7|		apdu.resp[9] = path[1];
 1979|      7|		apdu.sw1 = 0x90;
 1980|      7|		apdu.sw2 = 0x00;
 1981|      7|	}
 1982|  1.49k|	else {
 1983|  1.49k|		r = sc_transmit_apdu_t(card, &apdu);
 1984|  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: 224, False: 1.27k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1985|  1.49k|	}
 1986|       |
 1987|  1.27k|	if (file_out == NULL) {
  ------------------
  |  Branch (1987:6): [True: 0, False: 1.27k]
  ------------------
 1988|      0|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1988:7): [True: 0, False: 0]
  ------------------
 1989|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1990|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1991|      0|	}
 1992|       |
 1993|  1.27k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1994|  1.27k|	if (r)
  ------------------
  |  Branch (1994:6): [True: 499, False: 780]
  ------------------
 1995|  1.27k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    499|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    499|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    499|	int _ret = r; \
  |  |  |  |  155|    499|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 499, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    499|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    499|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 499, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    499|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    499|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    499|	return _ret; \
  |  |  |  |  163|    499|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1996|    780|	if (apdu.resplen < 2)
  ------------------
  |  Branch (1996:6): [True: 66, False: 714]
  ------------------
 1997|    780|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     66|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     66|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     66|	int _ret = r; \
  |  |  |  |  155|     66|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 66, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     66|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     66|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 66, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     66|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     66|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     66|	return _ret; \
  |  |  |  |  163|     66|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1998|       |
 1999|    714|	switch (apdu.resp[0]) {
 2000|    664|	case 0x6F:
  ------------------
  |  Branch (2000:2): [True: 664, False: 50]
  ------------------
 2001|    664|		file = sc_file_new();
 2002|    664|		if (file == NULL)
  ------------------
  |  Branch (2002:7): [True: 0, False: 664]
  ------------------
 2003|    664|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2004|    664|		file->path = *in_path;
 2005|    664|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (2005:7): [True: 0, False: 664]
  ------------------
 2006|      0|			sc_file_free(file);
 2007|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2008|      0|		}
 2009|       |
 2010|    664|		if ((size_t) apdu.resp[1] + 2 <= apdu.resplen)
  ------------------
  |  Branch (2010:7): [True: 620, False: 44]
  ------------------
 2011|    620|			card->ops->process_fci(card, file, apdu.resp + 2, apdu.resp[1]);
 2012|    664|		epass2003_hook_file(file, 0);
 2013|    664|		*file_out = file;
 2014|    664|		break;
 2015|     19|	case 0x00:		/* proprietary coding */
  ------------------
  |  Branch (2015:2): [True: 19, False: 695]
  ------------------
 2016|     19|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2017|      0|		break;
 2018|     31|	default:
  ------------------
  |  Branch (2018:2): [True: 31, False: 683]
  ------------------
 2019|     31|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     31|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     31|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     31|	int _ret = r; \
  |  |  |  |  155|     31|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     31|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     31|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     31|	return _ret; \
  |  |  |  |  163|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2020|    714|	}
 2021|    664|	return 0;
 2022|    714|}
card-epass2003.c:epass2003_hook_path:
 1878|  2.16k|{
 1879|  2.16k|	u8 fid_h = 0;
 1880|  2.16k|	u8 fid_l = 0;
 1881|       |
 1882|  2.16k|	if (!path || path->len < 2)
  ------------------
  |  Branch (1882:6): [True: 0, False: 2.16k]
  |  Branch (1882:15): [True: 0, False: 2.16k]
  ------------------
 1883|      0|		return -1;
 1884|  2.16k|	fid_h = path->value[path->len - 2];
 1885|  2.16k|	fid_l = path->value[path->len - 1];
 1886|       |
 1887|  2.16k|	switch (fid_h) {
 1888|     14|	case 0x29:
  ------------------
  |  Branch (1888:2): [True: 14, False: 2.15k]
  ------------------
 1889|     24|	case 0x30:
  ------------------
  |  Branch (1889:2): [True: 10, False: 2.15k]
  ------------------
 1890|     34|	case 0x31:
  ------------------
  |  Branch (1890:2): [True: 10, False: 2.15k]
  ------------------
 1891|     44|	case 0x32:
  ------------------
  |  Branch (1891:2): [True: 10, False: 2.15k]
  ------------------
 1892|     54|	case 0x33:
  ------------------
  |  Branch (1892:2): [True: 10, False: 2.15k]
  ------------------
 1893|     64|	case 0x34:
  ------------------
  |  Branch (1893:2): [True: 10, False: 2.15k]
  ------------------
 1894|     64|		if (inc)
  ------------------
  |  Branch (1894:7): [True: 37, False: 27]
  ------------------
 1895|     37|			fid_l = fid_l * FID_STEP;
  ------------------
  |  |  743|     37|#define FID_STEP 0x20
  ------------------
 1896|     27|		else
 1897|     27|			fid_l = fid_l / FID_STEP;
  ------------------
  |  |  743|     27|#define FID_STEP 0x20
  ------------------
 1898|     64|		path->value[path->len - 1] = fid_l;
 1899|     64|		return 1;
 1900|  2.10k|	default:
  ------------------
  |  Branch (1900:2): [True: 2.10k, False: 64]
  ------------------
 1901|  2.10k|		break;
 1902|  2.16k|	}
 1903|  2.10k|	return 0;
 1904|  2.16k|}
card-epass2003.c:epass2003_hook_file:
 1909|    664|{
 1910|    664|	int fidl = file->id & 0xff;
 1911|    664|	int fidh = file->id & 0xff00;
 1912|    664|	int rv = 0;
 1913|       |
 1914|    664|	rv = epass2003_hook_path(&file->path, inc);
 1915|       |
 1916|    664|	if (rv > 0) {
  ------------------
  |  Branch (1916:6): [True: 27, False: 637]
  ------------------
 1917|     27|		if (inc)
  ------------------
  |  Branch (1917:7): [True: 0, False: 27]
  ------------------
 1918|      0|			file->id = fidh + fidl * FID_STEP;
  ------------------
  |  |  743|      0|#define FID_STEP 0x20
  ------------------
 1919|     27|		else
 1920|     27|			file->id = fidh + fidl / FID_STEP;
  ------------------
  |  |  743|     27|#define FID_STEP 0x20
  ------------------
 1921|     27|	}
 1922|    664|	if (rv < 0)
  ------------------
  |  Branch (1922:6): [True: 0, False: 664]
  ------------------
 1923|      0|		return rv;
 1924|    664|	return SC_SUCCESS;
  ------------------
  |  |   28|    664|#define SC_SUCCESS				0
  ------------------
 1925|    664|}
card-epass2003.c:epass2003_set_cur_df:
 2039|    418|{
 2040|    418|	epass2003_exdata *exdata = (epass2003_exdata *)card->drv_data;
 2041|    418|	sc_file_t *df = NULL;
 2042|       |
 2043|    418|	if (!exdata)
  ------------------
  |  Branch (2043:6): [True: 0, False: 418]
  ------------------
 2044|      0|		return;
 2045|    418|	if (len > sizeof(exdata->cur_df)) {
  ------------------
  |  Branch (2045:6): [True: 0, False: 418]
  ------------------
 2046|      0|		epass2003_forget_cur_df(card);
 2047|      0|		return;
 2048|      0|	}
 2049|    418|	sc_file_dup(&df, file);
 2050|    418|	if (!df) {
  ------------------
  |  Branch (2050:6): [True: 0, False: 418]
  ------------------
 2051|      0|		epass2003_forget_cur_df(card);
 2052|      0|		return;
 2053|      0|	}
 2054|    418|	sc_file_free(exdata->cur_df_file);
 2055|    418|	exdata->cur_df_file = df;
 2056|    418|	memcpy(exdata->cur_df, path, len);
 2057|    418|	exdata->cur_df_len = len;
 2058|    418|}
card-epass2003.c:epass2003_select_aid:
 2089|    576|{
 2090|    576|	int r = 0;
 2091|       |
 2092|    576|	r = iso_ops->select_file(card, in_path, file_out);
 2093|    576|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    576|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    576|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    576|	int _ret = (r); \
  |  |  |  |  168|    576|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 513, False: 63]
  |  |  |  |  ------------------
  |  |  |  |  169|    513|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    513|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    513|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    513|		return _ret; \
  |  |  |  |  172|    513|	} \
  |  |  |  |  173|    576|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 63]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2094|       |
 2095|     63|	if (file_out && *file_out) {
  ------------------
  |  Branch (2095:6): [True: 0, False: 63]
  |  Branch (2095:18): [True: 0, False: 0]
  ------------------
 2096|      0|		sc_file_t *file = *file_out;
 2097|      0|		if (in_path->len > sizeof(file->name))
  ------------------
  |  Branch (2097:7): [True: 0, False: 0]
  ------------------
 2098|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2099|       |
 2100|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2101|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
 2102|      0|		file->path.len = 0;
 2103|      0|		file->size = 0;
 2104|       |		/* AID */
 2105|      0|		memcpy(file->name, in_path->value, in_path->len);
 2106|      0|		file->namelen = in_path->len;
 2107|      0|		file->id = 0x0000;
 2108|      0|	}
 2109|       |
 2110|     63|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2111|     63|}
card-epass2003.c:epass2003_forget_cur_df:
 2026|    799|{
 2027|    799|	epass2003_exdata *exdata = (epass2003_exdata *)card->drv_data;
 2028|       |
 2029|    799|	if (exdata) {
  ------------------
  |  Branch (2029:6): [True: 799, False: 0]
  ------------------
 2030|    799|		exdata->cur_df_len = 0;
 2031|    799|		sc_file_free(exdata->cur_df_file);
 2032|       |		exdata->cur_df_file = NULL;
 2033|    799|	}
 2034|    799|}
card-epass2003.c:epass2003_select_path:
 2117|  1.15k|{
 2118|  1.15k|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
 2119|  1.15k|	const u8 *path = pathbuf;
 2120|  1.15k|	size_t pathlen = len;
 2121|  1.15k|	size_t i, start = 0;
 2122|  1.15k|	int r;
 2123|  1.15k|	sc_file_t *file = NULL;
 2124|  1.15k|	epass2003_exdata *exdata;
 2125|       |
 2126|  1.15k|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (2126:6): [True: 0, False: 1.15k]
  |  Branch (2126:26): [True: 1, False: 1.15k]
  |  Branch (2126:41): [True: 0, False: 1.15k]
  ------------------
 2127|  1.15k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2128|       |
 2129|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
 2130|  1.15k|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (2130:6): [True: 107, False: 1.04k]
  |  Branch (2130:23): [True: 1, False: 106]
  |  Branch (2130:42): [True: 1, False: 105]
  ------------------
 2131|  1.15k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2132|       |
 2133|       |	/* unify path (the first FID should be MF) */
 2134|  1.15k|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (2134:6): [True: 63, False: 1.08k]
  |  Branch (2134:25): [True: 3, False: 1.08k]
  ------------------
 2135|     66|		n_pathbuf[0] = 0x3f;
 2136|     66|		n_pathbuf[1] = 0x00;
 2137|     66|		memcpy(n_pathbuf + 2, path, pathlen);
 2138|     66|		path = n_pathbuf;
 2139|     66|		pathlen += 2;
 2140|     66|	}
 2141|       |
 2142|  1.15k|	exdata = (epass2003_exdata *)card->drv_data;
 2143|  1.15k|	if (exdata && exdata->cur_df_len > 0 && exdata->cur_df_len <= pathlen &&
  ------------------
  |  Branch (2143:6): [True: 1.15k, False: 0]
  |  Branch (2143:16): [True: 461, False: 690]
  |  Branch (2143:42): [True: 461, False: 0]
  ------------------
 2144|    461|			memcmp(path, exdata->cur_df, exdata->cur_df_len) == 0) {
  ------------------
  |  Branch (2144:4): [True: 415, False: 46]
  ------------------
 2145|    415|		if (exdata->cur_df_len == pathlen) {
  ------------------
  |  Branch (2145:7): [True: 1, False: 414]
  ------------------
 2146|       |			/* already in the requested DF */
 2147|      1|			if (file_out) {
  ------------------
  |  Branch (2147:8): [True: 0, False: 1]
  ------------------
 2148|      0|				sc_file_dup(file_out, exdata->cur_df_file);
 2149|      0|				if (!*file_out)
  ------------------
  |  Branch (2149:9): [True: 0, False: 0]
  ------------------
 2150|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2151|      0|			}
 2152|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2153|      1|		}
 2154|       |		/* inside the current DF: select only what follows it */
 2155|    414|		start = exdata->cur_df_len;
 2156|    736|	} else {
 2157|    736|		epass2003_forget_cur_df(card);
 2158|    736|	}
 2159|       |
 2160|  1.50k|	for (i = start; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (2160:18): [True: 831, False: 672]
  ------------------
 2161|    831|		r = epass2003_select_fid(card, path[i], path[i + 1], &file);
 2162|    831|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|    831|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    831|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    831|	int _ret = (r); \
  |  |  |  |  168|    831|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 478, False: 353]
  |  |  |  |  ------------------
  |  |  |  |  169|    478|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    478|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    478|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    478|		return _ret; \
  |  |  |  |  172|    478|	} \
  |  |  |  |  173|    831|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 353]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2163|       |		/* a FID that is followed by further FIDs is a DF */
 2164|    353|		epass2003_set_cur_df(card, path, i + 2, file);
 2165|    353|		sc_file_free(file);
 2166|    353|		file = NULL;
 2167|    353|	}
 2168|       |
 2169|    672|	r = epass2003_select_fid(card, path[pathlen - 2], path[pathlen - 1], &file);
 2170|       |	/* selecting an EF or a failed select leaves the current DF unchanged */
 2171|    672|	if (r == SC_SUCCESS && file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |   28|  1.34k|#define SC_SUCCESS				0
  ------------------
              	if (r == SC_SUCCESS && file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |  214|    311|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (2171:6): [True: 311, False: 361]
  |  Branch (2171:25): [True: 65, False: 246]
  ------------------
 2172|     65|		epass2003_set_cur_df(card, path, pathlen, file);
 2173|       |
 2174|    672|	if (file_out)
  ------------------
  |  Branch (2174:6): [True: 458, False: 214]
  ------------------
 2175|    458|		*file_out = file;
 2176|    214|	else
 2177|    214|		sc_file_free(file);
 2178|    672|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    672|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    672|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    672|	int _ret = r; \
  |  |  |  |  155|    672|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 672, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    672|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    361|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 361, False: 311]
  |  |  |  |  ------------------
  |  |  |  |  157|    672|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    672|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    672|	return _ret; \
  |  |  |  |  163|    672|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2179|    672|}
card-epass2003.c:epass2003_card_ctl:
 3276|     19|{
 3277|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3278|       |
 3279|     19|	sc_log(card->ctx, "cmd is %0lx", cmd);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3280|     19|	switch (cmd) {
 3281|      0|	case SC_CARDCTL_ENTERSAFE_WRITE_KEY:
  ------------------
  |  Branch (3281:2): [True: 0, False: 19]
  ------------------
 3282|      0|		return epass2003_write_key(card, (sc_epass2003_wkey_data *) ptr);
 3283|      0|	case SC_CARDCTL_ENTERSAFE_GENERATE_KEY:
  ------------------
  |  Branch (3283:2): [True: 0, False: 19]
  ------------------
 3284|      0|		return epass2003_gen_key(card, (sc_epass2003_gen_key_data *) ptr);
 3285|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (3285:2): [True: 0, False: 19]
  ------------------
 3286|      0|		return epass2003_erase_card(card);
 3287|     19|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (3287:2): [True: 19, False: 0]
  ------------------
 3288|     19|		return epass2003_get_serialnr(card, (sc_serial_number_t *) ptr);
 3289|      0|	default:
  ------------------
  |  Branch (3289:2): [True: 0, False: 19]
  ------------------
 3290|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3291|     19|	}
 3292|     19|}
card-epass2003.c:epass2003_get_serialnr:
 3257|     19|{
 3258|     19|	u8 rbuf[8];
 3259|     19|	size_t rbuf_len = sizeof(rbuf);
 3260|       |
 3261|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3262|       |
 3263|     19|	if (SC_SUCCESS != get_data(card, 0x80, rbuf, rbuf_len))
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
  |  Branch (3263:6): [True: 18, False: 1]
  ------------------
 3264|     18|		return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|     18|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 3265|       |
 3266|      1|	card->serialnr.len = serial->len = 8;
 3267|      1|	memcpy(card->serialnr.value, rbuf, 8);
 3268|      1|	memcpy(serial->value, rbuf, 8);
 3269|       |
 3270|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3271|      1|}
card-epass2003.c:epass2003_process_fci:
 2526|    620|{
 2527|    620|	sc_context_t *ctx = card->ctx;
 2528|    620|	size_t taglen, len = buflen;
 2529|    620|	const u8 *tag = NULL, *p = buf;
 2530|       |
 2531|    620|	sc_log(ctx, "processing FCI bytes");
  ------------------
  |  |   71|    620|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2532|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
 2533|    620|	if (tag != NULL && taglen == 2) {
  ------------------
  |  Branch (2533:6): [True: 238, False: 382]
  |  Branch (2533:21): [True: 225, False: 13]
  ------------------
 2534|    225|		file->id = (tag[0] << 8) | tag[1];
 2535|    225|		sc_log(ctx, "  file identifier: 0x%02X%02X", tag[0], tag[1]);
  ------------------
  |  |   71|    225|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2536|    225|	}
 2537|       |
 2538|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
 2539|    620|	if (tag != NULL && taglen > 0 && taglen < 3) {
  ------------------
  |  Branch (2539:6): [True: 45, False: 575]
  |  Branch (2539:21): [True: 29, False: 16]
  |  Branch (2539:35): [True: 23, False: 6]
  ------------------
 2540|     23|		file->size = tag[0];
 2541|     23|		if (taglen == 2)
  ------------------
  |  Branch (2541:7): [True: 13, False: 10]
  ------------------
 2542|     13|			file->size = (file->size << 8) + tag[1];
 2543|     23|		sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2544|     23|	}
 2545|       |
 2546|    620|	if (tag == NULL) {
  ------------------
  |  Branch (2546:6): [True: 575, False: 45]
  ------------------
 2547|    575|		tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
 2548|    575|		if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (2548:7): [True: 86, False: 489]
  |  Branch (2548:22): [True: 72, False: 14]
  ------------------
 2549|     72|			int bytes = (tag[0] << 8) + tag[1];
 2550|       |
 2551|     72|			sc_log(ctx, "  bytes in file: %d", bytes);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2552|     72|			file->size = bytes;
 2553|     72|		}
 2554|    575|	}
 2555|       |
 2556|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
 2557|    620|	if (tag != NULL) {
  ------------------
  |  Branch (2557:6): [True: 340, False: 280]
  ------------------
 2558|    340|		if (taglen > 0) {
  ------------------
  |  Branch (2558:7): [True: 323, False: 17]
  ------------------
 2559|    323|			unsigned char byte = tag[0];
 2560|    323|			const char *type;
 2561|       |
 2562|    323|			if (byte == 0x38) {
  ------------------
  |  Branch (2562:8): [True: 81, False: 242]
  ------------------
 2563|     81|				type = "DF";
 2564|     81|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     81|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2565|    242|			} else if (0x01 <= byte && byte <= 0x07) {
  ------------------
  |  Branch (2565:15): [True: 226, False: 16]
  |  Branch (2565:31): [True: 98, False: 128]
  ------------------
 2566|     98|				type = "working EF";
 2567|     98|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     98|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 2568|     98|				switch (byte) {
 2569|     20|				case 0x01:
  ------------------
  |  Branch (2569:5): [True: 20, False: 78]
  ------------------
 2570|     20|					file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     20|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 2571|     20|					break;
 2572|     32|				case 0x02:
  ------------------
  |  Branch (2572:5): [True: 32, False: 66]
  ------------------
 2573|     32|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     32|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
 2574|     32|					break;
 2575|     12|				case 0x04:
  ------------------
  |  Branch (2575:5): [True: 12, False: 86]
  ------------------
 2576|     12|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     12|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
 2577|     12|					break;
 2578|     34|				default:
  ------------------
  |  Branch (2578:5): [True: 34, False: 64]
  ------------------
 2579|     34|					break;
 2580|     98|				}
 2581|       |
 2582|    144|			} else if (0x10 == byte) {
  ------------------
  |  Branch (2582:15): [True: 1, False: 143]
  ------------------
 2583|      1|				type = "BSO";
 2584|      1|				file->type = SC_FILE_TYPE_BSO;
  ------------------
  |  |  217|      1|#define SC_FILE_TYPE_BSO		0x10
  ------------------
 2585|    143|			} else if (0x11 <= byte) {
  ------------------
  |  Branch (2585:15): [True: 123, False: 20]
  ------------------
 2586|    123|				type = "internal EF";
 2587|    123|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    123|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
 2588|    123|				switch (byte) {
 2589|     17|				case 0x11:
  ------------------
  |  Branch (2589:5): [True: 17, False: 106]
  ------------------
 2590|     17|					break;
 2591|     12|				case 0x12:
  ------------------
  |  Branch (2591:5): [True: 12, False: 111]
  ------------------
 2592|     12|					break;
 2593|     94|				default:
  ------------------
  |  Branch (2593:5): [True: 94, False: 29]
  ------------------
 2594|     94|					break;
 2595|    123|				}
 2596|    123|			} else {
 2597|     20|				type = "unknown";
 2598|     20|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     20|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
 2599|     20|			}
 2600|    323|			sc_log(ctx, "type %s, EF structure %d", type, byte);
  ------------------
  |  |   71|    323|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2601|    323|		}
 2602|    340|	}
 2603|       |
 2604|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
 2605|    620|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (2605:6): [True: 89, False: 531]
  |  Branch (2605:21): [True: 76, False: 13]
  |  Branch (2605:35): [True: 66, False: 10]
  ------------------
 2606|     66|		memcpy(file->name, tag, taglen);
 2607|     66|		file->namelen = taglen;
 2608|       |
 2609|     66|		sc_log_hex(ctx, "File name", file->name, file->namelen);
  ------------------
  |  |  129|     66|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     66|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2610|     66|		if (!file->type)
  ------------------
  |  Branch (2610:7): [True: 40, False: 26]
  ------------------
 2611|     40|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     40|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2612|     66|	}
 2613|       |
 2614|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
 2615|    620|	if (tag != NULL && taglen)
  ------------------
  |  Branch (2615:6): [True: 128, False: 492]
  |  Branch (2615:21): [True: 118, False: 10]
  ------------------
 2616|    118|		sc_file_set_prop_attr(file, tag, taglen);
 2617|    502|	else
 2618|    502|		file->prop_attr_len = 0;
 2619|       |
 2620|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0xA5, &taglen);
 2621|    620|	if (tag != NULL && taglen)
  ------------------
  |  Branch (2621:6): [True: 34, False: 586]
  |  Branch (2621:21): [True: 24, False: 10]
  ------------------
 2622|     24|		sc_file_set_prop_attr(file, tag, taglen);
 2623|       |
 2624|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x86, &taglen);
 2625|    620|	if (tag != NULL && taglen) {
  ------------------
  |  Branch (2625:6): [True: 278, False: 342]
  |  Branch (2625:21): [True: 264, False: 14]
  ------------------
 2626|    264|		unsigned int i;
 2627|    264|		sc_file_set_sec_attr(file, tag, taglen);
 2628|  3.41k|		for (i = 0; i< taglen; i++)
  ------------------
  |  Branch (2628:15): [True: 3.15k, False: 264]
  ------------------
 2629|  3.15k|			if (tag[i] != 0xff) /* skip unused entries */
  ------------------
  |  Branch (2629:8): [True: 2.81k, False: 340]
  ------------------
 2630|  2.81k|				sec_attr_to_entry(card, file, i);
 2631|    264|	}
 2632|       |
 2633|    620|	tag = sc_asn1_find_tag(ctx, p, len, 0x8A, &taglen);
 2634|    620|	if (tag != NULL && taglen == 1) {
  ------------------
  |  Branch (2634:6): [True: 105, False: 515]
  |  Branch (2634:21): [True: 65, False: 40]
  ------------------
 2635|     65|		if (tag[0] == 0x01)
  ------------------
  |  Branch (2635:7): [True: 4, False: 61]
  ------------------
 2636|      4|			file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|      4|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
 2637|     61|		else if (tag[0] == 0x07 || tag[0] == 0x05)
  ------------------
  |  Branch (2637:12): [True: 7, False: 54]
  |  Branch (2637:30): [True: 10, False: 44]
  ------------------
 2638|     17|			file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     17|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
 2639|     44|		else if (tag[0] == 0x06 || tag[0] == 0x04)
  ------------------
  |  Branch (2639:12): [True: 10, False: 34]
  |  Branch (2639:30): [True: 10, False: 24]
  ------------------
 2640|     20|			file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     20|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
 2641|     65|	}
 2642|    620|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    620|#define SC_FILE_MAGIC			0x14426950
  ------------------
 2643|       |
 2644|    620|	return 0;
 2645|    620|}
card-epass2003.c:epass2003_pin_cmd:
 3455|     19|{
 3456|     19|	int r;
 3457|     19|	u8 kid;
 3458|     19|	u8 retries = 0;
 3459|     19|	u8 pin_low = 3;
 3460|     19|	unsigned char maxtries = 0;
 3461|       |
 3462|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3463|       |
 3464|     19|	if (!data)
  ------------------
  |  Branch (3464:6): [True: 0, False: 19]
  ------------------
 3465|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3466|       |
 3467|     19|	internal_sanitize_pin_info(&data->pin1, 0);
 3468|     19|	internal_sanitize_pin_info(&data->pin2, 1);
 3469|     19|	data->pin1.tries_left = -1;
 3470|     19|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     19|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 3471|     19|	kid = data->pin_reference;
 3472|       |
 3473|       |	/* get pin retries */
 3474|     19|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|     19|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (3474:6): [True: 19, False: 0]
  ------------------
 3475|       |
 3476|     19|		r = get_external_key_retries(card, 0x80 | kid, &retries);
 3477|     19|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
  |  Branch (3477:7): [True: 1, False: 18]
  ------------------
 3478|      1|			data->pin1.tries_left = retries;
 3479|       |
 3480|      1|			r = get_external_key_maxtries(card, &maxtries);
 3481|      1|			LOG_TEST_RET(card->ctx, r, "get max counter 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3482|       |
 3483|      0|			data->pin1.max_tries = maxtries;
 3484|      0|			data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 3485|      0|		}
 3486|     18|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     18|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     18|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     18|	int _ret = r; \
  |  |  |  |  155|     18|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     18|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     18|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     18|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     18|	return _ret; \
  |  |  |  |  163|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3487|     18|	}
 3488|       |
 3489|      0|	if (NULL == (unsigned char *)data->pin1.data || 0 == data->pin1.len)
  ------------------
  |  Branch (3489:6): [True: 0, False: 0]
  |  Branch (3489:50): [True: 0, False: 0]
  ------------------
 3490|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_PIN_CODE_INCORRECT);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3491|       |
 3492|      0|	if (data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (3492:6): [True: 0, False: 0]
  ------------------
 3493|      0|		r = external_key_auth(card, (kid + 1), (unsigned char *)data->pin1.data,
 3494|      0|				data->pin1.len);
 3495|      0|		if (r == SC_ERROR_PIN_CODE_INCORRECT &&
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (3495:7): [True: 0, False: 0]
  ------------------
 3496|      0|				get_external_key_retries(card, 0x80 | (kid + 1), &retries) == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3496:5): [True: 0, False: 0]
  ------------------
 3497|      0|			data->pin1.tries_left = retries;
 3498|      0|		LOG_TEST_RET(card->ctx, r, "verify unblock 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3499|       |
 3500|      0|		if (data->pin2.data && data->pin2.len > 0) {
  ------------------
  |  Branch (3500:7): [True: 0, False: 0]
  |  Branch (3500:26): [True: 0, False: 0]
  ------------------
 3501|      0|			r = update_secret_key(card, 0x04, kid, data->pin2.data,
 3502|      0|					(unsigned long)data->pin2.len);
 3503|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3504|      0|		}
 3505|      0|	} else if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (3505:13): [True: 0, False: 0]
  ------------------
 3506|      0|		if (NULL == data->pin2.data || 0 == data->pin2.len)
  ------------------
  |  Branch (3506:7): [True: 0, False: 0]
  |  Branch (3506:34): [True: 0, False: 0]
  ------------------
 3507|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3508|       |
 3509|      0|		r = external_key_auth(card, kid, (unsigned char *)data->pin1.data,
 3510|      0|				data->pin1.len);
 3511|      0|		if (r == SC_ERROR_PIN_CODE_INCORRECT &&
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (3511:7): [True: 0, False: 0]
  ------------------
 3512|      0|				get_external_key_retries(card, 0x80 | kid, &retries) == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3512:5): [True: 0, False: 0]
  ------------------
 3513|      0|			data->pin1.tries_left = retries;
 3514|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3515|       |
 3516|      0|		r = update_secret_key(card, 0x04, kid, data->pin2.data,
 3517|      0|				(unsigned long)data->pin2.len);
 3518|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3519|      0|	} else {
 3520|      0|		r = external_key_auth(card, kid, (unsigned char *)data->pin1.data,
 3521|      0|				data->pin1.len);
 3522|      0|		if (r == SC_ERROR_PIN_CODE_INCORRECT &&
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (3522:7): [True: 0, False: 0]
  ------------------
 3523|      0|				get_external_key_retries(card, 0x80 | kid, &retries) == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3523:5): [True: 0, False: 0]
  ------------------
 3524|      0|			data->pin1.tries_left = retries;
 3525|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3526|       |
 3527|      0|		r = get_external_key_retries(card, 0x80 | kid, &retries);
 3528|      0|		if (retries < pin_low)
  ------------------
  |  Branch (3528:7): [True: 0, False: 0]
  ------------------
 3529|      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__
  |  |  ------------------
  ------------------
 3530|       |
 3531|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3532|      0|	}
 3533|       |
 3534|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3534:6): [True: 0, False: 0]
  ------------------
 3535|      0|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 3536|      0|	}
 3537|      0|	return r;
 3538|      0|}
card-epass2003.c:internal_sanitize_pin_info:
 3297|     38|{
 3298|     38|	pin->encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|     38|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 3299|     38|	pin->min_length = 4;
 3300|     38|	pin->max_length = 16;
 3301|     38|	pin->pad_length = 16;
 3302|     38|	pin->offset = 5 + num * 16;
 3303|     38|	pin->pad_char = 0x00;
 3304|     38|}
card-epass2003.c:get_external_key_retries:
 3333|     19|{
 3334|     19|	int r;
 3335|     19|	struct sc_apdu apdu;
 3336|     19|	unsigned char random[16] = {0};
 3337|       |
 3338|     19|	r = sc_get_challenge(card, random, 8);
 3339|     19|	LOG_TEST_RET(card->ctx, r, "get challenge get_external_key_retries 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: 12, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3340|       |
 3341|      7|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x82, 0x01, 0x80 | kid);
  ------------------
  |  |  291|      7|#define SC_APDU_CASE_1			0x01
  ------------------
 3342|      7|	apdu.resp = NULL;
 3343|      7|	apdu.resplen = 0;
 3344|       |
 3345|      7|	r = sc_transmit_apdu_t(card, &apdu);
 3346|      7|	LOG_TEST_RET(card->ctx, r, "APDU get_external_key_retries failed");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3347|       |
 3348|      6|	if (retries && ((0x63 == (apdu.sw1 & 0xff)) && (0xC0 == (apdu.sw2 & 0xf0)))) {
  ------------------
  |  Branch (3348:6): [True: 6, False: 0]
  |  Branch (3348:18): [True: 2, False: 4]
  |  Branch (3348:49): [True: 1, False: 1]
  ------------------
 3349|      1|		*retries = (apdu.sw2 & 0x0f);
 3350|      1|		r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 3351|      5|	} else {
 3352|      5|		LOG_TEST_RET(card->ctx, r, "get_external_key_retries 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: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3353|      5|		r = SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      5|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 3354|      5|	}
 3355|       |
 3356|      6|	return r;
 3357|      6|}
card-epass2003.c:get_external_key_maxtries:
 3309|      1|{
 3310|      1|	unsigned char maxcounter[2] = {0};
 3311|      1|	static const sc_path_t file_path = {
 3312|      1|		{0x3f, 0x00, 0x50, 0x15, 0x9f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 6,
 3313|      1|		0,
 3314|      1|		0,
 3315|      1|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|      1|#define SC_PATH_TYPE_PATH		2
  ------------------
 3316|      1|		{{0}, 0}
 3317|      1|	};
 3318|      1|	int ret;
 3319|       |
 3320|      1|	ret = sc_select_file(card, &file_path, NULL);
 3321|      1|	LOG_TEST_RET(card->ctx, ret, "select max counter file 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3322|       |
 3323|      0|	ret = sc_read_binary(card, 0, maxcounter, 2, 0);
 3324|      0|	LOG_TEST_RET(card->ctx, ret, "read max counter file 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3325|       |
 3326|      0|	*maxtries = maxcounter[0];
 3327|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 3328|      0|}
card-epass2003.c:epass2003_check_sw:
  253|  6.63k|{
  254|  6.63k|	const int err_count = sizeof(epass2003_errors)/sizeof(epass2003_errors[0]);
  255|  6.63k|	int i;
  256|       |
  257|       |	/* Handle special cases here */
  258|  6.63k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (258:6): [True: 53, False: 6.58k]
  ------------------
  259|     53|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  260|     53|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     53|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  261|     53|	}
  262|       |
  263|   305k|	for (i = 0; i < err_count; i++) {
  ------------------
  |  Branch (263:14): [True: 305k, False: 415]
  ------------------
  264|   305k|		if (epass2003_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (264:7): [True: 6.17k, False: 299k]
  ------------------
  265|  6.17k|			sc_log(card->ctx, "%s", epass2003_errors[i].errorstr);
  ------------------
  |  |   71|  6.17k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  266|  6.17k|			return epass2003_errors[i].errorno;
  267|  6.17k|		}
  268|   305k|	}
  269|       |
  270|    415|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|    415|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  271|    415|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    415|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  272|  6.58k|}
card-epass2003.c:epass2003_get_challenge:
 3361|     37|{
 3362|     37|	u8 rbuf[16];
 3363|     37|	size_t out_len;
 3364|     37|	int r;
 3365|       |
 3366|     37|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     37|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     37|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     37|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     37|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3367|       |
 3368|     37|	if (!rnd || len == 0)
  ------------------
  |  Branch (3368:6): [True: 0, False: 37]
  |  Branch (3368:14): [True: 0, False: 37]
  ------------------
 3369|     37|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3370|       |
 3371|     37|	r = epass2003_sm_restart(card);
 3372|     37|	LOG_TEST_RET(card->ctx, r, "Can not re-establish SM");
  ------------------
  |  |  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: 0, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3373|       |
 3374|     37|	r = iso_ops->get_challenge(card, rbuf, sizeof rbuf);
 3375|     37|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE cmd 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: 11, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3376|       |
 3377|     26|	if (len < (size_t) r) {
  ------------------
  |  Branch (3377:6): [True: 6, False: 20]
  ------------------
 3378|      6|		out_len = len;
 3379|     20|	} else {
 3380|     20|		out_len = (size_t) r;
 3381|     20|	}
 3382|     26|	memcpy(rnd, rbuf, out_len);
 3383|       |
 3384|     26|	LOG_FUNC_RETURN(card->ctx, (int) out_len);
  ------------------
  |  |  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: 1, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3385|     26|}
card-epass2003.c:epass2003_card_reader_lock_obtained:
 2261|  1.24k|{
 2262|       |	/* after a reset the current DF is either not set or set to an unknown
 2263|       |	 * value by a different application */
 2264|  1.24k|	if (was_reset > 0)
  ------------------
  |  Branch (2264:6): [True: 0, False: 1.24k]
  ------------------
 2265|      0|		epass2003_forget_cur_df(card);
 2266|  1.24k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.24k|#define SC_SUCCESS				0
  ------------------
 2267|  1.24k|}

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

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

sc_get_cryptoflex_driver:
 1203|  16.1k|{
 1204|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1204:6): [True: 0, False: 16.1k]
  ------------------
 1205|      0|		iso_ops = sc_get_iso7816_driver()->ops;
 1206|       |
 1207|  16.1k|	cryptoflex_ops = *iso_ops;
 1208|  16.1k|	cryptoflex_ops.match_card = cryptoflex_match_card;
 1209|  16.1k|	cryptoflex_ops.init = flex_init;
 1210|  16.1k|	cryptoflex_ops.finish = flex_finish;
 1211|  16.1k|	cryptoflex_ops.process_fci = cryptoflex_process_file_attrs;
 1212|  16.1k|	cryptoflex_ops.construct_fci = cryptoflex_construct_file_attrs;
 1213|  16.1k|	cryptoflex_ops.select_file = flex_select_file;
 1214|  16.1k|	cryptoflex_ops.list_files = cryptoflex_list_files;
 1215|  16.1k|	cryptoflex_ops.delete_file = flex_delete_file;
 1216|  16.1k|	cryptoflex_ops.create_file = flex_create_file;
 1217|  16.1k|	cryptoflex_ops.card_ctl = flex_card_ctl;
 1218|  16.1k|	cryptoflex_ops.set_security_env = flex_set_security_env;
 1219|  16.1k|	cryptoflex_ops.restore_security_env = flex_restore_security_env;
 1220|  16.1k|	cryptoflex_ops.compute_signature = cryptoflex_compute_signature;
 1221|  16.1k|	cryptoflex_ops.decipher = flex_decipher;
 1222|  16.1k|	cryptoflex_ops.pin_cmd = flex_pin_cmd;
 1223|  16.1k|	cryptoflex_ops.logout = flex_logout;
 1224|  16.1k|	return &cryptoflex_drv;
 1225|  16.1k|}
sc_get_cyberflex_driver:
 1228|  16.1k|{
 1229|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1229:6): [True: 1, False: 16.1k]
  ------------------
 1230|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 1231|       |
 1232|  16.1k|	cyberflex_ops = *iso_ops;
 1233|  16.1k|	cyberflex_ops.match_card = cyberflex_match_card;
 1234|  16.1k|	cyberflex_ops.init = flex_init;
 1235|  16.1k|	cyberflex_ops.finish = flex_finish;
 1236|  16.1k|	cyberflex_ops.process_fci = cyberflex_process_file_attrs;
 1237|  16.1k|	cyberflex_ops.construct_fci = cyberflex_construct_file_attrs;
 1238|  16.1k|	cyberflex_ops.select_file = flex_select_file;
 1239|  16.1k|	cyberflex_ops.list_files = cyberflex_list_files;
 1240|  16.1k|	cyberflex_ops.delete_file = flex_delete_file;
 1241|  16.1k|	cyberflex_ops.create_file = flex_create_file;
 1242|  16.1k|	cyberflex_ops.card_ctl = flex_card_ctl;
 1243|  16.1k|	cyberflex_ops.set_security_env = flex_set_security_env;
 1244|  16.1k|	cyberflex_ops.restore_security_env = flex_restore_security_env;
 1245|  16.1k|	cyberflex_ops.compute_signature = cyberflex_compute_signature;
 1246|  16.1k|	cyberflex_ops.decipher = flex_decipher;
 1247|  16.1k|	cyberflex_ops.pin_cmd = flex_pin_cmd;
 1248|  16.1k|	cyberflex_ops.logout = flex_logout;
 1249|  16.1k|	return &cyberflex_drv;
 1250|  16.1k|}
card-flex.c:cryptoflex_match_card:
  134|  15.7k|{
  135|  15.7k|	int i;
  136|       |
  137|  15.7k|	i = _sc_match_atr(card, flex_atrs, NULL);
  138|  15.7k|	if (i < 0)
  ------------------
  |  Branch (138:6): [True: 15.5k, False: 139]
  ------------------
  139|  15.5k|		return 0;
  140|    139|	switch (flex_atrs[i].type) {
  ------------------
  |  Branch (140:10): [True: 139, False: 0]
  ------------------
  141|    138|	case SC_CARD_TYPE_FLEX_CRYPTO:
  ------------------
  |  Branch (141:2): [True: 138, False: 1]
  ------------------
  142|    139|	case SC_CARD_TYPE_FLEX_MULTI:
  ------------------
  |  Branch (142:2): [True: 1, False: 138]
  ------------------
  143|    139|		card->name = flex_atrs[i].name;
  144|    139|		card->type = flex_atrs[i].type;
  145|    139|		card->flags = flex_atrs[i].flags;
  146|    139|		return 1;
  147|    139|	}
  148|      0|	return 0;
  149|    139|}
card-flex.c:flex_init:
  169|    139|{
  170|    139|	struct flex_private_data *data;
  171|       |
  172|    139|	if (!(data = malloc(sizeof(*data))))
  ------------------
  |  Branch (172:6): [True: 0, False: 139]
  ------------------
  173|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  174|    139|	card->drv_data = data;
  175|       |
  176|    139|	card->cla = 0xC0;
  177|    139|	data->aak_key_ref = 1;
  178|       |
  179|       |	/* Override Cryptoflex defaults for specific card types */
  180|    139|	switch (card->type) {
  ------------------
  |  Branch (180:10): [True: 0, False: 139]
  ------------------
  181|      0|	case SC_CARD_TYPE_FLEX_CYBER:
  ------------------
  |  Branch (181:2): [True: 0, False: 139]
  ------------------
  182|      0|		card->cla = 0x00;
  183|      0|		data->aak_key_ref = 0;
  184|      0|		break;
  185|    139|	}
  186|       |
  187|       |	/* FIXME: Card type detection */
  188|    139|	if (1) {
  ------------------
  |  Branch (188:6): [True: 139, Folded]
  ------------------
  189|    139|		unsigned long flags;
  190|       |
  191|    139|		flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    139|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  192|    139|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    139|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  193|    139|		if (card->flags & FLAG_KEYGEN)
  ------------------
  |  |   31|    139|#define FLAG_KEYGEN		0x80000000
  ------------------
  |  Branch (193:7): [True: 137, False: 2]
  ------------------
  194|    137|			flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    137|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  195|       |
  196|    139|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  197|    139|		_sc_card_add_rsa_alg(card, 768, flags, 0);
  198|    139|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  199|    139|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  200|    139|	}
  201|       |
  202|       |	/* SCardTransmit failed: 8010002f
  203|       |	 * this can be solved with a small delay. */
  204|    139|	msleep(100);
  ------------------
  |  |   59|    139|#define msleep(t)	usleep((t) * 1000)
  ------------------
  205|       |
  206|       |	/* State that we have an RNG */
  207|    139|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    139|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  208|       |
  209|    139|	return 0;
  210|    139|}
card-flex.c:flex_finish:
  128|    139|{
  129|    139|	free(card->drv_data);
  130|    139|	return 0;
  131|    139|}
card-flex.c:cryptoflex_process_file_attrs:
  270|    110|{
  271|    110|	sc_context_t *ctx = card->ctx;
  272|    110|	const u8 *p = buf + 2;
  273|    110|	u8 b1, b2;
  274|    110|	int is_mf = 0;
  275|       |
  276|    110|	if (buflen < 14)
  ------------------
  |  Branch (276:6): [True: 0, False: 110]
  ------------------
  277|      0|		return -1;
  278|    110|	b1 = *p++;
  279|    110|	b2 = *p++;
  280|    110|	file->size = (b1 << 8) + b2;
  281|    110|	b1 = *p++;
  282|    110|	b2 = *p++;
  283|    110|	file->id = (b1 << 8) + b2;
  284|    110|	if (file->id == 0x3F00)
  ------------------
  |  Branch (284:6): [True: 4, False: 106]
  ------------------
  285|      4|		is_mf = 1;
  286|    110|	switch (*p) {
  287|     45|	case 0x01:
  ------------------
  |  Branch (287:2): [True: 45, False: 65]
  ------------------
  288|     45|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     45|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  289|     45|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     45|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  290|     45|		break;
  291|     31|	case 0x02:
  ------------------
  |  Branch (291:2): [True: 31, False: 79]
  ------------------
  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|      8|	case 0x04:
  ------------------
  |  Branch (295:2): [True: 8, False: 102]
  ------------------
  296|      8|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      8|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  297|      8|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|      8|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  298|      8|		break;
  299|      9|	case 0x06:
  ------------------
  |  Branch (299:2): [True: 9, False: 101]
  ------------------
  300|      9|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|      9|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  301|      9|		file->ef_structure = SC_FILE_EF_CYCLIC;
  ------------------
  |  |  226|      9|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  302|      9|		break;
  303|      7|	case 0x38:
  ------------------
  |  Branch (303:2): [True: 7, False: 103]
  ------------------
  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: 100]
  ------------------
  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|    110|	}
  310|    100|	p += 2;
  311|    100|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    100|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (311:6): [True: 7, False: 93]
  ------------------
  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|     93|	} else { /* EF */
  316|     93|		add_acl_entry(card, file, SC_AC_OP_READ, (u8)(p[0] >> 4));
  ------------------
  |  |  188|     93|#define SC_AC_OP_READ			22
  ------------------
  317|     93|		switch (file->ef_structure) {
  ------------------
  |  Branch (317:11): [True: 93, False: 0]
  ------------------
  318|     45|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     45|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (318:3): [True: 45, False: 48]
  ------------------
  319|     45|			add_acl_entry(card, file, SC_AC_OP_UPDATE, (u8)(p[0] & 0x0F));
  ------------------
  |  |  189|     45|#define SC_AC_OP_UPDATE			23
  ------------------
  320|     45|			break;
  321|     31|		case SC_FILE_EF_LINEAR_FIXED:
  ------------------
  |  |  222|     31|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
  |  Branch (321:3): [True: 31, False: 62]
  ------------------
  322|     39|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     39|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (322:3): [True: 8, False: 85]
  ------------------
  323|     39|			add_acl_entry(card, file, SC_AC_OP_UPDATE, (u8)(p[0] & 0x0F));
  ------------------
  |  |  189|     39|#define SC_AC_OP_UPDATE			23
  ------------------
  324|     39|			break;
  325|      9|		case SC_FILE_EF_CYCLIC:
  ------------------
  |  |  226|      9|#define SC_FILE_EF_CYCLIC		0x06
  ------------------
  |  Branch (325:3): [True: 9, False: 84]
  ------------------
  326|      9|			break;
  327|     93|		}
  328|     93|	}
  329|    100|	if (file->type != SC_FILE_TYPE_DF || is_mf) {
  ------------------
  |  |  214|    200|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (329:6): [True: 93, False: 7]
  |  Branch (329:39): [True: 2, False: 5]
  ------------------
  330|     95|		add_acl_entry(card, file, SC_AC_OP_REHABILITATE, (u8)(p[2] >> 4));
  ------------------
  |  |  170|     95|#define SC_AC_OP_REHABILITATE		4
  ------------------
  331|     95|		add_acl_entry(card, file, SC_AC_OP_INVALIDATE, (u8)(p[2] & 0x0F));
  ------------------
  |  |  171|     95|#define SC_AC_OP_INVALIDATE		5
  ------------------
  332|     95|	}
  333|    100|	p += 3;
  334|    100|	if (*p)
  ------------------
  |  Branch (334:6): [True: 67, False: 33]
  ------------------
  335|     67|		file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     67|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  336|     33|	else
  337|     33|		file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     33|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  338|       |
  339|    100|	return cryptoflex_get_ac_keys(card, file);
  340|    100|}
card-flex.c:add_acl_entry:
  214|    388|{
  215|    388|	struct flex_private_data *prv = DRV_DATA(card);
  ------------------
  |  |  109|    388|#define DRV_DATA(card)	((struct flex_private_data *) (card)->drv_data)
  ------------------
  216|       |
  217|    388|	switch (nibble) {
  218|     91|	case 0:
  ------------------
  |  Branch (218:2): [True: 91, False: 297]
  ------------------
  219|     91|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|     91|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     91|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  220|     91|		break;
  221|     45|	case 1:
  ------------------
  |  Branch (221:2): [True: 45, False: 343]
  ------------------
  222|     45|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 1);
  ------------------
  |  |  151|     45|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  223|     45|		break;
  224|     31|	case 2:
  ------------------
  |  Branch (224:2): [True: 31, False: 357]
  ------------------
  225|     31|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 2);
  ------------------
  |  |  151|     31|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  226|     31|		break;
  227|     24|	case 3:
  ------------------
  |  Branch (227:2): [True: 24, False: 364]
  ------------------
  228|     24|		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  153|     24|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     24|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  229|     24|		break;
  230|     30|	case 4:
  ------------------
  |  Branch (230:2): [True: 30, False: 358]
  ------------------
  231|       |		/* Assume the key is the AAK */
  232|     30|		sc_file_add_acl_entry(file, op, SC_AC_AUT, prv->aak_key_ref);
  ------------------
  |  |  154|     30|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  233|     30|		break;
  234|     33|	case 6:
  ------------------
  |  Branch (234:2): [True: 33, False: 355]
  ------------------
  235|     33|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 1);
  ------------------
  |  |  151|     33|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  236|     33|		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  153|     33|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_PRO, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     33|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  237|     33|		break;
  238|     29|	case 7:
  ------------------
  |  Branch (238:2): [True: 29, False: 359]
  ------------------
  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|     20|	case 8:
  ------------------
  |  Branch (242:2): [True: 20, False: 368]
  ------------------
  243|     20|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 1);
  ------------------
  |  |  151|     20|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  244|       |		/* Assume the key is the AAK */
  245|     20|		sc_file_add_acl_entry(file, op, SC_AC_AUT, prv->aak_key_ref);
  ------------------
  |  |  154|     20|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  246|     20|		break;
  247|     15|	case 9:
  ------------------
  |  Branch (247:2): [True: 15, False: 373]
  ------------------
  248|     15|		sc_file_add_acl_entry(file, op, SC_AC_CHV, 2);
  ------------------
  |  |  151|     15|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  249|       |		/* Assume the key is the AAK */
  250|     15|		sc_file_add_acl_entry(file, op, SC_AC_AUT, prv->aak_key_ref);
  ------------------
  |  |  154|     15|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  251|     15|		break;
  252|     36|	case 15:
  ------------------
  |  Branch (252:2): [True: 36, False: 352]
  ------------------
  253|     36|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|     36|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     36|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  254|     36|		break;
  255|     34|	default:
  ------------------
  |  Branch (255:2): [True: 34, False: 354]
  ------------------
  256|     34|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|     34|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     34|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  257|     34|		break;
  258|    388|	}
  259|    388|}
card-flex.c:cryptoflex_get_ac_keys:
  263|    100|{
  264|    100|	return 0;
  265|    100|}
card-flex.c:flex_select_file:
  491|    731|{
  492|    731|	int r;
  493|    731|	const u8 *pathptr = path->value;
  494|    731|	size_t pathlen = path->len;
  495|    731|	int locked = 0;
  496|    731|	u8 p1 = 0;
  497|       |
  498|    731|	switch (path->type) {
  ------------------
  |  Branch (498:10): [True: 731, False: 0]
  ------------------
  499|    453|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|    453|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (499:2): [True: 453, False: 278]
  ------------------
  500|    453|		if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (500:7): [True: 0, False: 453]
  ------------------
  501|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  502|    453|		if (pathlen == 0)
  ------------------
  |  Branch (502:7): [True: 0, False: 453]
  ------------------
  503|      0|			return 0;
  504|    453|		if (pathlen != 2 || memcmp(pathptr, "\x3F\x00", 2) != 0) {
  ------------------
  |  Branch (504:7): [True: 434, False: 19]
  |  Branch (504:23): [True: 19, False: 0]
  ------------------
  505|    453|			locked = 1;
  506|    453|			r = sc_lock(card);
  507|    453|			LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    453|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    453|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    453|	int _ret = (r); \
  |  |  |  |  168|    453|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 453]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    453|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 453]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  508|    453|			if (memcmp(pathptr, "\x3F\x00", 2) != 0) {
  ------------------
  |  Branch (508:8): [True: 19, False: 434]
  ------------------
  509|     19|				r = select_file_id(card, (const u8 *) "\x3F\x00", 2, 0, NULL);
  510|     19|				if (r)
  ------------------
  |  Branch (510:9): [True: 8, False: 11]
  ------------------
  511|      8|					sc_unlock(card);
  512|     19|				LOG_TEST_RET(card->ctx, r, "Unable to select Master File (MF)");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 8, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      8|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      8|		return _ret; \
  |  |  |  |  172|      8|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|     19|			}
  514|    624|			while (pathlen > 2) {
  ------------------
  |  Branch (514:11): [True: 443, False: 181]
  ------------------
  515|    443|				r = select_file_id(card, pathptr, 2, 0, NULL);
  516|    443|				if (r)
  ------------------
  |  Branch (516:9): [True: 264, False: 179]
  ------------------
  517|    264|					sc_unlock(card);
  518|    443|				LOG_TEST_RET(card->ctx, r, "Unable to select DF");
  ------------------
  |  |  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: 264, False: 179]
  |  |  |  |  ------------------
  |  |  |  |  169|    264|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    264|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    264|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    264|		return _ret; \
  |  |  |  |  172|    264|	} \
  |  |  |  |  173|    443|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 179]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|    179|				pathptr += 2;
  520|    179|				pathlen -= 2;
  521|    179|			}
  522|    445|		}
  523|    181|		break;
  524|    278|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    278|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (524:2): [True: 278, False: 453]
  ------------------
  525|    278|		p1 = 0x04;
  526|    278|		break;
  527|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (527:2): [True: 0, False: 731]
  ------------------
  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|    731|	}
  532|    459|	r = select_file_id(card, pathptr, pathlen, p1, file_out);
  533|    459|	if (locked)
  ------------------
  |  Branch (533:6): [True: 181, False: 278]
  ------------------
  534|    181|		sc_unlock(card);
  535|    459|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    459|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    459|	int _ret = r; \
  |  |  155|    459|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 459, False: 0]
  |  |  ------------------
  |  |  156|    459|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    302|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 302, False: 157]
  |  |  ------------------
  |  |  157|    459|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    459|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    459|	return _ret; \
  |  |  163|    459|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  536|    459|}
card-flex.c:select_file_id:
  438|    921|{
  439|    921|	int r;
  440|    921|	sc_apdu_t apdu;
  441|    921|        u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  442|    921|        sc_file_t *file;
  443|       |
  444|    921|	sc_log(card->ctx,  "called, p1=%u\n", p1);
  ------------------
  |  |   71|    921|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  445|    921|	sc_log_hex(card->ctx, "path", buf, buflen);
  ------------------
  |  |  129|    921|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    921|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|       |
  447|    921|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, p1, 0);
  ------------------
  |  |  294|    921|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  448|    921|	apdu.resp = rbuf;
  449|    921|	apdu.resplen = sizeof(rbuf);
  450|    921|	apdu.datalen = buflen;
  451|    921|	apdu.data = buf;
  452|    921|	apdu.lc = buflen;
  453|    921|	apdu.le = 252;
  454|       |
  455|       |	/* No need to get file information, if file is NULL. */
  456|    921|	if (file_out == NULL) {
  ------------------
  |  Branch (456:6): [True: 755, False: 166]
  ------------------
  457|    755|		apdu.cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|    755|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  458|    755|		apdu.le = 0;
  459|    755|	}
  460|    921|	r = sc_transmit_apdu(card, &apdu);
  461|    921|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    921|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    921|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    921|	int _ret = (r); \
  |  |  |  |  168|    921|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 906]
  |  |  |  |  ------------------
  |  |  |  |  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|    921|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 906]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  462|    906|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  463|    906|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|    906|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    906|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    906|	int _ret = (r); \
  |  |  |  |  168|    906|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 524, False: 382]
  |  |  |  |  ------------------
  |  |  |  |  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|    906|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 382]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  464|       |
  465|    382|	if (file_out == NULL)
  ------------------
  |  Branch (465:6): [True: 247, False: 135]
  ------------------
  466|    247|		return 0;
  467|       |
  468|    135|	if (apdu.resplen < 14)
  ------------------
  |  Branch (468:6): [True: 18, False: 117]
  ------------------
  469|     18|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     18|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  470|    117|	if (apdu.resp[0] == 0x6F) {
  ------------------
  |  Branch (470:6): [True: 7, False: 110]
  ------------------
  471|      7|		sc_log(card->ctx,  "unsupported: card returned FCI\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  472|      7|		return SC_ERROR_UNKNOWN_DATA_RECEIVED; /* FIXME */
  ------------------
  |  |   63|      7|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
  473|      7|	}
  474|    110|	file = sc_file_new();
  475|    110|	if (file == NULL)
  ------------------
  |  Branch (475:6): [True: 0, False: 110]
  ------------------
  476|    110|		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|    110|	r = card->ops->process_fci(card, file, apdu.resp, apdu.resplen);
  480|    110|	if (r) {
  ------------------
  |  Branch (480:6): [True: 10, False: 100]
  ------------------
  481|     10|		sc_file_free(file);
  482|     10|		return r;
  483|     10|	}
  484|       |
  485|    100|	*file_out = file;
  486|    100|	return 0;
  487|    110|}
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: 7, False: 6]
  ------------------
 1069|      7|		return r;
 1070|      6|	len = tfile->size;
 1071|      6|	sc_file_free(tfile);
 1072|      6|	if (len != 8) {
  ------------------
  |  Branch (1072:6): [True: 4, False: 2]
  ------------------
 1073|      4|		sc_log(card->ctx,  "unexpected file length of EF_ICCSN (%lu)\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__
  |  |  ------------------
  ------------------
 1074|      4|			(unsigned long) len);
 1075|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1076|      4|	}
 1077|      2|	r = sc_read_binary(card, 0, buf, len, 0);
 1078|      2|	if (r < 0)
  ------------------
  |  Branch (1078:6): [True: 1, False: 1]
  ------------------
 1079|      1|		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|      2|}
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|  15.7k|{
  153|  15.7k|	int i;
  154|       |
  155|  15.7k|	i = _sc_match_atr(card, flex_atrs, NULL);
  156|  15.7k|	if (i < 0)
  ------------------
  |  Branch (156:6): [True: 15.5k, False: 139]
  ------------------
  157|  15.5k|		return 0;
  158|    139|	switch (flex_atrs[i].type) {
  ------------------
  |  Branch (158:10): [True: 0, False: 139]
  ------------------
  159|      0|	case SC_CARD_TYPE_FLEX_CYBER:
  ------------------
  |  Branch (159:2): [True: 0, False: 139]
  ------------------
  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|    139|	}
  165|    139|	return 0;
  166|    139|}

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

sc_get_gids_driver:
 2202|  16.1k|{
 2203|  16.1k|	return sc_get_driver();
 2204|  16.1k|}
card-gids.c:sc_get_driver:
 2157|  16.1k|{
 2158|       |
 2159|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2159:6): [True: 1, False: 16.1k]
  ------------------
 2160|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2161|       |
 2162|  16.1k|	gids_ops.match_card = gids_match_card;
 2163|  16.1k|	gids_ops.init = gids_init;
 2164|  16.1k|	gids_ops.finish = gids_finish;
 2165|  16.1k|	gids_ops.read_binary = gids_read_binary;
 2166|  16.1k|	gids_ops.write_binary = NULL;
 2167|  16.1k|	gids_ops.update_binary = NULL;
 2168|  16.1k|	gids_ops.erase_binary = NULL;
 2169|  16.1k|	gids_ops.read_record = NULL;
 2170|  16.1k|	gids_ops.write_record = NULL;
 2171|  16.1k|	gids_ops.append_record = NULL;
 2172|  16.1k|	gids_ops.update_record = NULL;
 2173|  16.1k|	gids_ops.select_file = gids_select_file;
 2174|  16.1k|	gids_ops.get_response = iso_ops->get_response;
 2175|  16.1k|	gids_ops.get_challenge = NULL;
 2176|  16.1k|	gids_ops.verify = NULL; // see pin_cmd
 2177|  16.1k|	gids_ops.logout = gids_logout;
 2178|  16.1k|	gids_ops.restore_security_env = NULL;
 2179|  16.1k|	gids_ops.set_security_env = gids_set_security_env;
 2180|  16.1k|	gids_ops.decipher = gids_decipher;
 2181|  16.1k|	gids_ops.compute_signature = iso_ops->compute_signature;
 2182|  16.1k|	gids_ops.change_reference_data = NULL; // see pin_cmd
 2183|  16.1k|	gids_ops.reset_retry_counter = NULL; // see pin_cmd
 2184|  16.1k|	gids_ops.create_file = iso_ops->create_file;
 2185|  16.1k|	gids_ops.delete_file = NULL;
 2186|  16.1k|	gids_ops.list_files = NULL;
 2187|  16.1k|	gids_ops.check_sw = iso_ops->check_sw;
 2188|  16.1k|	gids_ops.card_ctl = gids_card_ctl;
 2189|  16.1k|	gids_ops.process_fci = iso_ops->process_fci;
 2190|  16.1k|	gids_ops.construct_fci = iso_ops->construct_fci;
 2191|  16.1k|	gids_ops.pin_cmd = gids_pin_cmd;
 2192|  16.1k|	gids_ops.get_data = NULL;
 2193|  16.1k|	gids_ops.put_data = NULL;
 2194|  16.1k|	gids_ops.delete_record = NULL;
 2195|  16.1k|	gids_ops.read_public_key = gids_read_public_key;
 2196|  16.1k|	gids_ops.card_reader_lock_obtained = gids_card_reader_lock_obtained;
 2197|       |
 2198|  16.1k|	return &gids_drv;
 2199|  16.1k|}
card-gids.c:gids_match_card:
  563|  3.68k|{
  564|  3.68k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  565|  3.68k|	int r,i;
  566|  3.68k|	size_t resplen = sizeof(rbuf);
  567|  3.68k|	const u8 *tag;
  568|  3.68k|	size_t taglen;
  569|  3.68k|	const u8 *aid;
  570|  3.68k|	size_t aidlen;
  571|       |
  572|  3.68k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  573|       |
  574|       |	/* Detect by selecting applet */
  575|  3.68k|	r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
  576|  3.68k|	if (r<0) return 0;
  ------------------
  |  Branch (576:6): [True: 3.56k, False: 113]
  ------------------
  577|       |
  578|    113|	card->type = SC_CARD_TYPE_GIDS_GENERIC;
  579|    113|	if (resplen > 2) {
  ------------------
  |  Branch (579:6): [True: 12, False: 101]
  ------------------
  580|     12|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, GIDS_APPLICATION_TEMPLATE_TAG, &taglen);
  ------------------
  |  |  105|     12|#define GIDS_APPLICATION_TEMPLATE_TAG 0x61
  ------------------
  581|     12|		if (tag != NULL) {
  ------------------
  |  Branch (581:7): [True: 9, False: 3]
  ------------------
  582|      9|			aid = sc_asn1_find_tag(card->ctx, tag, taglen, GIDS_APPLICATION_AID_TAG, &aidlen);
  ------------------
  |  |  106|      9|#define GIDS_APPLICATION_AID_TAG 0x4F
  ------------------
  583|      9|			if (aid != NULL ) {
  ------------------
  |  Branch (583:8): [True: 8, False: 1]
  ------------------
  584|      8|				sc_log(card->ctx, "found AID");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  585|     22|				for (i = 0; gids_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (585:17): [True: 15, False: 7]
  ------------------
  586|     15|					if ( aidlen > gids_aids[i].len_long && memcmp(aid, gids_aids[i].value,
  ------------------
  |  Branch (586:11): [True: 13, False: 2]
  |  Branch (586:45): [True: 1, False: 12]
  ------------------
  587|     13|									gids_aids[i].len_long) == 0) {
  588|      1|						card->type = gids_aids[i].enumtag;
  589|      1|						break;
  590|      1|					}
  591|     15|				}
  592|      8|			}
  593|      9|		}
  594|     12|	}
  595|       |
  596|    113|	return 1;
  597|  3.68k|}
card-gids.c:gids_select_aid:
  280|  3.68k|{
  281|  3.68k|	sc_apdu_t apdu;
  282|  3.68k|	int r;
  283|       |
  284|  3.68k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  285|  3.68k|	sc_log(card->ctx, "Got args: aid=%p, aidlen=%zu, response=%p, responselen=%zu",
  ------------------
  |  |   71|  7.36k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 3.68k, False: 0]
  |  |  ------------------
  ------------------
  286|  3.68k|			aid, aidlen, response, responselen ? *responselen : 0);
  287|       |
  288|  3.68k|	sc_format_apdu(card, &apdu,
  289|  3.68k|		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.68k|#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.68k|#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.68k|#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.68k|#define P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00
  ------------------
  |  Branch (289:3): [True: 0, False: 3.68k]
  ------------------
  290|  3.68k|	apdu.lc = aidlen;
  291|  3.68k|	apdu.data = aid;
  292|  3.68k|	apdu.datalen = aidlen;
  293|  3.68k|	apdu.resp = response;
  294|  3.68k|	apdu.resplen = responselen ? *responselen : 0;
  ------------------
  |  Branch (294:17): [True: 3.68k, False: 0]
  ------------------
  295|  3.68k|	apdu.le = response == NULL ? 0 : 256; /* could be 21 for fci */
  ------------------
  |  Branch (295:12): [True: 0, False: 3.68k]
  ------------------
  296|       |
  297|  3.68k|	r = sc_transmit_apdu(card, &apdu);
  298|  3.68k|	if (responselen)
  ------------------
  |  Branch (298:6): [True: 3.68k, False: 0]
  ------------------
  299|  3.68k|		*responselen = apdu.resplen;
  300|  3.68k|	LOG_TEST_RET(card->ctx, r, "gids select failed");
  ------------------
  |  |  174|  3.68k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.68k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.68k|	int _ret = (r); \
  |  |  |  |  168|  3.68k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 3.66k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.68k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.66k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|  3.66k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  153|  3.66k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  3.66k|	int _ret = r; \
  |  |  155|  3.66k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 3.66k, False: 0]
  |  |  ------------------
  |  |  156|  3.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|  3.54k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 3.54k, False: 113]
  |  |  ------------------
  |  |  157|  3.66k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  3.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|  3.66k|	return _ret; \
  |  |  163|  3.66k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  302|  3.66k|}
card-gids.c:gids_init:
  631|    113|{
  632|    113|	unsigned long flags;
  633|    113|	struct gids_private_data *data;
  634|    113|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    113|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    113|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    113|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 113]
  |  |  ------------------
  ------------------
  635|       |
  636|       |	// cache some data in memory
  637|    113|	data = (struct gids_private_data*) calloc(1, sizeof(struct gids_private_data));
  638|    113|	if (!data) {
  ------------------
  |  Branch (638:6): [True: 0, False: 113]
  ------------------
  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|    113|	memset(data, 0, sizeof(struct gids_private_data));
  642|    113|	card->drv_data = data;
  643|       |	// invalidate the master file and cmap file cache
  644|    113|	data->cmapfilesize = sizeof(data->cmapfile);
  645|    113|	data->masterfilesize = sizeof(data->masterfile);
  646|       |
  647|       |	/* supported RSA keys and how padding is done */
  648|    113|	flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|    113|#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|    113|#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|    113|#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|    113|#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|    113|#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|    113|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  652|    113|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  653|    113|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
  654|    113|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  655|       |
  656|    113|	return SC_SUCCESS;
  ------------------
  |  |   28|    113|#define SC_SUCCESS				0
  ------------------
  657|    113|}
card-gids.c:gids_finish:
  661|    113|{
  662|    113|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    113|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    113|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    113|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 113]
  |  |  ------------------
  ------------------
  663|       |	/* free the private data */
  664|    113|	if (card->drv_data) {
  ------------------
  |  Branch (664:6): [True: 113, False: 0]
  ------------------
  665|    113|		free(card->drv_data);
  666|       |		card->drv_data = NULL;
  667|    113|	}
  668|    113|	return 0;
  669|    113|}
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|    118|static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdentifier, u8* response, size_t *responselen) {
  211|    118|	sc_apdu_t apdu;
  212|    118|	int r;
  213|    118|	u8 data[4] = {0x5C, 0x02, (dataObjectIdentifier&0xFF00)>>8, (dataObjectIdentifier&0xFF)};
  214|    118|	size_t datasize = 0;
  215|    118|	const u8* p;
  216|    118|	u8 buffer[MAX_GIDS_FILE_SIZE];
  217|    118|	size_t buffer_len = sizeof(buffer);
  218|       |
  219|    118|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    118|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    118|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    118|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 118]
  |  |  ------------------
  ------------------
  220|    118|	sc_log(card->ctx, "Got args: fileIdentifier=%x, dataObjectIdentifier=%x, response=%p, responselen=%zu",
  ------------------
  |  |   71|    236|#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: 118, False: 0]
  |  |  ------------------
  ------------------
  221|    118|			fileIdentifier, dataObjectIdentifier, response, responselen ? *responselen : 0);
  222|       |
  223|    118|	sc_format_apdu(card, &apdu,
  224|    118|		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|    118|#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|    118|#define INS_GET_DATA 0xCB
  ------------------
  |  Branch (224:3): [True: 0, False: 118]
  ------------------
  225|    118|	apdu.lc = 04;
  226|    118|	apdu.data = data;
  227|    118|	apdu.datalen = 04;
  228|    118|	apdu.resp = buffer;
  229|    118|	apdu.resplen = buffer_len;
  230|    118|	apdu.le = 256;
  231|       |
  232|    118|	r = sc_transmit_apdu(card, &apdu);
  233|    118|	LOG_TEST_RET(card->ctx, r, "gids get data failed");
  ------------------
  |  |  174|    118|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    118|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    118|	int _ret = (r); \
  |  |  |  |  168|    118|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 115]
  |  |  |  |  ------------------
  |  |  |  |  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|    118|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 115]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|    115|	LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
  ------------------
  |  |  174|    115|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    115|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    115|	int _ret = (r); \
  |  |  |  |  168|    115|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 21, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  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|    115|} 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|    574|			   struct sc_file **file_out) {
  965|    574|	struct sc_file *file = NULL;
  966|    574|	struct sc_context *ctx = card->ctx;
  967|    574|	struct gids_private_data *data = (struct gids_private_data *) card->drv_data;
  968|       |
  969|    574|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    574|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    574|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    574|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    574|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 574]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  970|       |
  971|    574|	data->state = GIDS_STATE_NONE;
  ------------------
  |  |   57|    574|#define GIDS_STATE_NONE 0
  ------------------
  972|    574|	data->currentDO = 0;
  973|    574|	data->currentEFID = 0;
  974|    574|	if (in_path->len == 4 && in_path->value[0] == 0xA0) {
  ------------------
  |  Branch (974:6): [True: 332, False: 242]
  |  Branch (974:27): [True: 0, False: 332]
  ------------------
  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|    574|	} 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: 332, False: 242]
  |  Branch (991:34): [True: 332, False: 0]
  |  Branch (991:63): [True: 0, False: 332]
  |  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|    574|	} else {
 1002|    574|		return iso_ops->select_file(card, in_path, file_out);
 1003|    574|	}
 1004|    574|}
card-gids.c:gids_card_ctl:
 2106|    119|{
 2107|    119|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    119|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    119|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    119|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    119|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 119]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2108|    119|	switch (cmd) {
 2109|      6|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (2109:3): [True: 6, False: 113]
  ------------------
 2110|      6|			return gids_get_serialnr(card, (sc_serial_number_t *) ptr);
 2111|    113|		case SC_CARDCTL_GIDS_GET_ALL_CONTAINERS:
  ------------------
  |  Branch (2111:3): [True: 113, False: 6]
  ------------------
 2112|    113|			return gids_get_all_containers(card, (size_t*) ptr);
 2113|      0|		case SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL:
  ------------------
  |  Branch (2113:3): [True: 0, False: 119]
  ------------------
 2114|      0|			return gids_get_container_detail(card, (sc_cardctl_gids_get_container_t*) ptr);
 2115|      0|		case SC_CARDCTL_GIDS_SELECT_KEY_REFERENCE:
  ------------------
  |  Branch (2115:3): [True: 0, False: 119]
  ------------------
 2116|      0|			return gids_select_key_reference(card, (sc_pkcs15_prkey_info_t*) ptr);
 2117|      0|		case SC_CARDCTL_GIDS_CREATE_KEY:
  ------------------
  |  Branch (2117:3): [True: 0, False: 119]
  ------------------
 2118|      0|			return gids_create_keyfile(card, (sc_pkcs15_object_t*) ptr);
 2119|      0|		case SC_CARDCTL_GIDS_GENERATE_KEY:
  ------------------
  |  Branch (2119:3): [True: 0, False: 119]
  ------------------
 2120|      0|			return gids_generate_key(card, ((struct sc_cardctl_gids_genkey*) ptr)->object, ((struct sc_cardctl_gids_genkey*) ptr)->pubkey);
 2121|      0|		case SC_CARDCTL_GIDS_IMPORT_KEY:
  ------------------
  |  Branch (2121:3): [True: 0, False: 119]
  ------------------
 2122|      0|			return gids_import_key(card, ((struct sc_cardctl_gids_importkey*) ptr)->object, ((struct sc_cardctl_gids_importkey*) ptr)->key);
 2123|      0|		case SC_CARDCTL_GIDS_SAVE_CERT:
  ------------------
  |  Branch (2123:3): [True: 0, False: 119]
  ------------------
 2124|      0|			return gids_save_certificate(card, ((struct sc_cardctl_gids_save_cert*) ptr)->certobject,
 2125|      0|										((struct sc_cardctl_gids_save_cert*) ptr)->privkeyobject, ((struct sc_cardctl_gids_save_cert*) ptr)->path);
 2126|      0|		case SC_CARDCTL_GIDS_DELETE_CERT:
  ------------------
  |  Branch (2126:3): [True: 0, False: 119]
  ------------------
 2127|      0|			return gids_delete_cert(card, (sc_pkcs15_object_t*) ptr);
 2128|      0|		case SC_CARDCTL_GIDS_DELETE_KEY:
  ------------------
  |  Branch (2128:3): [True: 0, False: 119]
  ------------------
 2129|      0|			return gids_delete_key(card, (sc_pkcs15_object_t*) ptr);
 2130|      0|		case SC_CARDCTL_GIDS_INITIALIZE:
  ------------------
  |  Branch (2130:3): [True: 0, False: 119]
  ------------------
 2131|      0|			return gids_initialize(card, (sc_cardctl_gids_init_param_t*) ptr);
 2132|      0|		case SC_CARDCTL_GIDS_SET_ADMIN_KEY:
  ------------------
  |  Branch (2132:3): [True: 0, False: 119]
  ------------------
 2133|      0|			return gids_set_administrator_key(card, (u8*) ptr);
 2134|      0|		case SC_CARDCTL_GIDS_AUTHENTICATE_ADMIN:
  ------------------
  |  Branch (2134:3): [True: 0, False: 119]
  ------------------
 2135|      0|			return gids_authenticate_admin(card, (u8*) ptr);
 2136|      0|		default:
  ------------------
  |  Branch (2136:3): [True: 0, False: 119]
  ------------------
 2137|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2138|    119|	}
 2139|    119|}
card-gids.c:gids_get_serialnr:
  602|      6|{
  603|      6|	int r;
  604|      6|	u8 buffer[SC_MAX_EXT_APDU_BUFFER_SIZE];
  605|      6|	size_t buffersize;
  606|       |
  607|      6|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      6|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  ------------------
  ------------------
  608|       |
  609|      6|	buffersize = sizeof(buffer);
  610|      6|	r = gids_read_gidsfile(card, "", "cardid", buffer, &buffersize);
  611|      6|	LOG_TEST_RET(card->ctx, r, "unable to read cardid");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|      0|	if (SC_MAX_SERIALNR < buffersize)
  ------------------
  |  |  373|      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|     89|static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename, u8* response, size_t *responselen) {
  386|     89|	struct gids_private_data* privatedata = (struct gids_private_data*) card->drv_data;
  387|     89|	int r;
  388|     89|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  389|     89|	if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
  ------------------
  |  Branch (389:6): [True: 4, False: 85]
  ------------------
  390|      4|		r = gids_read_masterfile(card);
  391|      4|		LOG_TEST_RET(card->ctx, r, "unable to get the masterfile");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      3|		return _ret; \
  |  |  |  |  172|      3|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|      4|	}
  393|     86|	r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
  394|     86|		directory, filename, response, responselen);
  395|     86|	LOG_TEST_RET(card->ctx, r, "unable to read the file");
  ------------------
  |  |  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: 86, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     86|} 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|    117|static int gids_read_masterfile(sc_card_t* card) {
  341|    117|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  342|    117|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    117|#define SC_SUCCESS				0
  ------------------
  343|       |
  344|    117|	data->masterfilesize = sizeof(data->masterfile);
  345|    117|	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   66|    117|#define MF_FI UserCreateDeleteDirAc_FI
  |  |  ------------------
  |  |  |  |   63|    117|#define UserCreateDeleteDirAc_FI 0xA000
  |  |  ------------------
  ------------------
              	r = gids_get_DO(card, MF_FI, MF_DO, data->masterfile, &data->masterfilesize);
  ------------------
  |  |   67|    117|#define MF_DO 0xDF1F
  ------------------
  346|    117|	if (r<0) {
  ------------------
  |  Branch (346:6): [True: 28, False: 89]
  ------------------
  347|     28|		data->masterfilesize = sizeof(data->masterfile);
  348|     28|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|     28|	}
  350|     89|	if (data->masterfilesize < 1 || data->masterfile[0] != 1) {
  ------------------
  |  Branch (350:6): [True: 1, False: 88]
  |  Branch (350:34): [True: 4, False: 84]
  ------------------
  351|      5|		data->masterfilesize = sizeof(data->masterfile);
  352|      5|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|      5|	}
  354|     84|	return r;
  355|     89|}
card-gids.c:gids_read_gidsfile_without_cache:
  308|     86|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|     86|	int r;
  310|     86|	int fileIdentifier;
  311|     86|	int dataObjectIdentifier;
  312|       |
  313|     86|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     86|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     86|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     86|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 86]
  |  |  ------------------
  ------------------
  314|     86|	r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
  315|     86|	LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
  ------------------
  |  |  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: 85, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|     85|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     85|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     85|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     85|		return _ret; \
  |  |  |  |  172|     85|	} \
  |  |  |  |  173|     86|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|      1|	r = gids_get_DO(card, fileIdentifier, dataObjectIdentifier, response, responselen);
  317|      1|	LOG_TEST_RET(card->ctx, r, "unable to get the data from the file");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|      0|	return r;
  319|      1|}
card-gids.c:gids_get_identifiers:
  163|     86|static int gids_get_identifiers(sc_card_t* card, u8* masterfile, size_t masterfilesize, char *directory, char *filename, int *fileIdentifier, int *dataObjectIdentifier) {
  164|     86|	gids_mf_record_t *records = (gids_mf_record_t *) (masterfile+1);
  165|     86|	size_t recordcount = ((masterfilesize-1) / sizeof(gids_mf_record_t));
  166|     86|	size_t i;
  167|     86|	if (masterfilesize < 1)
  ------------------
  |  Branch (167:6): [True: 0, False: 86]
  ------------------
  168|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  169|       |
  170|    318|	for (i = 0; i < recordcount; i++) {
  ------------------
  |  Branch (170:14): [True: 233, False: 85]
  ------------------
  171|    233|		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: 62, False: 171]
  |  Branch (171:86): [True: 1, False: 61]
  ------------------
  172|      1|			*fileIdentifier = records[i].fileIdentifier;
  173|      1|			*dataObjectIdentifier = records[i].dataObjectIdentifier;
  174|      1|			sc_log(card->ctx,
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  175|      1|		"Identifiers of %s %s is fileIdentifier=%x, dataObjectIdentifier=%x\n", directory, filename, *fileIdentifier, *dataObjectIdentifier);
  176|      1|			return 0;
  177|      1|		}
  178|    233|	}
  179|     85|	sc_log(card->ctx, "file %s %s not found\n", directory, filename);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  180|     85|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     85|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  181|     86|}
card-gids.c:gids_get_all_containers:
 1074|    113|gids_get_all_containers(sc_card_t* card, size_t *recordsnum) {
 1075|    113|	int r;
 1076|    113|	struct gids_private_data *privatedata = (struct gids_private_data *) card->drv_data;
 1077|    113|	r = gids_read_masterfile(card);
 1078|    113|	LOG_TEST_RET(card->ctx, r, "unable to read the masterfile");
  ------------------
  |  |  174|    113|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    113|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    113|	int _ret = (r); \
  |  |  |  |  168|    113|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 30, False: 83]
  |  |  |  |  ------------------
  |  |  |  |  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|    113|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 83]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|     83|	r = gids_read_cmapfile(card);
 1080|     83|	LOG_TEST_RET(card->ctx, r, "unable to read the cmapfile");
  ------------------
  |  |  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: 83, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     83|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     83|		return _ret; \
  |  |  |  |  172|     83|	} \
  |  |  |  |  173|     83|} 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|     83|}
card-gids.c:gids_read_cmapfile:
  427|     83|static int gids_read_cmapfile(sc_card_t* card) {
  428|     83|	struct gids_private_data* data = (struct gids_private_data*) card->drv_data;
  429|     83|	int r = SC_SUCCESS;
  ------------------
  |  |   28|     83|#define SC_SUCCESS				0
  ------------------
  430|       |
  431|     83|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     83|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     83|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     83|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 83]
  |  |  ------------------
  ------------------
  432|     83|	data->cmapfilesize = sizeof(data->cmapfile);
  433|     83|	r = gids_read_gidsfile(card, "mscp", "cmapfile", data->cmapfile, &data->cmapfilesize);
  434|     83|	if (r<0) {
  ------------------
  |  Branch (434:6): [True: 83, False: 0]
  ------------------
  435|     83|		data->cmapfilesize = sizeof(data->cmapfile);
  436|     83|	}
  437|     83|	LOG_TEST_RET(card->ctx, r, "unable to get the cmapfile");
  ------------------
  |  |  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: 83, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     83|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     83|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     83|		return _ret; \
  |  |  |  |  172|     83|	} \
  |  |  |  |  173|     83|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  438|      0|	return r;
  439|     83|}
card-gids.c:gids_pin_cmd:
 1022|      6|gids_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1023|      6|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|      6|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1023:6): [True: 6, False: 0]
  ------------------
 1024|      6|		return gids_get_pin_policy(card, data);
 1025|      6|	} else {
 1026|      0|		return iso_ops->pin_cmd(card, data);
 1027|      0|	}
 1028|      6|}
card-gids.c:gids_get_pin_policy:
 1006|      6|static int gids_get_pin_policy(struct sc_card *card, struct sc_pin_cmd_data *data) {
 1007|      6|	int r;
 1008|      6|	if (data->pin_type != SC_AC_CHV) {
  ------------------
  |  |  151|      6|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1008:6): [True: 0, False: 6]
  ------------------
 1009|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1010|      0|	}
 1011|      6|	r = gids_get_pin_status(card, data->pin_reference, &(data->pin1.tries_left), &(data->pin1.max_tries));
 1012|      6|	LOG_TEST_RET(card->ctx, r, "gids_get_pin_status failed");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1013|      0|	data->pin1.max_length = 16;
 1014|      0|	data->pin1.min_length = 4;
 1015|      0|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1016|      0|	data->pin1.offset = 5;
 1017|      0|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1018|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1019|      6|}
card-gids.c:gids_get_pin_status:
  516|      6|static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_left, int *max_tries) {
  517|      6|	int dataObjectIdentifier, r;
  518|      6|	u8 buffer[100];
  519|      6|	const u8* p;
  520|      6|	size_t buffersize = sizeof(buffer);
  521|      6|	size_t datasize;
  522|       |
  523|      6|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|      6|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      6|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      6|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6]
  |  |  ------------------
  ------------------
  524|      6|	if (tries_left) *tries_left = -1;
  ------------------
  |  Branch (524:6): [True: 6, False: 0]
  ------------------
  525|      6|	if (max_tries) *max_tries = -1;
  ------------------
  |  Branch (525:6): [True: 6, False: 0]
  ------------------
  526|      6|	switch(pinreference) {
  527|      0|	case GIDS_PIN_IDENTIFIER:
  ------------------
  |  |  100|      0|#define GIDS_PIN_IDENTIFIER 0x80
  ------------------
  |  Branch (527:2): [True: 0, False: 6]
  ------------------
  528|      0|		dataObjectIdentifier = GIDS_PIN_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   80|      0|#define GIDS_PIN_STATUS_OBJECT_IDENTIFIER 0x7F71
  ------------------
  529|      0|		break;
  530|      0|	case GIDS_PUK_IDENTIFIER:
  ------------------
  |  |  101|      0|#define GIDS_PUK_IDENTIFIER 0x81
  ------------------
  |  Branch (530:2): [True: 0, False: 6]
  ------------------
  531|      0|		dataObjectIdentifier = GIDS_PUK_STATUS_OBJECT_IDENTIFIER;
  ------------------
  |  |   81|      0|#define GIDS_PUK_STATUS_OBJECT_IDENTIFIER 0x7F73
  ------------------
  532|      0|		break;
  533|      6|	default:
  ------------------
  |  Branch (533:2): [True: 6, False: 0]
  ------------------
  534|      6|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      6|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      6|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      6|	return _ret; \
  |  |  |  |  163|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  535|      6|	}
  536|      0|	r = gids_get_DO(card, GIDS_APPLET_EFID, dataObjectIdentifier, buffer, &buffersize);
  ------------------
  |  |   82|      0|#define GIDS_APPLET_EFID 0x3FFF
  ------------------
  537|      0|	LOG_TEST_RET(card->ctx, r, "unable to update the masterfile");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|       |
  539|      0|	buffersize = buffersize > sizeof(buffer) ? sizeof(buffer) : buffersize;
  ------------------
  |  Branch (539:15): [True: 0, False: 0]
  ------------------
  540|       |
  541|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_OLD_TAG, &datasize);
  ------------------
  |  |  102|      0|#define GIDS_TRY_COUNTER_OLD_TAG 0x9F17
  ------------------
  542|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (542:6): [True: 0, False: 0]
  |  Branch (542:11): [True: 0, False: 0]
  ------------------
  543|      0|		if (tries_left)
  ------------------
  |  Branch (543:7): [True: 0, False: 0]
  ------------------
  544|      0|			*tries_left = p[0];
  545|      0|	}
  546|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_TRY_COUNTER_TAG, &datasize);
  ------------------
  |  |  103|      0|#define GIDS_TRY_COUNTER_TAG 0x97
  ------------------
  547|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (547:6): [True: 0, False: 0]
  |  Branch (547:11): [True: 0, False: 0]
  ------------------
  548|      0|		if (tries_left)
  ------------------
  |  Branch (548:7): [True: 0, False: 0]
  ------------------
  549|      0|			*tries_left = p[0];
  550|      0|	}
  551|      0|	p = sc_asn1_find_tag(card->ctx, buffer, buffersize , GIDS_TRY_LIMIT_TAG, &datasize);
  ------------------
  |  |  104|      0|#define GIDS_TRY_LIMIT_TAG 0x93
  ------------------
  552|      0|	if (p && datasize == 1) {
  ------------------
  |  Branch (552:6): [True: 0, False: 0]
  |  Branch (552:11): [True: 0, False: 0]
  ------------------
  553|      0|		if (max_tries)
  ------------------
  |  Branch (553:7): [True: 0, False: 0]
  ------------------
  554|      0|			*max_tries = p[0];
  555|      0|	}
  556|       |
  557|      0|	sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 0]
  |  |  |  Branch (71:122): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  558|      0|		"Pin information for PIN 0x%x: triesleft=%d trieslimit=%d\n", pinreference, (tries_left?*tries_left:-1), (max_tries?*max_tries:-1));
  559|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|      0|}
card-gids.c:gids_card_reader_lock_obtained:
 2142|  3.79k|{
 2143|  3.79k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.79k|#define SC_SUCCESS				0
  ------------------
 2144|       |
 2145|  3.79k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.79k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.79k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.79k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.79k]
  |  |  ------------------
  ------------------
 2146|       |
 2147|  3.79k|	if (was_reset > 0) {
  ------------------
  |  Branch (2147:6): [True: 0, False: 3.79k]
  ------------------
 2148|      0|		u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2149|      0|		size_t resplen = sizeof(rbuf);
 2150|      0|		r = gids_select_aid(card, gids_aid.value, gids_aid.len, rbuf, &resplen);
 2151|      0|	}
 2152|       |
 2153|  3.79k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.79k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.79k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.79k|	int _ret = r; \
  |  |  |  |  155|  3.79k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.79k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.79k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.79k|	return _ret; \
  |  |  |  |  163|  3.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2154|  3.79k|}

sc_invalidate_cache:
  164|  2.86k|{
  165|  2.86k|	if (card) {
  ------------------
  |  Branch (165:6): [True: 2.86k, False: 0]
  ------------------
  166|  2.86k|		struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  167|  2.86k|		sc_file_free(prv->cache.current_ef);
  168|  2.86k|		sc_file_free(prv->cache.current_df);
  169|  2.86k|		memset(&prv->cache, 0, sizeof(prv->cache));
  170|  2.86k|		prv->cache.valid = 0;
  171|  2.86k|	}
  172|  2.86k|}
iasecc_se_get_info:
 1624|    207|{
 1625|    207|	struct sc_context *ctx = card->ctx;
 1626|    207|	struct sc_apdu apdu;
 1627|    207|	unsigned char rbuf[0x100];
 1628|    207|	unsigned char sbuf_iasecc[10] = {
 1629|    207|		0x4D, 0x08, IASECC_SDO_TEMPLATE_TAG, 0x06,
  ------------------
  |  |   29|    207|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 1630|    207|		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   27|    207|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |  102|    207|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   59|    207|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 1631|    207|		se->reference & 0x3F,
 1632|    207|		0x02, IASECC_SDO_CLASS_SE, 0x80
  ------------------
  |  |  102|    207|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 1633|    207|	};
 1634|    207|	int rv;
 1635|       |
 1636|    207|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    207|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    207|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    207|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    207|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1637|       |
 1638|    207|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (1638:6): [True: 48, False: 159]
  ------------------
 1639|     48|		rv = iasecc_select_mf(card, NULL);
 1640|     48|		LOG_TEST_RET(ctx, rv, "MF invalid");
  ------------------
  |  |  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: 11, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 37]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1641|     48|	}
 1642|       |
 1643|    196|	if (se->reference > IASECC_SE_REF_MAX)
  ------------------
  |  |   66|    196|#define IASECC_SE_REF_MAX	0x0F
  ------------------
  |  Branch (1643:6): [True: 0, False: 196]
  ------------------
 1644|    196|                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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1645|       |
 1646|    196|	rv = iasecc_se_get_info_from_cache(card, se);
 1647|    196|	if (rv == SC_ERROR_OBJECT_NOT_FOUND)   {
  ------------------
  |  |   88|    196|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1647:6): [True: 191, False: 5]
  ------------------
 1648|    191|		sc_log(ctx, "No SE#%X info in cache, try to use 'GET DATA'", se->reference);
  ------------------
  |  |   71|    191|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1649|       |
 1650|    191|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    191|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1651|    191|		apdu.data = sbuf_iasecc;
 1652|    191|		apdu.datalen = sizeof(sbuf_iasecc);
 1653|    191|		apdu.lc = apdu.datalen;
 1654|    191|		apdu.resp = rbuf;
 1655|    191|		apdu.resplen = sizeof(rbuf);
 1656|    191|		apdu.le = sizeof(rbuf);
 1657|       |
 1658|    191|		rv = sc_transmit_apdu(card, &apdu);
 1659|    191|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    191|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    191|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    191|	int _ret = (r); \
  |  |  |  |  168|    191|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 188]
  |  |  |  |  ------------------
  |  |  |  |  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|    191|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 188]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|    188|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1661|    188|		LOG_TEST_RET(ctx, rv, "get SE data  error");
  ------------------
  |  |  174|    188|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    188|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    188|	int _ret = (r); \
  |  |  |  |  168|    188|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 32, False: 156]
  |  |  |  |  ------------------
  |  |  |  |  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|    188|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 156]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1662|       |
 1663|    156|		rv = iasecc_se_parse(card, apdu.resp, apdu.resplen, se);
 1664|    156|		LOG_TEST_RET(ctx, rv, "cannot parse SE data");
  ------------------
  |  |  174|    156|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    156|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    156|	int _ret = (r); \
  |  |  |  |  168|    156|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 125, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  169|    125|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    125|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    125|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    125|		return _ret; \
  |  |  |  |  172|    125|	} \
  |  |  |  |  173|    156|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1665|       |
 1666|     31|		rv = iasecc_se_cache_info(card, se);
 1667|     31|		LOG_TEST_RET(ctx, rv, "failed to put SE data into cache");
  ------------------
  |  |  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: 0, False: 31]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     31|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 31]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1668|     31|	}
 1669|       |
 1670|     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|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1671|     36|}
sc_get_iasecc_driver:
 3696|  16.1k|{
 3697|  16.1k|	return sc_get_driver();
 3698|  16.1k|}
card-iasecc.c:iasecc_is_cpx:
  588|  13.3k|{
  589|  13.3k|	switch(card->type) {
  590|  2.00k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (590:3): [True: 2.00k, False: 11.3k]
  ------------------
  591|  2.22k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (591:3): [True: 213, False: 13.1k]
  ------------------
  592|  2.22k|			return 1;
  593|  11.1k|		default:
  ------------------
  |  Branch (593:3): [True: 11.1k, False: 2.22k]
  ------------------
  594|  11.1k|			return 0;
  595|  13.3k|	}
  596|       |
  597|      0|	return 0;
  598|  13.3k|}
card-iasecc.c:iasecc_select_mf:
  283|  2.75k|{
  284|  2.75k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  285|  2.75k|	struct sc_context *ctx = card->ctx;
  286|  2.75k|	struct sc_file *mf_file = NULL;
  287|  2.75k|	struct sc_path path;
  288|  2.75k|	int rv;
  289|       |
  290|  2.75k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.75k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.75k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.75k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.75k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.75k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|  2.75k|	if (file_out)
  ------------------
  |  Branch (292:6): [True: 1.65k, False: 1.09k]
  ------------------
  293|  1.65k|		*file_out = NULL;
  294|       |
  295|  2.75k|	memset(&path, 0, sizeof(struct sc_path));
  296|  2.75k|	if (!card->ef_atr || !card->ef_atr->aid.len)   {
  ------------------
  |  Branch (296:6): [True: 173, False: 2.57k]
  |  Branch (296:23): [True: 228, False: 2.35k]
  ------------------
  297|    401|		struct sc_apdu apdu;
  298|    401|		unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  299|       |
  300|       |		/* ISO 'select' command fails when not FCP data returned */
  301|    401|		sc_format_path("3F00", &path);
  302|    401|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    401|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  303|       |
  304|    401|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    401|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|    401|		apdu.lc = path.len;
  306|    401|		apdu.data = path.value;
  307|    401|		apdu.datalen = path.len;
  308|    401|		apdu.resplen = sizeof(apdu_resp);
  309|    401|		apdu.resp = apdu_resp;
  310|       |
  311|       |		/* TODO: this might be obsolete now that 0x0c (no data) is default for p2 */
  312|    401|		if (card->type == SC_CARD_TYPE_IASECC_MI2)
  ------------------
  |  Branch (312:7): [True: 64, False: 337]
  ------------------
  313|     64|			apdu.p2 = 0x04;
  314|       |
  315|    401|		rv = sc_transmit_apdu(card, &apdu);
  316|    401|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    401|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    401|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    401|	int _ret = (r); \
  |  |  |  |  168|    401|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 391]
  |  |  |  |  ------------------
  |  |  |  |  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|    401|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 391]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|    391|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  318|    391|		LOG_TEST_RET(card->ctx, rv, "Cannot select MF");
  ------------------
  |  |  174|    391|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    391|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    391|	int _ret = (r); \
  |  |  |  |  168|    391|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 166, False: 225]
  |  |  |  |  ------------------
  |  |  |  |  169|    166|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    166|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    166|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    166|		return _ret; \
  |  |  |  |  172|    166|	} \
  |  |  |  |  173|    391|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 225]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|    391|	}
  320|  2.35k|	else   {
  321|  2.35k|		if (card->ef_atr->aid.len > sizeof(path.value))
  ------------------
  |  Branch (321:7): [True: 0, False: 2.35k]
  ------------------
  322|  2.35k|			LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_DATA, "AID length too large");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %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|  2.35k|		memset(&path, 0, sizeof(path));
  324|  2.35k|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.35k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  325|  2.35k|		memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  326|  2.35k|		path.len = card->ef_atr->aid.len;
  327|  2.35k|		rv = iasecc_select_file(card, &path, file_out);
  328|  2.35k|		LOG_TEST_RET(ctx, rv, "Unable to ROOT selection");
  ------------------
  |  |  174|  2.35k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.35k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.35k|	int _ret = (r); \
  |  |  |  |  168|  2.35k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.87k, False: 473]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.87k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.87k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.87k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.87k|		return _ret; \
  |  |  |  |  172|  1.87k|	} \
  |  |  |  |  173|  2.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 473]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  329|  2.35k|	}
  330|       |
  331|       |	/* Ignore the FCP of the MF, because:
  332|       |	 * - some cards do not return it;
  333|       |	 * - there is not need of it -- create/delete of the files in MF is not envisaged.
  334|       |	 */
  335|    698|	mf_file = sc_file_new();
  336|    698|	if (mf_file == NULL)
  ------------------
  |  Branch (336:6): [True: 0, False: 698]
  ------------------
  337|    698|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  338|    698|	mf_file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    698|#define SC_FILE_TYPE_DF			0x04
  ------------------
  339|    698|	mf_file->path = path;
  340|       |
  341|    698|	sc_invalidate_cache(card);
  342|    698|	sc_file_dup(&prv->cache.current_df, mf_file);
  343|    698|	prv->cache.valid = 1;
  344|       |
  345|    698|	if (file_out && *file_out == NULL)
  ------------------
  |  Branch (345:6): [True: 518, False: 180]
  |  Branch (345:18): [True: 426, False: 92]
  ------------------
  346|    426|		*file_out = mf_file;
  347|    272|	else
  348|    272|		sc_file_free(mf_file);
  349|       |
  350|    698|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    698|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    698|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    698|	int _ret = r; \
  |  |  |  |  155|    698|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 698, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    698|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 698]
  |  |  |  |  ------------------
  |  |  |  |  157|    698|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    698|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    698|	return _ret; \
  |  |  |  |  163|    698|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|    698|}
card-iasecc.c:iasecc_select_file:
  866|  7.44k|{
  867|  7.44k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  868|  7.44k|	struct sc_context *ctx = card->ctx;
  869|  7.44k|	struct sc_path lpath;
  870|  7.44k|	int rv, ii;
  871|       |
  872|  7.44k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  7.44k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.44k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.44k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.44k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.44k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  873|  7.44k|	memcpy(&lpath, path, sizeof(struct sc_path));
  874|  7.44k|	if (file_out)
  ------------------
  |  Branch (874:6): [True: 3.55k, False: 3.89k]
  ------------------
  875|  3.55k|		*file_out = NULL;
  876|       |
  877|  7.44k|	sc_log(ctx, "iasecc_select_file(card:%p) path.len %zu; path.type %i; aid_len %zu",
  ------------------
  |  |   71|  7.44k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  878|  7.44k|			card, path->len, path->type, path->aid.len);
  879|  7.44k|	sc_log(ctx, "path:%s", sc_print_path(path));
  ------------------
  |  |   71|  7.44k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  880|       |
  881|  7.44k|	if ((!iasecc_is_cpx(card)) &&
  ------------------
  |  Branch (881:6): [True: 6.79k, False: 650]
  ------------------
  882|  6.79k|	    (card->type != SC_CARD_TYPE_IASECC_GEMALTO) &&
  ------------------
  |  Branch (882:6): [True: 6.73k, False: 67]
  ------------------
  883|  6.73k|	    (path->type != SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  13.4k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (883:7): [True: 2.68k, False: 4.04k]
  ------------------
  884|  2.68k|			&& lpath.len >= 2
  ------------------
  |  Branch (884:7): [True: 2.68k, False: 0]
  ------------------
  885|  2.68k|			&& lpath.value[0] == 0x3F && lpath.value[1] == 0x00))   {
  ------------------
  |  Branch (885:7): [True: 2.63k, False: 56]
  |  Branch (885:33): [True: 2.62k, False: 9]
  ------------------
  886|  2.62k|		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.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 2.46k, False: 158]
  |  |  ------------------
  ------------------
  887|       |
  888|  2.62k|		rv = iasecc_select_mf(card, file_out);
  889|  2.62k|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|  2.62k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.62k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.62k|	int _ret = (r); \
  |  |  |  |  168|  2.62k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.98k, False: 637]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.98k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.98k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.98k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.98k|		return _ret; \
  |  |  |  |  172|  1.98k|	} \
  |  |  |  |  173|  2.62k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 637]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  890|       |
  891|    637|		memmove(&lpath.value[0], &lpath.value[2], lpath.len - 2);
  892|    637|		lpath.len -=  2;
  893|    637|	}
  894|       |
  895|  5.46k|	if (lpath.aid.len)	{
  ------------------
  |  Branch (895:6): [True: 16, False: 5.44k]
  ------------------
  896|     16|		struct sc_file *file = NULL;
  897|     16|		struct sc_path ppath;
  898|       |
  899|     16|		if (lpath.aid.len > sizeof(ppath.value)) {
  ------------------
  |  Branch (899:7): [True: 0, False: 16]
  ------------------
  900|      0|			rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  901|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "AID length too large");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  902|      0|		}
  903|       |
  904|     16|		sc_log(ctx, "select parent AID:%p/%zu", lpath.aid.value, lpath.aid.len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  905|     16|		sc_log(ctx, "select parent AID:%s", sc_dump_hex(lpath.aid.value, lpath.aid.len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  906|     16|		memset(&ppath, 0, sizeof(ppath));
  907|     16|		memcpy(ppath.value, lpath.aid.value, lpath.aid.len);
  908|     16|		ppath.len = lpath.aid.len;
  909|     16|		ppath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|     16|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  910|       |
  911|     16|		rv = iasecc_select_file(card, &ppath, &file);
  912|     16|		LOG_TEST_GOTO_ERR(ctx, rv, "select AID path failed");
  ------------------
  |  |  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: 5, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  913|       |
  914|     11|		if (file_out) {
  ------------------
  |  Branch (914:7): [True: 11, False: 0]
  ------------------
  915|     11|			sc_file_free(*file_out);
  916|     11|			*file_out = file;
  917|     11|		} else {
  918|      0|			sc_file_free(file);
  919|      0|		}
  920|       |
  921|     11|		if (lpath.type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|     11|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (921:7): [True: 0, False: 11]
  ------------------
  922|      0|			lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  923|     11|	}
  924|       |
  925|  5.45k|	if (lpath.type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  5.45k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (925:6): [True: 1.25k, False: 4.19k]
  ------------------
  926|  1.25k|		lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|  1.25k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  927|       |
  928|  5.45k|	if (!lpath.len) {
  ------------------
  |  Branch (928:6): [True: 7, False: 5.45k]
  ------------------
  929|      7|		if (file_out) {
  ------------------
  |  Branch (929:7): [True: 3, False: 4]
  ------------------
  930|      3|			sc_file_free(*file_out);
  931|      3|			*file_out = NULL;
  932|      3|		}
  933|      7|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  934|      7|	}
  935|       |
  936|  5.45k|	do   {
  937|  5.45k|		struct sc_apdu apdu;
  938|  5.45k|		struct sc_file *file = NULL;
  939|  5.45k|		unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  940|  5.45k|		size_t pathlen = lpath.len;
  941|       |
  942|  5.45k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  5.45k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  943|       |
  944|  5.45k|		if (card->type != SC_CARD_TYPE_IASECC_GEMALTO
  ------------------
  |  Branch (944:7): [True: 5.38k, False: 67]
  ------------------
  945|  5.38k|				&& card->type != SC_CARD_TYPE_IASECC_OBERTHUR
  ------------------
  |  Branch (945:8): [True: 5.22k, False: 157]
  ------------------
  946|  5.22k|				&& card->type != SC_CARD_TYPE_IASECC_SAGEM
  ------------------
  |  Branch (946:8): [True: 5.13k, False: 95]
  ------------------
  947|  5.13k|				&& card->type != SC_CARD_TYPE_IASECC_AMOS
  ------------------
  |  Branch (947:8): [True: 5.08k, False: 46]
  ------------------
  948|  5.08k|				&& card->type != SC_CARD_TYPE_IASECC_MI
  ------------------
  |  Branch (948:8): [True: 694, False: 4.39k]
  ------------------
  949|    694|				&& card->type != SC_CARD_TYPE_IASECC_MI2
  ------------------
  |  Branch (949:8): [True: 646, False: 48]
  ------------------
  950|    646|				&& !iasecc_is_cpx(card)) {
  ------------------
  |  Branch (950:8): [True: 0, False: 646]
  ------------------
  951|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  952|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  953|      0|		}
  954|       |
  955|  5.45k|		if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  5.45k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (955:7): [True: 3, False: 5.44k]
  ------------------
  956|      3|			apdu.p1 = 0x02;
  957|      3|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (957:8): [True: 0, False: 3]
  ------------------
  958|      0|				apdu.p1 = 0x01;
  959|      3|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (959:8): [True: 0, False: 3]
  ------------------
  960|      3|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (960:8): [True: 0, False: 3]
  ------------------
  961|      3|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (961:8): [True: 0, False: 3]
  ------------------
  962|      3|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (962:8): [True: 0, False: 3]
  ------------------
  963|      3|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (963:8): [True: 0, False: 3]
  ------------------
  964|      3|			    iasecc_is_cpx(card)
  ------------------
  |  Branch (964:8): [True: 3, False: 0]
  ------------------
  965|      3|			    )   {
  966|      3|				apdu.p2 = 0x04;
  967|      3|			}
  968|      3|		}
  969|  5.44k|		else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|  5.44k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (969:12): [True: 1.25k, False: 4.19k]
  ------------------
  970|  1.25k|			apdu.p1 = 0x09;
  971|  1.25k|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (971:8): [True: 71, False: 1.18k]
  ------------------
  972|  1.18k|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (972:8): [True: 30, False: 1.15k]
  ------------------
  973|  1.15k|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (973:8): [True: 503, False: 650]
  ------------------
  974|    650|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (974:8): [True: 28, False: 622]
  ------------------
  975|    622|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (975:8): [True: 61, False: 561]
  ------------------
  976|  1.19k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (976:8): [True: 499, False: 62]
  ------------------
  977|  1.19k|				apdu.p2 = 0x04;
  978|  1.19k|			}
  979|  1.25k|		}
  980|  4.19k|		else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|  4.19k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (980:12): [True: 0, False: 4.19k]
  ------------------
  981|      0|			apdu.p1 = 0x03;
  982|      0|			pathlen = 0;
  983|      0|			apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  984|      0|		}
  985|  4.19k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  4.19k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (985:12): [True: 4.19k, False: 0]
  ------------------
  986|  4.19k|			apdu.p1 = 0x04;
  987|  4.19k|			if (card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (987:8): [True: 16, False: 4.17k]
  ------------------
  988|  4.17k|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (988:8): [True: 20, False: 4.15k]
  ------------------
  989|  4.15k|			    card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (989:8): [True: 86, False: 4.07k]
  ------------------
  990|  4.07k|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (990:8): [True: 6, False: 4.06k]
  ------------------
  991|  4.06k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (991:8): [True: 144, False: 3.92k]
  ------------------
  992|    272|				apdu.p2 = 0x04;
  993|    272|			}
  994|  4.19k|		}
  995|      0|		else   {
  996|      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__
  |  |  ------------------
  ------------------
  997|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  998|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  999|      0|		}
 1000|       |
 1001|  5.52k|		for (ii=0; ii<2; ii++)   {
  ------------------
  |  Branch (1001:14): [True: 5.52k, False: 0]
  ------------------
 1002|  5.52k|			apdu.lc = pathlen;
 1003|  5.52k|			apdu.data = lpath.value;
 1004|  5.52k|			apdu.datalen = pathlen;
 1005|       |
 1006|  5.52k|			apdu.resp = rbuf;
 1007|  5.52k|			apdu.resplen = sizeof(rbuf);
 1008|  5.52k|			apdu.le = 256;
 1009|       |
 1010|  5.52k|			rv = sc_transmit_apdu(card, &apdu);
 1011|  5.52k|			LOG_TEST_GOTO_ERR(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  184|  5.52k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.52k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.52k|	int _ret = (r); \
  |  |  |  |  178|  5.52k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 31, False: 5.49k]
  |  |  |  |  ------------------
  |  |  |  |  179|     31|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     31|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     31|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     31|		goto err; \
  |  |  |  |  182|     31|	} \
  |  |  |  |  183|  5.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 5.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1012|  5.49k|			rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1013|  5.49k|			if (rv == SC_ERROR_INCORRECT_PARAMETERS &&
  ------------------
  |  |   55|  10.9k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1013:8): [True: 110, False: 5.38k]
  ------------------
 1014|    110|					lpath.type == SC_PATH_TYPE_DF_NAME && apdu.p2 == 0x00)   {
  ------------------
  |  |  118|  5.60k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1014:6): [True: 86, False: 24]
  |  Branch (1014:44): [True: 71, False: 15]
  ------------------
 1015|     71|				sc_log(ctx, "Warning: SC_ERROR_INCORRECT_PARAMETERS for SC_PATH_TYPE_DF_NAME, try again with P2=0x0C");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1016|     71|				apdu.p2 = 0x0C;
 1017|     71|				continue;
 1018|     71|			}
 1019|       |
 1020|  5.41k|			if (ii)   {
  ------------------
  |  Branch (1020:8): [True: 71, False: 5.34k]
  ------------------
 1021|       |				/* 'SELECT AID' do not returned FCP. Try to emulate. */
 1022|     71|				apdu.resplen = sizeof(rbuf);
 1023|     71|				rv = iasecc_emulate_fcp(ctx, &apdu);
 1024|     71|				LOG_TEST_GOTO_ERR(ctx, rv, "Failed to emulate DF FCP");
  ------------------
  |  |  184|     71|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     71|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     71|	int _ret = (r); \
  |  |  |  |  178|     71|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  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|     71|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|     71|			}
 1026|       |
 1027|  5.41k|			break;
 1028|  5.41k|		}
 1029|       |
 1030|  5.41k|		LOG_TEST_GOTO_ERR(ctx, rv, "check SW failed");
  ------------------
  |  |  184|  5.41k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.41k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.41k|	int _ret = (r); \
  |  |  |  |  178|  5.41k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 3.06k, False: 2.35k]
  |  |  |  |  ------------------
  |  |  |  |  179|  3.06k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.06k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  3.06k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  3.06k|		goto err; \
  |  |  |  |  182|  3.06k|	} \
  |  |  |  |  183|  5.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.35k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1031|       |
 1032|  2.35k|		sc_log(ctx, "apdu.resp %zu", apdu.resplen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1033|  2.35k|		if (apdu.resplen)   {
  ------------------
  |  Branch (1033:7): [True: 973, False: 1.37k]
  ------------------
 1034|    973|			sc_log(ctx, "apdu.resp %02X:%02X:%02X...", apdu.resp[0], apdu.resp[1], apdu.resp[2]);
  ------------------
  |  |   71|    973|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1035|       |
 1036|    973|			switch (apdu.resp[0]) {
 1037|     88|			case 0x62:
  ------------------
  |  Branch (1037:4): [True: 88, False: 885]
  ------------------
 1038|    916|			case 0x6F:
  ------------------
  |  Branch (1038:4): [True: 828, False: 145]
  ------------------
 1039|    916|				file = sc_file_new();
 1040|    916|				if (file == NULL) {
  ------------------
  |  Branch (1040:9): [True: 0, False: 916]
  ------------------
 1041|      0|					if (file_out) {
  ------------------
  |  Branch (1041:10): [True: 0, False: 0]
  ------------------
 1042|      0|						sc_file_free(*file_out);
 1043|      0|						*file_out = NULL;
 1044|      0|					}
 1045|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1046|      0|				}
 1047|    916|				file->path = lpath;
 1048|       |
 1049|    916|				rv = iasecc_process_fci(card, file, apdu.resp, apdu.resplen);
 1050|    916|				if (rv) {
  ------------------
  |  Branch (1050:9): [True: 74, False: 842]
  ------------------
 1051|     74|					sc_file_free(file);
 1052|     74|					if (file_out) {
  ------------------
  |  Branch (1052:10): [True: 43, False: 31]
  ------------------
 1053|     43|						sc_file_free(*file_out);
 1054|     43|						*file_out = NULL;
 1055|     43|					}
 1056|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1057|     74|				}
 1058|    842|				break;
 1059|    842|			default:
  ------------------
  |  Branch (1059:4): [True: 57, False: 916]
  ------------------
 1060|     57|				if (file_out) {
  ------------------
  |  Branch (1060:9): [True: 30, False: 27]
  ------------------
 1061|     30|					sc_file_free(*file_out);
 1062|     30|					*file_out = NULL;
 1063|     30|				}
 1064|     57|				LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     57|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|    973|			}
 1066|       |
 1067|    842|			sc_log(ctx, "FileType %i", file->type);
  ------------------
  |  |   71|    842|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1068|    842|			if (file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|    842|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1068:8): [True: 78, False: 764]
  ------------------
 1069|     78|				sc_invalidate_cache(card);
 1070|     78|				sc_file_dup(&prv->cache.current_df, file);
 1071|     78|				prv->cache.valid = 1;
 1072|     78|			}
 1073|    764|			else   {
 1074|    764|				sc_file_free(prv->cache.current_ef);
 1075|    764|				sc_file_dup(&prv->cache.current_ef, file);
 1076|    764|				prv->cache.valid = 1;
 1077|    764|			}
 1078|       |
 1079|    842|			if (file_out)   {
  ------------------
  |  Branch (1079:8): [True: 698, False: 144]
  ------------------
 1080|    698|				sc_file_free(*file_out);
 1081|    698|				*file_out = file;
 1082|    698|			}
 1083|    144|			else   {
 1084|    144|				sc_file_free(file);
 1085|    144|			}
 1086|    842|		}
 1087|  1.37k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.37k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1087:12): [True: 1.22k, False: 153]
  ------------------
 1088|  1.22k|			sc_invalidate_cache(card);
 1089|  1.22k|			prv->cache.valid = 1;
 1090|  1.22k|		}
 1091|  2.35k|	} while(0);
  ------------------
  |  Branch (1091:10): [Folded, False: 2.22k]
  ------------------
 1092|       |
 1093|  2.22k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.22k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.22k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.22k|	int _ret = r; \
  |  |  |  |  155|  2.22k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.22k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.22k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.22k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.22k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.22k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.22k|	return _ret; \
  |  |  |  |  163|  2.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1094|  3.10k|err:
 1095|  3.10k|	if (file_out) {
  ------------------
  |  Branch (1095:6): [True: 1.26k, False: 1.84k]
  ------------------
 1096|  1.26k|		sc_file_free(*file_out);
 1097|       |		*file_out = NULL;
 1098|  1.26k|	}
 1099|  3.10k|	return rv;
 1100|  2.22k|}
card-iasecc.c:iasecc_emulate_fcp:
  831|     71|{
  832|     71|	unsigned char dummy_df_fcp[] = {
  833|     71|		0x62,0xFF,
  834|     71|			0x82,0x01,0x38,
  835|     71|			0x8A,0x01,0x05,
  836|     71|			0xA1,0x04,0x8C,0x02,0x02,0x00,
  837|     71|			0x84,0xFF,
  838|     71|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  839|     71|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  840|     71|	};
  841|       |
  842|     71|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     71|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     71|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     71|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     71|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|       |
  844|     71|	if (apdu->p1 != 0x04)
  ------------------
  |  Branch (844:6): [True: 0, False: 71]
  ------------------
  845|     71|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|     71|	if (apdu->datalen > 16)
  ------------------
  |  Branch (846:6): [True: 0, False: 71]
  ------------------
  847|     71|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  848|     71|	if (apdu->resplen < apdu->datalen + 16)
  ------------------
  |  Branch (848:6): [True: 0, False: 71]
  ------------------
  849|     71|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  850|       |
  851|     71|	memcpy(dummy_df_fcp + 16, apdu->data, apdu->datalen);
  852|     71|	dummy_df_fcp[15] = apdu->datalen;
  853|     71|	dummy_df_fcp[1] = apdu->datalen + 14;
  854|     71|	apdu->resplen = apdu->datalen + 16;
  855|     71|	memcpy(apdu->resp, dummy_df_fcp, apdu->resplen);
  856|       |
  857|     71|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  858|     71|}
card-iasecc.c:iasecc_process_fci:
 1106|    916|{
 1107|    916|	struct sc_context *ctx = card->ctx;
 1108|    916|	size_t taglen, offs, ii;
 1109|    916|	int rv;
 1110|    916|	const unsigned char *acls = NULL, *tag = NULL;
 1111|    916|	unsigned char mask;
 1112|    916|	unsigned char ops_DF[7] = {
 1113|    916|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  168|    916|#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|    916|#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|    916|#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|    916|#define SC_AC_OP_CREATE			3
  ------------------
 1114|    916|	};
 1115|    916|	unsigned char ops_EF[7] = {
 1116|    916|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  168|    916|#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|    916|#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|    916|#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|    916|#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|    916|#define SC_AC_OP_READ			22
  ------------------
 1117|    916|	};
 1118|       |
 1119|    916|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    916|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    916|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    916|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    916|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 916]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1120|       |
 1121|    916|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x6F, &taglen);
 1122|    916|	sc_log(ctx, "processing FCI: 0x6F tag %p", tag);
  ------------------
  |  |   71|    916|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1123|    916|	if (tag != NULL) {
  ------------------
  |  Branch (1123:6): [True: 807, False: 109]
  ------------------
 1124|    807|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   71|    807|#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|    807|		buf = tag;
 1126|    807|		buflen = taglen;
 1127|    807|	}
 1128|       |
 1129|    916|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x62, &taglen);
 1130|    916|	sc_log(ctx, "processing FCI: 0x62 tag %p", tag);
  ------------------
  |  |   71|    916|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1131|    916|	if (tag != NULL) {
  ------------------
  |  Branch (1131:6): [True: 77, False: 839]
  ------------------
 1132|     77|		sc_log(ctx, "  FCP length %zu", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1133|     77|		buf = tag;
 1134|     77|		buflen = taglen;
 1135|     77|	}
 1136|       |
 1137|    916|	rv = iso_ops->process_fci(card, file, buf, buflen);
 1138|    916|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    916|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    916|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    916|	int _ret = (r); \
  |  |  |  |  168|    916|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 916]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    916|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 916]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1139|       |/*
 1140|       |	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
 1141|       |	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
 1142|       |	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
 1143|       |*/
 1144|       |
 1145|    916|	sc_log(ctx, "type %i; let's parse file ACLs", file->type);
  ------------------
  |  |   71|    916|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1146|    916|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS, &taglen);
  ------------------
  |  |   39|    916|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
 1147|    916|	if (tag)
  ------------------
  |  Branch (1147:6): [True: 72, False: 844]
  ------------------
 1148|     72|		acls = sc_asn1_find_tag(ctx, tag, taglen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|     72|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1149|    844|	else
 1150|    844|		acls = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    844|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1151|       |
 1152|    916|	if (!acls)   {
  ------------------
  |  Branch (1152:6): [True: 74, False: 842]
  ------------------
 1153|     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__
  |  |  ------------------
  ------------------
 1154|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1155|     74|	}
 1156|       |
 1157|    842|	sc_log(ctx, "ACLs(%zu) '%s'", taglen, sc_dump_hex(acls, taglen));
  ------------------
  |  |   71|    842|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1158|    842|	mask = 0x40, offs = 1;
 1159|  5.16k|	for (ii = 0; ii < 7; ii++, mask /= 2)  {
  ------------------
  |  Branch (1159:15): [True: 4.67k, False: 498]
  ------------------
 1160|  4.67k|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|  4.67k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1160:22): [True: 520, False: 4.15k]
  ------------------
 1161|       |
 1162|       |		/* avoid any access to acls[offs] beyond the taglen */
 1163|  4.67k|		if (offs >= taglen) {
  ------------------
  |  Branch (1163:7): [True: 344, False: 4.32k]
  ------------------
 1164|    344|			sc_log(ctx, "Warning: Invalid offset reached during ACL parsing");
  ------------------
  |  |   71|    344|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1165|    344|			break;
 1166|    344|		}
 1167|  4.32k|		if (!(mask & acls[0]))
  ------------------
  |  Branch (1167:7): [True: 1.69k, False: 2.63k]
  ------------------
 1168|  1.69k|			continue;
 1169|       |
 1170|  2.63k|		sc_log(ctx, "ACLs mask 0x%X, offs %zu, op 0x%X, acls[offs] 0x%X", mask, offs, op, acls[offs]);
  ------------------
  |  |   71|  2.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1171|  2.63k|		if (op == 0xFF)   {
  ------------------
  |  Branch (1171:7): [True: 742, False: 1.89k]
  ------------------
 1172|    742|			;
 1173|    742|		}
 1174|  1.89k|		else if (acls[offs] == 0)   {
  ------------------
  |  Branch (1174:12): [True: 489, False: 1.40k]
  ------------------
 1175|    489|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|    489|#define SC_AC_NONE			0x00000000
  ------------------
 1176|    489|		}
 1177|  1.40k|		else if (acls[offs] == 0xFF)   {
  ------------------
  |  Branch (1177:12): [True: 194, False: 1.21k]
  ------------------
 1178|    194|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    194|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1179|    194|		}
 1180|  1.21k|		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   89|  1.21k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
              		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   93|  1.21k|#define IASECC_SCB_METHOD_USER_AUTH	0x10
  ------------------
  |  Branch (1180:12): [True: 157, False: 1.05k]
  ------------------
 1181|    157|			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |  156|    157|#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|    157|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
 1182|    157|		}
 1183|  1.05k|		else if (acls[offs] & IASECC_SCB_METHOD_MASK)   {
  ------------------
  |  |   89|  1.05k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
  |  Branch (1183:12): [True: 723, False: 330]
  ------------------
 1184|    723|			sc_file_add_acl_entry(file, op, SC_AC_SCB, acls[offs]);
  ------------------
  |  |  157|    723|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
 1185|    723|		}
 1186|    330|		else   {
 1187|    330|			sc_log(ctx, "Warning: non supported SCB method: %X", acls[offs]);
  ------------------
  |  |   71|    330|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1188|    330|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    330|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1189|    330|		}
 1190|       |
 1191|  2.63k|		offs++;
 1192|  2.63k|	}
 1193|       |
 1194|    842|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    842|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    842|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    842|	int _ret = r; \
  |  |  |  |  155|    842|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 842, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    842|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 842]
  |  |  |  |  ------------------
  |  |  |  |  157|    842|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    842|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    842|	return _ret; \
  |  |  |  |  163|    842|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1195|    842|}
card-iasecc.c:iasecc_se_get_info_from_cache:
 1583|    196|{
 1584|    196|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1585|    196|	struct sc_context *ctx = card->ctx;
 1586|    196|	struct iasecc_se_info *si = NULL;
 1587|    196|	int rv;
 1588|       |
 1589|    196|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    196|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    196|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    196|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    196|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 196]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1590|       |
 1591|    219|	for(si = prv->se_info; si; si = si->next)   {
  ------------------
  |  Branch (1591:25): [True: 28, False: 191]
  ------------------
 1592|     28|		if (si->reference != se->reference)
  ------------------
  |  Branch (1592:7): [True: 21, False: 7]
  ------------------
 1593|     21|			continue;
 1594|      7|		if (!(prv->cache.valid && prv->cache.current_df) && si->df)
  ------------------
  |  Branch (1594:9): [True: 7, False: 0]
  |  Branch (1594:29): [True: 5, False: 2]
  |  Branch (1594:55): [True: 2, False: 0]
  ------------------
 1595|      2|			continue;
 1596|      5|		if (prv->cache.valid && prv->cache.current_df && !si->df)
  ------------------
  |  Branch (1596:7): [True: 5, False: 0]
  |  Branch (1596:27): [True: 5, False: 0]
  |  Branch (1596:52): [True: 0, False: 5]
  ------------------
 1597|      0|			continue;
 1598|      5|		if (prv->cache.valid && prv->cache.current_df && si->df)
  ------------------
  |  Branch (1598:7): [True: 5, False: 0]
  |  Branch (1598:27): [True: 5, False: 0]
  |  Branch (1598:52): [True: 5, False: 0]
  ------------------
 1599|      5|			if (memcmp(&prv->cache.current_df->path, &si->df->path, sizeof(struct sc_path)))
  ------------------
  |  Branch (1599:8): [True: 0, False: 5]
  ------------------
 1600|      0|				continue;
 1601|      5|		break;
 1602|      5|	}
 1603|       |
 1604|    196|	if (!si)
  ------------------
  |  Branch (1604:6): [True: 191, False: 5]
  ------------------
 1605|    191|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    191|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1606|       |
 1607|      5|	memcpy(se, si, sizeof(struct iasecc_se_info));
 1608|       |
 1609|      5|	if (si->df)   {
  ------------------
  |  Branch (1609:6): [True: 5, False: 0]
  ------------------
 1610|      5|		sc_file_dup(&se->df, si->df);
 1611|      5|		if (se->df == NULL)
  ------------------
  |  Branch (1611:7): [True: 0, False: 5]
  ------------------
 1612|      5|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1613|      5|	}
 1614|       |
 1615|      5|	rv = iasecc_docp_copy(ctx, &si->docp, &se->docp);
 1616|      5|	LOG_TEST_RET(ctx, rv, "Cannot make copy of DOCP");
  ------------------
  |  |  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: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1617|       |
 1618|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|      5|}
card-iasecc.c:iasecc_se_cache_info:
 1539|     31|{
 1540|     31|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1541|     31|	struct sc_context *ctx = card->ctx;
 1542|     31|	struct iasecc_se_info *se_info = NULL, *si = NULL;
 1543|     31|	int rv;
 1544|       |
 1545|     31|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1546|       |
 1547|     31|	se_info = calloc(1, sizeof(struct iasecc_se_info));
 1548|     31|	if (!se_info)
  ------------------
  |  Branch (1548:6): [True: 0, False: 31]
  ------------------
 1549|     31|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1550|     31|	memcpy(se_info, se, sizeof(struct iasecc_se_info));
 1551|       |
 1552|     31|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (1552:6): [True: 31, False: 0]
  |  Branch (1552:26): [True: 29, False: 2]
  ------------------
 1553|     29|		sc_file_dup(&se_info->df, prv->cache.current_df);
 1554|     29|		if (se_info->df == NULL)   {
  ------------------
  |  Branch (1554:7): [True: 0, False: 29]
  ------------------
 1555|      0|			free(se_info);
 1556|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1557|      0|		}
 1558|     29|	}
 1559|       |
 1560|     31|	rv = iasecc_docp_copy(ctx, &se->docp, &se_info->docp);
 1561|     31|	if (rv < 0)   {
  ------------------
  |  Branch (1561:6): [True: 0, False: 31]
  ------------------
 1562|      0|		free(se_info->df);
 1563|      0|		iasecc_docp_free_fields(&se_info->docp);
 1564|      0|		free(se_info);
 1565|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1566|      0|	}
 1567|       |
 1568|     31|	if (!prv->se_info)   {
  ------------------
  |  Branch (1568:6): [True: 22, False: 9]
  ------------------
 1569|     22|		prv->se_info = se_info;
 1570|     22|	}
 1571|      9|	else    {
 1572|     13|		for (si = prv->se_info; si->next; si = si->next)
  ------------------
  |  Branch (1572:27): [True: 4, False: 9]
  ------------------
 1573|      4|			;
 1574|      9|		si->next = se_info;
 1575|      9|	}
 1576|       |
 1577|     31|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1578|     31|}
card-iasecc.c:sc_get_driver:
 3649|  16.1k|{
 3650|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3651|       |
 3652|  16.1k|	if (!iso_ops)
  ------------------
  |  Branch (3652:6): [True: 1, False: 16.1k]
  ------------------
 3653|      1|		iso_ops = iso_drv->ops;
 3654|       |
 3655|  16.1k|	iasecc_ops = *iso_ops;
 3656|       |
 3657|  16.1k|	iasecc_ops.match_card = iasecc_match_card;
 3658|  16.1k|	iasecc_ops.init = iasecc_init;
 3659|  16.1k|	iasecc_ops.finish = iasecc_finish;
 3660|  16.1k|	iasecc_ops.read_binary = iasecc_read_binary;
 3661|       |	/*	write_binary: ISO7816 implementation works	*/
 3662|       |	/*	update_binary: ISO7816 implementation works	*/
 3663|  16.1k|	iasecc_ops.erase_binary = iasecc_erase_binary;
 3664|       |	/*	resize_binary	*/
 3665|       |	/* 	read_record: Untested	*/
 3666|       |	/*	write_record: Untested	*/
 3667|       |	/*	append_record: Untested	*/
 3668|       |	/*	update_record: Untested	*/
 3669|  16.1k|	iasecc_ops.select_file = iasecc_select_file;
 3670|       |	/*	get_response: Untested	*/
 3671|  16.1k|	iasecc_ops.get_challenge = iasecc_get_challenge;
 3672|  16.1k|	iasecc_ops.logout = iasecc_logout;
 3673|       |	/*	restore_security_env	*/
 3674|  16.1k|	iasecc_ops.set_security_env = iasecc_set_security_env;
 3675|  16.1k|	iasecc_ops.decipher = iasecc_decipher;
 3676|  16.1k|	iasecc_ops.compute_signature = iasecc_compute_signature;
 3677|  16.1k|	iasecc_ops.create_file = iasecc_create_file;
 3678|  16.1k|	iasecc_ops.delete_file = iasecc_delete_file;
 3679|       |	/*	list_files	*/
 3680|  16.1k|	iasecc_ops.check_sw = iasecc_check_sw;
 3681|  16.1k|	iasecc_ops.card_ctl = iasecc_card_ctl;
 3682|  16.1k|	iasecc_ops.process_fci = iasecc_process_fci;
 3683|       |	/*	construct_fci: Not needed	*/
 3684|  16.1k|	iasecc_ops.pin_cmd = iasecc_pin_cmd;
 3685|       |	/*	get_data: Not implemented	*/
 3686|       |	/*	put_data: Not implemented	*/
 3687|       |	/*	delete_record: Not implemented	*/
 3688|       |
 3689|  16.1k|	iasecc_ops.read_public_key = iasecc_read_public_key;
 3690|       |
 3691|  16.1k|	return &iasecc_drv;
 3692|  16.1k|}
card-iasecc.c:iasecc_match_card:
  355|  10.7k|{
  356|  10.7k|	struct sc_context *ctx = card->ctx;
  357|  10.7k|	int i;
  358|       |
  359|  10.7k|	i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
  360|  10.7k|	if (i < 0)   {
  ------------------
  |  Branch (360:6): [True: 9.83k, False: 867]
  ------------------
  361|  9.83k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  9.83k|#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|  9.83k|		return 0;
  363|  9.83k|	}
  364|       |
  365|    867|	sc_log(ctx, "'%s' card matched", iasecc_known_atrs[i].name);
  ------------------
  |  |   71|    867|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  366|    867|	return 1;
  367|  10.7k|}
card-iasecc.c:iasecc_init:
  626|    867|{
  627|    867|	struct sc_context *ctx = card->ctx;
  628|    867|	struct iasecc_private_data *private_data = NULL;
  629|    867|	int rv = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    867|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  630|    867|	void *old_drv_data = card->drv_data;
  631|       |
  632|    867|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    867|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    867|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    867|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    867|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 867]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|    867|	private_data = (struct iasecc_private_data *) calloc(1, sizeof(struct iasecc_private_data));
  634|    867|	if (private_data == NULL)
  ------------------
  |  Branch (634:6): [True: 0, False: 867]
  ------------------
  635|    867|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    867|	card->cla  = 0x00;
  638|    867|	card->drv_data = private_data;
  639|       |
  640|    867|	if (card->type == SC_CARD_TYPE_IASECC_GEMALTO)
  ------------------
  |  Branch (640:6): [True: 22, False: 845]
  ------------------
  641|     22|		rv = iasecc_init_gemalto(card);
  642|    845|	else if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (642:11): [True: 67, False: 778]
  ------------------
  643|     67|		rv = iasecc_init_oberthur(card);
  644|    778|	else if (card->type == SC_CARD_TYPE_IASECC_SAGEM)
  ------------------
  |  Branch (644:11): [True: 42, False: 736]
  ------------------
  645|     42|		rv = iasecc_init_amos_or_sagem(card);
  646|    736|	else if (card->type == SC_CARD_TYPE_IASECC_AMOS)
  ------------------
  |  Branch (646:11): [True: 11, False: 725]
  ------------------
  647|     11|		rv = iasecc_init_amos_or_sagem(card);
  648|    725|	else if (card->type == SC_CARD_TYPE_IASECC_MI)
  ------------------
  |  Branch (648:11): [True: 497, False: 228]
  ------------------
  649|    497|		rv = iasecc_init_amos_or_sagem(card);
  650|    228|	else if (iasecc_is_cpx(card))
  ------------------
  |  Branch (650:11): [True: 228, False: 0]
  ------------------
  651|    228|		rv = iasecc_init_cpx(card);
  652|      0|	else {
  653|      0|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  654|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  655|      0|	}
  656|       |
  657|       |
  658|    867|	if (!rv)   {
  ------------------
  |  Branch (658:6): [True: 572, False: 295]
  ------------------
  659|    572|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (659:7): [True: 572, False: 0]
  |  Branch (659:23): [True: 472, False: 100]
  ------------------
  660|    472|			struct sc_path path;
  661|       |
  662|    472|			memset(&path, 0, sizeof(struct sc_path));
  663|    472|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    472|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  664|    472|			memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  665|    472|			path.len = card->ef_atr->aid.len;
  666|       |
  667|    472|			rv = iasecc_select_file(card, &path, NULL);
  668|    472|			sc_log(ctx, "Select ECC ROOT with the AID from EF.ATR: rv %i", rv);
  ------------------
  |  |   71|    472|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  669|    472|			LOG_TEST_GOTO_ERR(ctx, rv, "Select EF.ATR AID failed");
  ------------------
  |  |  184|    472|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    472|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    472|	int _ret = (r); \
  |  |  |  |  178|    472|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 6, False: 466]
  |  |  |  |  ------------------
  |  |  |  |  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|    472|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 466]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  670|    472|		}
  671|       |
  672|    566|		iasecc_get_serialnr(card, NULL);
  673|    566|	}
  674|       |
  675|    861|#ifdef ENABLE_SM
  676|    861|	card->sm_ctx.ops.read_binary = _iasecc_sm_read_binary;
  677|    861|	card->sm_ctx.ops.update_binary = _iasecc_sm_update_binary;
  678|    861|#endif
  679|       |
  680|    861|	if (!rv && card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (680:6): [True: 566, False: 295]
  |  Branch (680:13): [True: 566, False: 0]
  |  Branch (680:29): [True: 466, False: 100]
  ------------------
  681|    466|		sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   71|    466|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  682|    466|	}
  683|       |
  684|    867|err:
  685|    867|	if (rv < 0) {
  ------------------
  |  Branch (685:6): [True: 301, False: 566]
  ------------------
  686|    301|		sc_invalidate_cache(card);
  687|    301|		free(private_data);
  688|    301|		card->drv_data = old_drv_data;
  689|    566|	} else {
  690|    566|		free(old_drv_data);
  691|    566|	}
  692|       |
  693|    867|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    867|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    867|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    867|	int _ret = r; \
  |  |  |  |  155|    867|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 867, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    867|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    301|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 301, False: 566]
  |  |  |  |  ------------------
  |  |  |  |  157|    867|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    867|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    867|	return _ret; \
  |  |  |  |  163|    867|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|    867|}
card-iasecc.c:iasecc_init_gemalto:
  421|     22|{
  422|     22|	struct sc_context *ctx = card->ctx;
  423|     22|	struct sc_path path;
  424|     22|	unsigned int flags;
  425|     22|	int rv = 0;
  426|       |
  427|     22|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     22|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     22|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     22|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     22|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  428|       |
  429|     22|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     22|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     22|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     22|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     22|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     22|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     22|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  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 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     22|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     22|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     22|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     22|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     22|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     22|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  430|       |
  431|     22|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     22|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     22|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     22|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     22|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     22|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     22|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     22|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     22|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     22|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  432|       |
  433|     22|	sc_format_path("3F00", &path);
  434|     22|	if (SC_SUCCESS != sc_select_file(card, &path, NULL)) {
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
  |  Branch (434:6): [True: 20, False: 2]
  ------------------
  435|       |		/* Result ignored*/
  436|     20|		sc_log(card->ctx, "Warning, MF select failed");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  437|     20|	}
  438|       |
  439|     22|	rv = iasecc_parse_ef_atr(card);
  440|     22|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  441|     22|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     22|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (441:6): [True: 2, False: 20]
  ------------------
  442|      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__
  |  |  ------------------
  ------------------
  443|      2|		rv = iasecc_select_mf(card, NULL);
  444|      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__
  |  |  ------------------
  ------------------
  445|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|       |
  447|      1|		rv = iasecc_parse_ef_atr(card);
  448|      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__
  |  |  ------------------
  ------------------
  449|      1|	}
  450|     21|	sc_log(ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  451|     21|	LOG_TEST_RET(ctx, rv, "Cannot read/parse EF.ATR");
  ------------------
  |  |  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: 18, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  452|       |
  453|      3|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  454|      3|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  455|       |
  456|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  457|      3|}
card-iasecc.c:iasecc_parse_ef_atr:
  371|    421|{
  372|    421|	struct sc_context *ctx = card->ctx;
  373|    421|	struct iasecc_private_data *pdata = (struct iasecc_private_data *) card->drv_data;
  374|    421|	struct iasecc_version *version = &pdata->version;
  375|    421|	struct iasecc_io_buffer_sizes *sizes = &pdata->max_sizes;
  376|    421|	int rv;
  377|       |
  378|    421|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    421|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    421|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    421|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    421|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 421]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|    421|	rv = sc_parse_ef_atr(card);
  380|    421|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  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: 193, False: 228]
  |  |  |  |  ------------------
  |  |  |  |  169|    193|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    193|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    193|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    193|		return _ret; \
  |  |  |  |  172|    193|	} \
  |  |  |  |  173|    421|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|       |
  382|    228|	if (card->ef_atr->pre_issuing_len < 4)
  ------------------
  |  Branch (382:6): [True: 117, False: 111]
  ------------------
  383|    228|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid pre-issuing data");
  ------------------
  |  |  174|    117|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    117|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    117|	int _ret = (r); \
  |  |  |  |  168|    117|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 117, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|       |
  385|    111|	version->ic_manufacturer =	card->ef_atr->pre_issuing[0];
  386|    111|	version->ic_type =		card->ef_atr->pre_issuing[1];
  387|    111|	version->os_version =		card->ef_atr->pre_issuing[2];
  388|    111|	version->iasecc_version =	card->ef_atr->pre_issuing[3];
  389|    111|	sc_log(ctx, "EF.ATR: IC manufacturer/type %X/%X, OS/IasEcc versions %X/%X",
  ------------------
  |  |   71|    111|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  390|    111|		version->ic_manufacturer, version->ic_type, version->os_version, version->iasecc_version);
  391|       |
  392|    111|	if (card->ef_atr->issuer_data_len < 16)
  ------------------
  |  Branch (392:6): [True: 9, False: 102]
  ------------------
  393|    111|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid issuer data");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|       |
  395|    102|	sizes->send =	 card->ef_atr->issuer_data[2] * 0x100 + card->ef_atr->issuer_data[3];
  396|    102|	sizes->send_sc = card->ef_atr->issuer_data[6] * 0x100 + card->ef_atr->issuer_data[7];
  397|    102|	sizes->recv =	 card->ef_atr->issuer_data[10] * 0x100 + card->ef_atr->issuer_data[11];
  398|    102|	sizes->recv_sc = card->ef_atr->issuer_data[14] * 0x100 + card->ef_atr->issuer_data[15];
  399|       |
  400|    102|	sc_log(ctx, "EF.ATR: IO Buffer Size send/sc %zd/%zd recv/sc %zd/%zd",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  401|    102|			sizes->send, sizes->send_sc, sizes->recv, sizes->recv_sc);
  402|       |
  403|    102|	card->max_send_size = sizes->send;
  404|    102|	card->max_recv_size = sizes->recv;
  405|       |
  406|       |	/* Most of the card producers interpret 'send' values as "maximum APDU data size".
  407|       |	 * Oberthur strictly follows specification and interpret these values as "maximum APDU command size".
  408|       |	 * Here we need 'data size'.
  409|       |	 */
  410|    102|	if (card->max_send_size > 0xFF)
  ------------------
  |  Branch (410:6): [True: 81, False: 21]
  ------------------
  411|     81|		card->max_send_size -= 5;
  412|       |
  413|    102|	sc_log(ctx, "EF.ATR: max send/recv sizes %zX/%zX", card->max_send_size, card->max_recv_size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  414|       |
  415|    102|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    102|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    102|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    102|	int _ret = r; \
  |  |  |  |  155|    102|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 102, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    102|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 102]
  |  |  |  |  ------------------
  |  |  |  |  157|    102|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    102|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    102|	return _ret; \
  |  |  |  |  163|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|    102|}
card-iasecc.c:iasecc_init_oberthur:
  490|     67|{
  491|     67|	struct sc_context *ctx = card->ctx;
  492|     67|	unsigned int flags;
  493|     67|	int rv = 0;
  494|       |
  495|     67|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     67|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     67|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     67|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     67|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  496|       |
  497|     67|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     67|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     67|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|     67|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     67|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|     67|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     67|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|     67|#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|     67|#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|     67|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     67|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|     67|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     67|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|     67|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     67|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|     67|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  498|       |
  499|     67|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  500|     67|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  501|       |
  502|     67|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     67|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     67|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|     67|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     67|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|     67|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     67|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|     67|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     67|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|     67|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  503|       |
  504|     67|	iasecc_parse_ef_atr(card);
  505|       |
  506|       |	/* if we fail to select CM, */
  507|     67|	if (gp_select_card_manager(card)) {
  ------------------
  |  Branch (507:6): [True: 50, False: 17]
  ------------------
  508|     50|		gp_select_isd_rid(card);
  509|     50|	}
  510|       |
  511|     67|	rv = iasecc_oberthur_match(card);
  512|     67|	LOG_TEST_RET(ctx, rv, "unknown Oberthur's IAS/ECC card");
  ------------------
  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|       |
  514|     67|	rv = iasecc_select_mf(card, NULL);
  515|     67|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 55, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|     55|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     55|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     55|		return _ret; \
  |  |  |  |  172|     55|	} \
  |  |  |  |  173|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|       |
  517|     12|	rv = iasecc_parse_ef_atr(card);
  518|     12|	LOG_TEST_RET(ctx, rv, "EF.ATR read or parse error");
  ------------------
  |  |  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: 8, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|       |
  520|      4|	sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  521|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  522|      4|}
card-iasecc.c:iasecc_oberthur_match:
  462|     67|{
  463|     67|	struct sc_context *ctx = card->ctx;
  464|     67|	unsigned char *hist = card->reader->atr_info.hist_bytes;
  465|       |
  466|     67|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     67|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     67|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     67|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     67|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 67]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|       |
  468|     67|	if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
  ------------------
  |  Branch (468:6): [True: 0, False: 67]
  |  Branch (468:23): [True: 0, False: 67]
  ------------------
  469|     67|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|       |
  471|     67|	sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
  ------------------
  |  |  129|     67|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     67|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  472|       |
  473|     67|	if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
  ------------------
  |  Branch (473:6): [True: 0, False: 67]
  ------------------
  474|     67|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|       |
  476|     67|	if (!card->ef_atr)
  ------------------
  |  Branch (476:6): [True: 32, False: 35]
  ------------------
  477|     32|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  478|     67|	if (!card->ef_atr)
  ------------------
  |  Branch (478:6): [True: 0, False: 67]
  ------------------
  479|     67|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  480|       |
  481|     67|	memcpy(card->ef_atr->aid.value, OberthurIASECC_AID.value, OberthurIASECC_AID.len);
  482|     67|	card->ef_atr->aid.len = OberthurIASECC_AID.len;
  483|       |
  484|     67|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     67|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     67|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     67|	int _ret = r; \
  |  |  |  |  155|     67|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 67, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     67|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 67]
  |  |  |  |  ------------------
  |  |  |  |  157|     67|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     67|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     67|	return _ret; \
  |  |  |  |  163|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  485|     67|}
card-iasecc.c:iasecc_init_amos_or_sagem:
  552|    550|{
  553|    550|	struct sc_context *ctx = card->ctx;
  554|    550|	unsigned int flags;
  555|    550|	int rv = 0;
  556|       |
  557|    550|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    550|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    550|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    550|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    550|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 550]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  558|       |
  559|    550|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    550|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    550|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    550|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    550|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    550|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    550|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    550|#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|    550|#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|    550|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    550|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    550|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    550|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    550|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    550|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    550|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  560|       |
  561|    550|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  562|    550|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  563|       |
  564|    550|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    550|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    550|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    550|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    550|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    550|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    550|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    550|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    550|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    550|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  565|       |
  566|    550|	if (card->type == SC_CARD_TYPE_IASECC_MI)   {
  ------------------
  |  Branch (566:6): [True: 497, False: 53]
  ------------------
  567|    497|		rv = iasecc_mi_match(card);
  568|    497|		if (rv)
  ------------------
  |  Branch (568:7): [True: 27, False: 470]
  ------------------
  569|     27|			card->type = SC_CARD_TYPE_IASECC_MI2;
  570|    470|		else
  571|    497|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    470|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    470|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    470|	int _ret = r; \
  |  |  |  |  155|    470|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 470, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    470|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 470]
  |  |  |  |  ------------------
  |  |  |  |  157|    470|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    470|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    470|	return _ret; \
  |  |  |  |  163|    470|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  572|    497|	}
  573|       |
  574|     80|	rv = iasecc_parse_ef_atr(card);
  575|     80|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     80|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (575:6): [True: 13, False: 67]
  ------------------
  576|     13|		rv = iasecc_select_mf(card, NULL);
  577|     13|		LOG_TEST_RET(ctx, rv, "MF selection 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: 2, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  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|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|       |
  579|     11|		rv = iasecc_parse_ef_atr(card);
  580|     11|	}
  581|     78|	LOG_TEST_RET(ctx, rv, "IASECC: ATR parse failed");
  ------------------
  |  |  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: 46, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  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|     78|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  582|       |
  583|     32|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  584|     32|}
card-iasecc.c:iasecc_mi_match:
  527|    497|{
  528|    497|	struct sc_context *ctx = card->ctx;
  529|    497|	unsigned char resp[0x100];
  530|    497|	size_t resp_len = sizeof(resp);
  531|    497|	int rv = 0;
  532|       |
  533|    497|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    497|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    497|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    497|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    497|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 497]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|       |
  535|    497|	rv = iso7816_select_aid(card, MIIASECC_AID.value, MIIASECC_AID.len, resp, &resp_len);
  536|    497|	LOG_TEST_RET(ctx, rv, "IASECC: failed to select MI IAS/ECC applet");
  ------------------
  |  |  174|    497|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    497|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    497|	int _ret = (r); \
  |  |  |  |  168|    497|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 470]
  |  |  |  |  ------------------
  |  |  |  |  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|    497|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 470]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  537|       |
  538|    470|	if (!card->ef_atr)
  ------------------
  |  Branch (538:6): [True: 470, False: 0]
  ------------------
  539|    470|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  540|    470|	if (!card->ef_atr)
  ------------------
  |  Branch (540:6): [True: 0, False: 470]
  ------------------
  541|    470|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  542|       |
  543|    470|	memcpy(card->ef_atr->aid.value, MIIASECC_AID.value, MIIASECC_AID.len);
  544|    470|	card->ef_atr->aid.len = MIIASECC_AID.len;
  545|       |
  546|    470|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    470|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    470|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    470|	int _ret = r; \
  |  |  |  |  155|    470|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 470, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    470|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 470]
  |  |  |  |  ------------------
  |  |  |  |  157|    470|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    470|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    470|	return _ret; \
  |  |  |  |  163|    470|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  547|    470|}
card-iasecc.c:iasecc_init_cpx:
  602|    228|{
  603|    228|	struct sc_context *ctx = card->ctx;
  604|    228|	unsigned int flags;
  605|    228|	int rv = 0;
  606|       |
  607|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|    228|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    228|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    228|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  550|    228|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    228|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  547|    228|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    228|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  557|    228|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    228|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  553|    228|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  610|       |
  611|    228|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    228|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    228|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |   93|    228|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    228|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  106|    228|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    228|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  111|    228|#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|    228|#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|    228|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    228|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  133|    228|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    228|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  134|    228|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    228|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  138|    228|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  612|       |
  613|    228|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  614|    228|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  615|    228|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  616|       |
  617|    228|	rv = iasecc_parse_ef_atr(card);
  618|    228|	LOG_TEST_RET(ctx, rv, "Parse EF.ATR");
  ------------------
  |  |  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: 165, False: 63]
  |  |  |  |  ------------------
  |  |  |  |  169|    165|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    165|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    165|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    165|		return _ret; \
  |  |  |  |  172|    165|	} \
  |  |  |  |  173|    228|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 63]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|       |
  620|     63|	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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|     63|}
card-iasecc.c:iasecc_get_serialnr:
 2506|    781|{
 2507|    781|	struct sc_context *ctx = card->ctx;
 2508|    781|	struct sc_iin *iin = &card->serialnr.iin;
 2509|    781|	struct sc_apdu apdu;
 2510|    781|	unsigned char rbuf[0xC0];
 2511|    781|	size_t ii, offs, len;
 2512|    781|	int rv;
 2513|       |
 2514|    781|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    781|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    781|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    781|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    781|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 781]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2515|    781|	if (card->serialnr.len)
  ------------------
  |  Branch (2515:6): [True: 1, False: 780]
  ------------------
 2516|      1|		goto end;
 2517|       |
 2518|    780|	memset(&card->serialnr, 0, sizeof(card->serialnr));
 2519|       |
 2520|    780|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |  292|    780|#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|    780|#define IASECC_SFI_EF_SN	0x1C
  ------------------
 2521|    780|	apdu.le = sizeof(rbuf);
 2522|    780|	apdu.resp = rbuf;
 2523|    780|	apdu.resplen = sizeof(rbuf);
 2524|       |
 2525|    780|	rv = sc_transmit_apdu(card, &apdu);
 2526|    780|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    780|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    780|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    780|	int _ret = (r); \
  |  |  |  |  168|    780|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 771]
  |  |  |  |  ------------------
  |  |  |  |  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|    780|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 771]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2527|    771|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2528|    771|	LOG_TEST_RET(ctx, rv, "Get 'serial number' data failed");
  ------------------
  |  |  174|    771|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    771|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    771|	int _ret = (r); \
  |  |  |  |  168|    771|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 519, False: 252]
  |  |  |  |  ------------------
  |  |  |  |  169|    519|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    519|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    519|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    519|		return _ret; \
  |  |  |  |  172|    519|	} \
  |  |  |  |  173|    771|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 252]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2529|       |
 2530|    252|	if (apdu.resplen < 2 || rbuf[0] != ISO7812_PAN_SN_TAG || rbuf[1] > (apdu.resplen-2))
  ------------------
  |  |   29|    281|#define ISO7812_PAN_SN_TAG	0x5A
  ------------------
  |  Branch (2530:6): [True: 223, False: 29]
  |  Branch (2530:26): [True: 14, False: 15]
  |  Branch (2530:59): [True: 2, False: 13]
  ------------------
 2531|    252|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "serial number parse error");
  ------------------
  |  |  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: 239, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    239|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    239|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    239|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    239|		return _ret; \
  |  |  |  |  172|    239|	} \
  |  |  |  |  173|    239|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2532|     13|	len = rbuf[1];
 2533|       |
 2534|     13|	iin->mii = (rbuf[2] >> 4) & 0x0F;
 2535|       |
 2536|     13|	iin->country = 0;
 2537|     52|	for (ii=5; ii<8; ii++)   {
  ------------------
  |  Branch (2537:13): [True: 39, False: 13]
  ------------------
 2538|     39|		iin->country *= 10;
 2539|     39|		iin->country += (rbuf[ii/2] >> ((ii & 0x01) ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2539:35): [True: 26, False: 13]
  ------------------
 2540|     39|	}
 2541|       |
 2542|     13|	iin->issuer_id = 0;
 2543|     39|	for (ii=8; ii<10; ii++)   {
  ------------------
  |  Branch (2543:13): [True: 26, False: 13]
  ------------------
 2544|     26|		iin->issuer_id *= 10;
 2545|     26|		iin->issuer_id += (rbuf[ii/2] >> (ii & 0x01 ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2545:37): [True: 13, False: 13]
  ------------------
 2546|     26|	}
 2547|       |
 2548|       |	/* Copy the serial number from the last 8 bytes (at most) */
 2549|     13|	offs = len > 8 ? len - 8 : 0;
  ------------------
  |  Branch (2549:9): [True: 2, False: 11]
  ------------------
 2550|     13|	if (card->type == SC_CARD_TYPE_IASECC_SAGEM)   {
  ------------------
  |  Branch (2550:6): [True: 6, False: 7]
  ------------------
 2551|       |		/* 5A 0A 92 50 00 20 10 10 25 00 01 3F */
 2552|       |		/*            00 02 01 01 02 50 00 13  */
 2553|     25|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2553:14): [True: 19, False: 6]
  ------------------
 2554|     19|			*(card->serialnr.value + ii) = ((rbuf[ii + offs + 1] & 0x0F) << 4)
 2555|     19|				+ ((rbuf[ii + offs + 2] & 0xF0) >> 4) ;
 2556|      6|		card->serialnr.len = ii;
 2557|      6|	}
 2558|      7|	else   {
 2559|     26|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2559:14): [True: 19, False: 7]
  ------------------
 2560|     19|			*(card->serialnr.value + ii) = rbuf[ii + offs + 2];
 2561|      7|		card->serialnr.len = ii;
 2562|      7|	}
 2563|       |
 2564|     13|	do  {
 2565|     13|		char txt[0x200];
 2566|       |
 2567|     51|		for (ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (2567:13): [True: 38, False: 13]
  ------------------
 2568|     38|			sprintf(txt + ii*2, "%02X", *(card->serialnr.value + ii));
 2569|       |
 2570|     13|		sc_log(ctx, "serial number '%s'; mii %i; country %i; issuer_id %li", txt, iin->mii, iin->country, iin->issuer_id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2571|     13|	} while(0);
  ------------------
  |  Branch (2571:10): [Folded, False: 13]
  ------------------
 2572|       |
 2573|     14|end:
 2574|     14|	if (serial)
  ------------------
  |  Branch (2574:6): [True: 2, False: 12]
  ------------------
 2575|      2|		memcpy(serial, &card->serialnr, sizeof(*serial));
 2576|       |
 2577|     14|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  157|     14|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2578|     14|}
card-iasecc.c:_iasecc_sm_read_binary:
  763|    284|{
  764|    284|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  765|    284|	struct sc_context *ctx = card->ctx;
  766|    284|	const struct sc_acl_entry *entry = NULL;
  767|    284|	int rv;
  768|       |
  769|    284|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    284|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    284|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    284|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    284|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 284]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  770|    284|	sc_log(ctx, "card:%p offs:%i count:%zu ", card, offs, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  771|    284|	if (offs > 0x7fff)
  ------------------
  |  Branch (771:6): [True: 0, False: 284]
  ------------------
  772|    284|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  773|       |
  774|    284|	if (count == 0)
  ------------------
  |  Branch (774:6): [True: 0, False: 284]
  ------------------
  775|      0|		return 0;
  776|       |
  777|    284|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (777:6): [True: 284, False: 0]
  |  Branch (777:26): [True: 270, False: 14]
  ------------------
  778|    270|		entry = sc_file_get_acl_entry(prv->cache.current_ef, SC_AC_OP_READ);
  ------------------
  |  |  188|    270|#define SC_AC_OP_READ			22
  ------------------
  779|    270|		if (!entry)
  ------------------
  |  Branch (779:7): [True: 15, False: 255]
  ------------------
  780|    270|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "'READ' ACL not present");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  781|       |
  782|    255|		sc_log(ctx, "READ method/reference %X/%X", entry->method, entry->key_ref);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  783|    255|		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |  157|    255|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
              		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |   91|    218|#define IASECC_SCB_METHOD_SM		0x40
  ------------------
  |  Branch (783:7): [True: 218, False: 37]
  |  Branch (783:39): [True: 207, False: 11]
  ------------------
  784|    207|			unsigned char se_num = entry->key_ref & IASECC_SCB_METHOD_MASK_REF;
  ------------------
  |  |   90|    207|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
  785|       |
  786|    207|			rv = iasecc_sm_read_binary(card, se_num, offs, buff, count);
  787|    207|			LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    207|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    207|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    207|	int _ret = r; \
  |  |  |  |  155|    207|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    207|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    207|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 207, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    207|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    207|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    207|	return _ret; \
  |  |  |  |  163|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  788|    207|		}
  789|    255|	}
  790|       |
  791|     62|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     62|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     62|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     62|	int _ret = r; \
  |  |  |  |  155|     62|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  157|     62|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     62|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  792|     62|}
card-iasecc.c:iasecc_finish:
 1424|    566|{
 1425|    566|	struct sc_context *ctx = card->ctx;
 1426|    566|	struct iasecc_private_data *private_data = (struct iasecc_private_data *)card->drv_data;
 1427|       |
 1428|    566|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    566|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    566|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    566|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    566|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 566]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1429|       |
 1430|    566|	sc_invalidate_cache(card);
 1431|       |
 1432|    566|	if (private_data) {
  ------------------
  |  Branch (1432:6): [True: 566, False: 0]
  ------------------
 1433|    566|		struct iasecc_se_info *se_info = private_data->se_info, *next;
 1434|       |
 1435|    597|		while (se_info) {
  ------------------
  |  Branch (1435:10): [True: 31, False: 566]
  ------------------
 1436|     31|			sc_file_free(se_info->df);
 1437|     31|			next = se_info->next;
 1438|     31|			iasecc_docp_free_fields(&se_info->docp);
 1439|     31|			free(se_info);
 1440|     31|			se_info = next;
 1441|     31|		}
 1442|       |
 1443|    566|		free(card->drv_data);
 1444|    566|		card->drv_data = NULL;
 1445|    566|	}
 1446|       |
 1447|    566|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    566|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    566|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    566|	int _ret = r; \
  |  |  |  |  155|    566|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 566, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    566|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 566]
  |  |  |  |  ------------------
  |  |  |  |  157|    566|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    566|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    566|	return _ret; \
  |  |  |  |  163|    566|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1448|    566|}
card-iasecc.c:iasecc_read_binary:
  700|  1.62k|{
  701|  1.62k|	struct sc_context *ctx = card->ctx;
  702|  1.62k|	struct sc_apdu apdu;
  703|  1.62k|	int rv;
  704|       |
  705|  1.62k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.62k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.62k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.62k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.62k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.62k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  706|  1.62k|	sc_log(ctx, "iasecc_read_binary(card:%p) offs %i; count %zu", card, offs, count);
  ------------------
  |  |   71|  1.62k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  707|  1.62k|	if (offs > 0x7fff) {
  ------------------
  |  Branch (707:6): [True: 2, False: 1.62k]
  ------------------
  708|      2|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", offs);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  709|      2|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      2|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  710|      2|	}
  711|       |
  712|  1.62k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (offs >> 8) & 0x7F, offs & 0xFF);
  ------------------
  |  |  292|  1.62k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  713|  1.62k|	apdu.le = count < 0x100 ? count : 0x100;
  ------------------
  |  Branch (713:12): [True: 207, False: 1.41k]
  ------------------
  714|  1.62k|	apdu.resplen = count;
  715|  1.62k|	apdu.resp = buf;
  716|       |
  717|  1.62k|	rv = sc_transmit_apdu(card, &apdu);
  718|  1.62k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.62k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.62k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.62k|	int _ret = (r); \
  |  |  |  |  168|  1.62k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 1.60k]
  |  |  |  |  ------------------
  |  |  |  |  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.62k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.60k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  719|  1.60k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  720|  1.60k|	LOG_TEST_RET(ctx, rv, "failed");
  ------------------
  |  |  174|  1.60k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.60k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.60k|	int _ret = (r); \
  |  |  |  |  168|  1.60k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 321, False: 1.28k]
  |  |  |  |  ------------------
  |  |  |  |  169|    321|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    321|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    321|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    321|		return _ret; \
  |  |  |  |  172|    321|	} \
  |  |  |  |  173|  1.60k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.28k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  721|  1.28k|	sc_log(ctx, "apdu.resplen %zu", apdu.resplen);
  ------------------
  |  |   71|  1.28k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  722|       |
  723|  1.28k|	if (apdu.resplen == IASECC_READ_BINARY_LENGTH_MAX && apdu.resplen < count)   {
  ------------------
  |  |   76|  2.57k|#define IASECC_READ_BINARY_LENGTH_MAX	0xE7
  ------------------
  |  Branch (723:6): [True: 415, False: 873]
  |  Branch (723:55): [True: 414, False: 1]
  ------------------
  724|    414|		rv = iasecc_read_binary(card, (int)(offs + apdu.resplen), buf + apdu.resplen, count - apdu.resplen, flags);
  725|    414|		if (rv != SC_ERROR_WRONG_LENGTH)   {
  ------------------
  |  |   56|    414|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (725:7): [True: 404, False: 10]
  ------------------
  726|    404|			LOG_TEST_RET(ctx, rv, "read tail failed");
  ------------------
  |  |  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: 214, False: 190]
  |  |  |  |  ------------------
  |  |  |  |  169|    214|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    214|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    214|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    214|		return _ret; \
  |  |  |  |  172|    214|	} \
  |  |  |  |  173|    404|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 190]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|    190|			apdu.resplen += rv;
  728|    190|		}
  729|    414|	}
  730|       |
  731|  1.07k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.07k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.07k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.07k|	int _ret = r; \
  |  |  |  |  155|  1.07k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 1.04k]
  |  |  |  |  ------------------
  |  |  |  |  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|  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.07k|	return _ret; \
  |  |  |  |  163|  1.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  732|  1.07k|}
card-iasecc.c:iasecc_sdo_get_data:
 2892|    196|{
 2893|    196|	struct sc_context *ctx = card->ctx;
 2894|    196|	int rv, sdo_tag;
 2895|       |
 2896|    196|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    196|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    196|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    196|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    196|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 196]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2897|       |
 2898|    196|	sdo_tag = iasecc_sdo_tag_from_class(sdo->sdo_class);
 2899|       |
 2900|    196|	rv = iasecc_sdo_get_tagged_data(card, sdo_tag, sdo);
 2901|    196|	LOG_TEST_RET(ctx, rv, "cannot parse ECC SDO data");
  ------------------
  |  |  174|    196|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    196|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    196|	int _ret = (r); \
  |  |  |  |  168|    196|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 194, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|    194|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    194|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    194|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    194|		return _ret; \
  |  |  |  |  172|    194|	} \
  |  |  |  |  173|    196|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2902|       |
 2903|      2|	rv = iasecc_sdo_get_tagged_data(card, IASECC_DOCP_TAG, sdo);
  ------------------
  |  |   31|      2|#define IASECC_DOCP_TAG				0xA0
  ------------------
 2904|      2|	LOG_TEST_RET(ctx, rv, "cannot parse ECC DOCP data");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2905|       |
 2906|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2907|      0|}
card-iasecc.c:iasecc_sdo_tag_from_class:
 2793|    196|{
 2794|    196|	switch (sdo_class & ~IASECC_OBJECT_REF_LOCAL)   {
  ------------------
  |  |   59|    196|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2794:10): [True: 196, False: 0]
  ------------------
 2795|    196|	case IASECC_SDO_CLASS_CHV:
  ------------------
  |  |   98|    196|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (2795:2): [True: 196, False: 0]
  ------------------
 2796|    196|		return IASECC_SDO_CHV_TAG;
  ------------------
  |  |   63|    196|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
 2797|      0|	case IASECC_SDO_CLASS_RSA_PRIVATE:
  ------------------
  |  |  100|      0|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (2797:2): [True: 0, False: 196]
  ------------------
 2798|      0|		return IASECC_SDO_PRVKEY_TAG;
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
 2799|      0|	case IASECC_SDO_CLASS_RSA_PUBLIC:
  ------------------
  |  |  101|      0|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (2799:2): [True: 0, False: 196]
  ------------------
 2800|      0|		return IASECC_SDO_PUBKEY_TAG;
  ------------------
  |  |   76|      0|#define IASECC_SDO_PUBKEY_TAG			0x7F49
  ------------------
 2801|      0|	case IASECC_SDO_CLASS_SE:
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (2801:2): [True: 0, False: 196]
  ------------------
 2802|      0|		return IASECC_SDO_CLASS_SE;
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 2803|      0|	case IASECC_SDO_CLASS_KEYSET:
  ------------------
  |  |   99|      0|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (2803:2): [True: 0, False: 196]
  ------------------
 2804|      0|		return IASECC_SDO_KEYSET_TAG;
  ------------------
  |  |   83|      0|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
 2805|    196|	}
 2806|       |
 2807|      0|	return -1;
 2808|    196|}
card-iasecc.c:iasecc_sdo_get_tagged_data:
 2813|    198|{
 2814|    198|	struct sc_context *ctx = card->ctx;
 2815|    198|	struct sc_apdu apdu;
 2816|    198|	unsigned char sbuf[0x100];
 2817|    198|	size_t offs = sizeof(sbuf) - 1;
 2818|    198|	unsigned char rbuf[0x400];
 2819|    198|	int rv;
 2820|       |
 2821|    198|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    198|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    198|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    198|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    198|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 198]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2822|       |
 2823|    198|	sc_log(ctx, "sdo_tag=0x%x sdo_ref=0x%x sdo_class=0x%x", sdo_tag,
  ------------------
  |  |   71|    198|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2824|    198|			sdo->sdo_ref, sdo->sdo_class);
 2825|       |
 2826|       |	/* XXX: for the CPx, the SDO are available from some specific path */
 2827|    198|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (2827:6): [True: 2, False: 196]
  ------------------
 2828|      2|		struct sc_path path;
 2829|      2|		char *path_str = NULL;
 2830|      2|		switch(sdo_tag) {
 2831|      0|			case IASECC_SDO_PRVKEY_TAG:
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (2831:4): [True: 0, False: 2]
  ------------------
 2832|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 90 02 03 7F 48 80 */
 2833|      0|			path_str = "3F00:0001";
 2834|      0|			break;
 2835|      2|			case IASECC_SDO_CHV_TAG:
  ------------------
  |  |   63|      2|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (2835:4): [True: 2, False: 0]
  ------------------
 2836|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 81 01 03 7F 41 80 */
 2837|      2|			path_str = "3F00";
 2838|      2|			break;
 2839|      0|			default:
  ------------------
  |  Branch (2839:4): [True: 0, False: 2]
  ------------------
 2840|      0|			path_str = NULL;
 2841|      0|			break;
 2842|      2|		}
 2843|      2|		if (path_str) {
  ------------------
  |  Branch (2843:7): [True: 2, False: 0]
  ------------------
 2844|      2|			sc_log(ctx, "Warning: Enforce the path=%s", path_str);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2845|      2|			sc_format_path(path_str, &path);
 2846|      2|			rv = iasecc_select_file(card, &path, NULL);
 2847|      2|			LOG_TEST_RET(ctx, rv, "path 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2848|      2|		}
 2849|      2|	}
 2850|       |
 2851|    197|	sbuf[offs--] = 0x80;
 2852|    197|	sbuf[offs--] = sdo_tag & 0xFF;
 2853|    197|	if ((sdo_tag >> 8) & 0xFF)
  ------------------
  |  Branch (2853:6): [True: 195, False: 2]
  ------------------
 2854|    195|		sbuf[offs--] = (sdo_tag >> 8) & 0xFF;
 2855|    197|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2856|    197|	offs--;
 2857|       |
 2858|    197|	sbuf[offs--] = sdo->sdo_ref & 0x9F;
 2859|    197|	sbuf[offs--] = sdo->sdo_class | IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    197|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2860|    197|	sbuf[offs--] = IASECC_SDO_TAG_HEADER;
  ------------------
  |  |   27|    197|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
 2861|       |
 2862|    197|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2863|    197|	offs--;
 2864|    197|	sbuf[offs--] = IASECC_SDO_TEMPLATE_TAG;
  ------------------
  |  |   29|    197|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 2865|       |
 2866|    197|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2867|    197|	offs--;
 2868|    197|	sbuf[offs] = 0x4D;
 2869|       |
 2870|    197|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    197|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 2871|    197|	apdu.data = sbuf + offs;
 2872|    197|	apdu.datalen = sizeof(sbuf) - offs;
 2873|    197|	apdu.lc = sizeof(sbuf) - offs;
 2874|    197|	apdu.resp = rbuf;
 2875|    197|	apdu.resplen = sizeof(rbuf);
 2876|    197|	apdu.le = 0x100;
 2877|       |
 2878|    197|	rv = sc_transmit_apdu(card, &apdu);
 2879|    197|	LOG_TEST_RET(ctx, rv, "APDU transmit 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: 1, False: 196]
  |  |  |  |  ------------------
  |  |  |  |  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|    197|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 196]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2880|    196|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2881|    196|	LOG_TEST_RET(ctx, rv, "SDO get data error");
  ------------------
  |  |  174|    196|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    196|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    196|	int _ret = (r); \
  |  |  |  |  168|    196|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  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|    196|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2882|       |
 2883|    185|	rv = iasecc_sdo_parse(card, apdu.resp, apdu.resplen, sdo);
 2884|    185|	LOG_TEST_RET(ctx, rv, "cannot parse SDO 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: 183, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|    183|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    183|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    183|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    183|		return _ret; \
  |  |  |  |  172|    183|	} \
  |  |  |  |  173|    185|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2885|       |
 2886|      2|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2887|      2|}
card-iasecc.c:iasecc_check_sw:
 1501|  9.62k|{
 1502|  9.62k|	if (sw1 == 0x62 && sw2 == 0x82)
  ------------------
  |  Branch (1502:6): [True: 155, False: 9.47k]
  |  Branch (1502:21): [True: 130, False: 25]
  ------------------
 1503|    130|		return SC_SUCCESS;
  ------------------
  |  |   28|    130|#define SC_SUCCESS				0
  ------------------
 1504|       |
 1505|  9.49k|	return iso_ops->check_sw(card, sw1, sw2);
 1506|  9.62k|}
card-iasecc.c:iasecc_card_ctl:
 3015|    215|{
 3016|    215|	struct sc_context *ctx = card->ctx;
 3017|    215|	struct iasecc_sdo *sdo = (struct iasecc_sdo *) ptr;
 3018|       |
 3019|    215|	switch (cmd) {
  ------------------
  |  Branch (3019:10): [True: 215, False: 0]
  ------------------
 3020|    215|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (3020:2): [True: 215, False: 0]
  ------------------
 3021|    215|		return iasecc_get_serialnr(card, (struct sc_serial_number *)ptr);
 3022|      0|	case SC_CARDCTL_IASECC_SDO_CREATE:
  ------------------
  |  Branch (3022:2): [True: 0, False: 215]
  ------------------
 3023|      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__
  |  |  ------------------
  ------------------
 3024|      0|		return iasecc_sdo_create(card, (struct iasecc_sdo *) ptr);
 3025|      0|	case SC_CARDCTL_IASECC_SDO_DELETE:
  ------------------
  |  Branch (3025:2): [True: 0, False: 215]
  ------------------
 3026|      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__
  |  |  ------------------
  ------------------
 3027|      0|		return iasecc_sdo_delete(card, (struct iasecc_sdo *) ptr);
 3028|      0|	case SC_CARDCTL_IASECC_SDO_PUT_DATA:
  ------------------
  |  Branch (3028:2): [True: 0, False: 215]
  ------------------
 3029|      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__
  |  |  ------------------
  ------------------
 3030|      0|		return iasecc_sdo_put_data(card, (struct iasecc_sdo_update *) ptr);
 3031|      0|	case SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA:
  ------------------
  |  Branch (3031:2): [True: 0, False: 215]
  ------------------
 3032|      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__
  |  |  ------------------
  ------------------
 3033|      0|		return iasecc_sdo_key_rsa_put_data(card, (struct iasecc_sdo_rsa_update *) ptr);
 3034|      0|	case SC_CARDCTL_IASECC_SDO_GET_DATA:
  ------------------
  |  Branch (3034:2): [True: 0, False: 215]
  ------------------
 3035|      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__
  |  |  ------------------
  ------------------
 3036|      0|		return iasecc_sdo_get_data(card, (struct iasecc_sdo *) ptr);
 3037|      0|	case SC_CARDCTL_IASECC_SDO_GENERATE:
  ------------------
  |  Branch (3037:2): [True: 0, False: 215]
  ------------------
 3038|      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__
  |  |  ------------------
  ------------------
 3039|      0|		return iasecc_sdo_generate(card, (struct iasecc_sdo *) ptr);
 3040|      0|	case SC_CARDCTL_GET_SE_INFO:
  ------------------
  |  Branch (3040:2): [True: 0, False: 215]
  ------------------
 3041|      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__
  |  |  ------------------
  ------------------
 3042|      0|		return iasecc_se_get_info(card, (struct iasecc_se_info *) ptr);
 3043|      0|	case SC_CARDCTL_GET_CHV_REFERENCE_IN_SE:
  ------------------
  |  Branch (3043:2): [True: 0, False: 215]
  ------------------
 3044|      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__
  |  |  ------------------
  ------------------
 3045|      0|		return iasecc_get_chv_reference_from_se(card, (int *)ptr);
 3046|      0|	case SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE:
  ------------------
  |  Branch (3046:2): [True: 0, False: 215]
  ------------------
 3047|      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__
  |  |  ------------------
  ------------------
 3048|      0|		return iasecc_get_free_reference(card, (struct iasecc_ctl_get_free_reference *)ptr);
 3049|    215|	}
 3050|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3051|    215|}
card-iasecc.c:iasecc_pin_cmd:
 2470|    215|{
 2471|    215|	struct sc_context *ctx = card->ctx;
 2472|    215|	int rv;
 2473|       |
 2474|    215|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    215|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    215|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    215|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    215|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 215]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2475|    215|	sc_log(ctx, "cmd 0x%X, PIN type 0x%X, PIN reference %i, PIN-1 %p:%zu, PIN-2 %p:%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2476|    215|			data->cmd, data->pin_type, data->pin_reference,
 2477|    215|			data->pin1.data, data->pin1.len, data->pin2.data, data->pin2.len);
 2478|       |
 2479|    215|	switch (data->cmd)   {
 2480|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2480:2): [True: 0, False: 215]
  ------------------
 2481|      0|		rv = iasecc_pin_verify(card, data);
 2482|      0|		break;
 2483|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2483:2): [True: 0, False: 215]
  ------------------
 2484|      0|		if (data->pin_type == SC_AC_AUT)
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2484:7): [True: 0, False: 0]
  ------------------
 2485|      0|			rv = iasecc_keyset_change(card, data);
 2486|      0|		else
 2487|      0|			rv = iasecc_pin_change(card, data);
 2488|      0|		break;
 2489|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2489:2): [True: 0, False: 215]
  ------------------
 2490|      0|		rv = iasecc_pin_reset(card, data);
 2491|      0|		break;
 2492|    215|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|    215|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2492:2): [True: 215, False: 0]
  ------------------
 2493|    215|		rv = iasecc_pin_get_info(card, data);
 2494|    215|		break;
 2495|      0|	default:
  ------------------
  |  Branch (2495:2): [True: 0, False: 215]
  ------------------
 2496|      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__
  |  |  ------------------
  ------------------
 2497|      0|		rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2498|    215|	}
 2499|       |
 2500|    215|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    215|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    215|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    215|	int _ret = r; \
  |  |  |  |  155|    215|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 215, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    215|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    215|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 215, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    215|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    215|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    215|	return _ret; \
  |  |  |  |  163|    215|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2501|    215|}
card-iasecc.c:iasecc_pin_get_status:
 1936|    215|{
 1937|    215|	struct sc_context *ctx = card->ctx;
 1938|    215|	struct sc_pin_cmd_data info;
 1939|    215|	int rv;
 1940|       |
 1941|    215|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    215|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    215|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    215|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    215|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 215]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1942|       |
 1943|    215|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    215|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1943:6): [True: 0, False: 215]
  ------------------
 1944|    215|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1945|       |
 1946|    215|	memset(&info, 0, sizeof(info));
 1947|    215|	info.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|    215|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1948|    215|	info.pin_type = data->pin_type;
 1949|    215|	info.pin_reference = data->pin_reference;
 1950|       |
 1951|    215|	rv = iso_ops->pin_cmd(card, &info);
 1952|    215|	LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
  ------------------
  |  |  174|    215|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    215|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    215|	int _ret = (r); \
  |  |  |  |  168|    215|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 201]
  |  |  |  |  ------------------
  |  |  |  |  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|    215|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 201]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1953|       |
 1954|    201|	data->pin1.max_tries = info.pin1.max_tries;
 1955|    201|	data->pin1.tries_left = info.pin1.tries_left;
 1956|    201|	data->pin1.logged_in = info.pin1.logged_in;
 1957|       |
 1958|    201|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    201|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    201|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    201|	int _ret = r; \
  |  |  |  |  155|    201|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 201, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    201|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 201]
  |  |  |  |  ------------------
  |  |  |  |  157|    201|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    201|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    201|	return _ret; \
  |  |  |  |  163|    201|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1959|    201|}
card-iasecc.c:iasecc_pin_get_policy:
 2055|    201|{
 2056|    201|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 2057|    201|	struct sc_context *ctx = card->ctx;
 2058|    201|	struct sc_file *save_current_df = NULL, *save_current_ef = NULL;
 2059|    201|	struct iasecc_sdo sdo = {0};
 2060|    201|	struct sc_path path;
 2061|    201|	int rv;
 2062|       |
 2063|    201|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    201|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    201|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    201|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    201|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 201]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2064|    201|	sc_log(ctx, "iasecc_pin_get_policy(card:%p)", card);
  ------------------
  |  |   71|    201|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2065|       |
 2066|    201|	if (data->pin_type != SC_AC_CHV)   {
  ------------------
  |  |  151|    201|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2066:6): [True: 0, False: 201]
  ------------------
 2067|      0|		rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2068|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "PIN policy only available for CHV 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2069|      0|	}
 2070|       |
 2071|    201|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (2071:6): [True: 201, False: 0]
  |  Branch (2071:26): [True: 7, False: 194]
  ------------------
 2072|      7|		sc_file_dup(&save_current_df, prv->cache.current_df);
 2073|      7|		if (save_current_df == NULL) {
  ------------------
  |  Branch (2073:7): [True: 0, False: 7]
  ------------------
 2074|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2075|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "Cannot duplicate current DF 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2076|      0|		}
 2077|      7|	}
 2078|       |
 2079|    201|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (2079:6): [True: 201, False: 0]
  |  Branch (2079:26): [True: 6, False: 195]
  ------------------
 2080|      6|		sc_file_dup(&save_current_ef, prv->cache.current_ef);
 2081|      6|		if (save_current_ef == NULL) {
  ------------------
  |  Branch (2081:7): [True: 0, False: 6]
  ------------------
 2082|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2083|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "Cannot duplicate current EF 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2084|      0|		}
 2085|      6|	}
 2086|       |
 2087|    201|	if (!(data->pin_reference & IASECC_OBJECT_REF_LOCAL) && prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  |   59|    201|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2087:6): [True: 201, False: 0]
  |  Branch (2087:58): [True: 201, False: 0]
  |  Branch (2087:78): [True: 7, False: 194]
  ------------------
 2088|      7|		sc_format_path("3F00", &path);
 2089|      7|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      7|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 2090|      7|		rv = iasecc_select_file(card, &path, NULL);
 2091|      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: 5, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2092|      7|	}
 2093|       |
 2094|    196|	sdo.sdo_class = IASECC_SDO_CLASS_CHV;
  ------------------
  |  |   98|    196|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
 2095|       |
 2096|    196|	sdo.sdo_ref = data->pin_reference & ~IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    196|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2097|       |
 2098|    196|	sc_log(ctx, "reference %i", sdo.sdo_ref);
  ------------------
  |  |   71|    196|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2099|       |
 2100|    196|	rv = iasecc_sdo_get_data(card, &sdo);
 2101|    196|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot get SDO PIN data");
  ------------------
  |  |  184|    196|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    196|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    196|	int _ret = (r); \
  |  |  |  |  178|    196|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 196, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    196|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    196|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    196|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    196|		goto err; \
  |  |  |  |  182|    196|	} \
  |  |  |  |  183|    196|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2102|       |
 2103|      0|	if (sdo.docp.acls_contact.size == 0) {
  ------------------
  |  Branch (2103:6): [True: 0, False: 0]
  ------------------
 2104|      0|		rv = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2105|      0|		LOG_TEST_GOTO_ERR(ctx, rv, "Extremely strange ... there is no ACLs");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2106|      0|	}
 2107|       |
 2108|      0|	sc_log(ctx, "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__
  |  |  ------------------
  ------------------
 2109|       |
 2110|      0|	memcpy(pin->scbs, sdo.docp.scbs, sizeof(pin->scbs));
 2111|       |
 2112|      0|	pin->min_length = (sdo.data.chv.size_min.value ? *sdo.data.chv.size_min.value : -1);
  ------------------
  |  Branch (2112:21): [True: 0, False: 0]
  ------------------
 2113|      0|	pin->max_length = (sdo.data.chv.size_max.value ? *sdo.data.chv.size_max.value : -1);
  ------------------
  |  Branch (2113:21): [True: 0, False: 0]
  ------------------
 2114|      0|	pin->tries_maximum = (sdo.docp.tries_maximum.value ? *sdo.docp.tries_maximum.value : -1);
  ------------------
  |  Branch (2114:24): [True: 0, False: 0]
  ------------------
 2115|      0|	pin->tries_remaining = (sdo.docp.tries_remaining.value ? *sdo.docp.tries_remaining.value : -1);
  ------------------
  |  Branch (2115:26): [True: 0, False: 0]
  ------------------
 2116|      0|	if (sdo.docp.size.value && sdo.docp.size.size <= sizeof(int)) {
  ------------------
  |  Branch (2116:6): [True: 0, False: 0]
  |  Branch (2116:29): [True: 0, False: 0]
  ------------------
 2117|      0|		unsigned int n = 0;
 2118|      0|		unsigned int i;
 2119|      0|		for (i=0; i<sdo.docp.size.size; i++)
  ------------------
  |  Branch (2119:13): [True: 0, False: 0]
  ------------------
 2120|      0|			n = (n << 8) + *(sdo.docp.size.value + i);
 2121|      0|		pin->stored_length = n;
 2122|      0|	} else {
 2123|      0|		pin->stored_length = -1;
 2124|      0|	}
 2125|       |
 2126|      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__
  |  |  ------------------
  ------------------
 2127|      0|	       pin->max_length, pin->min_length, pin->tries_maximum, pin->tries_remaining);
 2128|       |
 2129|      0|	if (save_current_df)   {
  ------------------
  |  Branch (2129:6): [True: 0, False: 0]
  ------------------
 2130|      0|		sc_log(ctx, "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__
  |  |  ------------------
  ------------------
 2131|      0|		rv = iasecc_select_file(card, &save_current_df->path, NULL);
 2132|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2133|      0|	}
 2134|       |
 2135|      0|	if (save_current_ef)   {
  ------------------
  |  Branch (2135:6): [True: 0, False: 0]
  ------------------
 2136|      0|		sc_log(ctx, "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__
  |  |  ------------------
  ------------------
 2137|      0|		rv = iasecc_select_file(card, &save_current_ef->path, NULL);
 2138|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2139|      0|	}
 2140|       |
 2141|    201|err:
 2142|    201|	iasecc_sdo_free_fields(card, &sdo);
 2143|    201|	sc_file_free(save_current_df);
 2144|    201|	sc_file_free(save_current_ef);
 2145|       |
 2146|    201|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    201|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    201|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    201|	int _ret = r; \
  |  |  |  |  155|    201|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 201, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    201|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    201|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 201, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    201|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    201|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    201|	return _ret; \
  |  |  |  |  163|    201|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2147|    201|}
card-iasecc.c:iasecc_pin_get_info:
 2152|    215|{
 2153|    215|	struct sc_context *ctx = card->ctx;
 2154|    215|	struct iasecc_pin_policy policy;
 2155|    215|	int rv;
 2156|       |
 2157|    215|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    215|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    215|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    215|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    215|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 215]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2158|    215|	sc_log(ctx, "iasecc_pin_get_info(card:%p)", card);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2159|       |
 2160|       |	/*
 2161|       |	 * Get PIN status first and thereafter update with info from PIN policy, when available.
 2162|       |	 * The first one is typically used for the PIN verification status and number of remaining
 2163|       |	 * tries, and the second one for the maximum tries. If a field is present in both, the
 2164|       |	 * policy takes precedence.
 2165|       |	 */
 2166|    215|	rv = iasecc_pin_get_status(card, data);
 2167|    215|	LOG_TEST_RET(ctx, rv, "Failed to get PIN status");
  ------------------
  |  |  174|    215|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    215|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    215|	int _ret = (r); \
  |  |  |  |  168|    215|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14, False: 201]
  |  |  |  |  ------------------
  |  |  |  |  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|    215|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 201]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2168|       |
 2169|    201|	rv = iasecc_pin_get_policy(card, data, &policy);
 2170|    201|	LOG_TEST_RET(ctx, rv, "Failed to get PIN policy");
  ------------------
  |  |  174|    201|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    201|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    201|	int _ret = (r); \
  |  |  |  |  168|    201|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 201, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    201|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2171|       |
 2172|       |	/*
 2173|       |	 * We only care about the tries_xxx fields in the PIN policy, since the other ones are not
 2174|       |	 * commonly expected or used in a SC_PIN_CMD_GET_INFO response.	Note that max_tries is
 2175|       |	 * always taken from the policy, since it is never expected to be available in status (it
 2176|       |	 * is set to -1 when not available in policy).
 2177|       |	 */
 2178|      0|	data->pin1.max_tries = policy.tries_maximum;
 2179|      0|	if (policy.tries_remaining >= 0)
  ------------------
  |  Branch (2179:6): [True: 0, False: 0]
  ------------------
 2180|      0|		data->pin1.tries_left = policy.tries_remaining;
 2181|       |
 2182|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2183|      0|}

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

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

sc_get_itacns_driver:
  605|  16.1k|{
  606|  16.1k|	return sc_get_driver();
  607|  16.1k|}
card-itacns.c:sc_get_driver:
  585|  16.1k|{
  586|  16.1k|	if (!default_ops)
  ------------------
  |  Branch (586:6): [True: 1, False: 16.1k]
  ------------------
  587|      1|		default_ops = sc_get_iso7816_driver()->ops;
  588|  16.1k|	itacns_ops = *default_ops;
  589|  16.1k|	itacns_ops.match_card = itacns_match_card;
  590|  16.1k|	itacns_ops.init = itacns_init;
  591|  16.1k|	itacns_ops.finish = itacns_finish;
  592|  16.1k|	itacns_ops.card_reader_lock_obtained = itacns_card_reader_lock_obtained;
  593|  16.1k|	itacns_ops.set_security_env = itacns_set_security_env;
  594|  16.1k|	itacns_ops.restore_security_env = itacns_restore_security_env;
  595|  16.1k|	itacns_ops.pin_cmd = itacns_pin_cmd;
  596|  16.1k|	itacns_ops.read_binary = itacns_read_binary;
  597|  16.1k|	itacns_ops.list_files = itacns_list_files;
  598|  16.1k|	itacns_ops.select_file = itacns_select_file;
  599|  16.1k|	itacns_ops.card_ctl = itacns_card_ctl;
  600|  16.1k|	itacns_ops.get_challenge = itacns_get_challenge;
  601|  16.1k|	return &itacns_drv;
  602|  16.1k|}
card-itacns.c:itacns_match_card:
  161|  4.00k|{
  162|  4.00k|	int r = 0;
  163|       |
  164|       |	/* Try table first */
  165|  4.00k|	r = _sc_match_atr(card, itacns_atrs, &card->type);
  166|  4.00k|	if(r >= 0) return 1;
  ------------------
  |  Branch (166:5): [True: 144, False: 3.85k]
  ------------------
  167|       |
  168|  3.85k|	if (itacns_match_cns_card(card)) {
  ------------------
  |  Branch (168:6): [True: 38, False: 3.81k]
  ------------------
  169|     38|		if (card->type == SC_CARD_TYPE_ITACNS_CNS &&
  ------------------
  |  Branch (169:7): [True: 36, False: 2]
  ------------------
  170|     36|				card->reader->atr_info.hist_bytes[3] == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   13|     36|#define ITACNS_MASKMAN_STINCARD		0x09
  ------------------
  |  Branch (170:5): [True: 8, False: 28]
  ------------------
  171|      8|			r = itacns_match_cns_model(card);
  172|      8|			if (r == 0)
  ------------------
  |  Branch (172:8): [True: 7, False: 1]
  ------------------
  173|      7|				itacns_match_cns_aid(card);
  174|      8|		}
  175|     38|		return 1;
  176|     38|	}
  177|  3.81k|	if (itacns_match_cie_card(card)) return 1;
  ------------------
  |  Branch (177:6): [True: 74, False: 3.74k]
  ------------------
  178|  3.74k|	if (itacns_match_cns_aid(card))
  ------------------
  |  Branch (178:6): [True: 4, False: 3.74k]
  ------------------
  179|      4|		return 1;
  180|       |
  181|       |	/* No card type was matched. */
  182|  3.74k|	return 0;
  183|  3.74k|}
card-itacns.c:itacns_match_cns_card:
  124|  3.85k|{
  125|  3.85k|	u8 manufacturer_code;
  126|  3.85k|	u8 manufacturer_mask;
  127|  3.85k|	u8 fw_major;
  128|       |
  129|  3.85k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (129:6): [True: 3.58k, False: 268]
  ------------------
  130|    268|	    0 != memcmp(card->reader->atr_info.hist_bytes+9, "CNS", 3))
  ------------------
  |  Branch (130:6): [True: 230, False: 38]
  ------------------
  131|  3.81k|		return 0;
  132|       |
  133|     38|	card->type = SC_CARD_TYPE_ITACNS_CNS;
  134|       |
  135|     38|	manufacturer_code = card->reader->atr_info.hist_bytes[2];
  136|     38|	manufacturer_mask = card->reader->atr_info.hist_bytes[3];
  137|     38|	fw_major = card->reader->atr_info.hist_bytes[4];
  138|       |
  139|     38|	if (manufacturer_code == ITACNS_ICMAN_INFINEON &&
  ------------------
  |  |    9|     76|#define ITACNS_ICMAN_INFINEON		0x05
  ------------------
  |  Branch (139:6): [True: 10, False: 28]
  ------------------
  140|     10|	    manufacturer_mask == ITACNS_MASKMAN_IDEMIA &&
  ------------------
  |  |   11|     48|#define ITACNS_MASKMAN_IDEMIA		0x05
  ------------------
  |  Branch (140:6): [True: 5, False: 5]
  ------------------
  141|      5|	    fw_major >= 32) {
  ------------------
  |  Branch (141:6): [True: 2, False: 3]
  ------------------
  142|      2|			card->type = SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021;
  143|      2|	}
  144|       |
  145|     38|	return 1;
  146|  3.85k|}
card-itacns.c:itacns_match_cns_model:
   89|     44|{
   90|     44|	static const u8 model[] = {'J', 'S', 'i', 'g', 'n', '4'};
   91|     44|	sc_apdu_t apdu;
   92|     44|	u8 rbuf[16];
   93|     44|	int r;
   94|       |
   95|     44|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x01, 0x80);
  ------------------
  |  |  292|     44|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   96|     44|	apdu.le = sizeof model;
   97|     44|	apdu.resp = rbuf;
   98|     44|	apdu.resplen = sizeof rbuf;
   99|     44|	r = sc_transmit_apdu(card, &apdu);
  100|     44|	if (r < 0)
  ------------------
  |  Branch (100:6): [True: 5, False: 39]
  ------------------
  101|      5|		return r;
  102|     39|	if (sc_check_sw(card, apdu.sw1, apdu.sw2) != SC_SUCCESS)
  ------------------
  |  |   28|     39|#define SC_SUCCESS				0
  ------------------
  |  Branch (102:6): [True: 11, False: 28]
  ------------------
  103|     11|		return 0;
  104|       |
  105|     28|	if (apdu.resplen < sizeof model ||
  ------------------
  |  Branch (105:6): [True: 10, False: 18]
  ------------------
  106|     18|			memcmp(rbuf, model, sizeof model) != 0)
  ------------------
  |  Branch (106:4): [True: 12, False: 6]
  ------------------
  107|     22|		return 0;
  108|       |
  109|      6|	card->type = SC_CARD_TYPE_ITACNS_CNS_JSIGN4;
  110|      6|	return 1;
  111|     28|}
card-itacns.c:itacns_match_cns_aid:
  115|  3.75k|{
  116|  3.75k|	if (iso7816_select_aid(card, itacns_cns_aid, sizeof itacns_cns_aid,
  ------------------
  |  Branch (116:6): [True: 3.72k, False: 31]
  ------------------
  117|  3.75k|			    NULL, NULL) != SC_SUCCESS)
  ------------------
  |  |   28|  3.75k|#define SC_SUCCESS				0
  ------------------
  118|  3.72k|		return 0;
  119|       |
  120|     31|	return itacns_match_cns_model(card) > 0;
  121|  3.75k|}
card-itacns.c:itacns_match_cie_card:
  149|  3.81k|{
  150|  3.81k|	u8 h7_to_h15[] = { 0x02, 'I', 'T', 'I', 'D', 0x20, 0x20, 0x31, 0x80, };
  151|  3.81k|	if (15 != card->reader->atr_info.hist_bytes_len ||
  ------------------
  |  Branch (151:6): [True: 3.58k, False: 230]
  ------------------
  152|    230|	    0 != memcmp(card->reader->atr_info.hist_bytes+6,
  ------------------
  |  Branch (152:6): [True: 156, False: 74]
  ------------------
  153|    230|			h7_to_h15, sizeof h7_to_h15))
  154|  3.74k|		return 0;
  155|       |
  156|     74|	card->type = SC_CARD_TYPE_ITACNS_CIE_V2;
  157|     74|	return 1;
  158|  3.81k|}
card-itacns.c:itacns_init:
  190|    260|{
  191|    260|	unsigned long	flags;
  192|       |
  193|    260|	SC_FUNC_CALLED(card->ctx, 1);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  194|       |
  195|    260|	card->name = "CNS card";
  196|    260|	card->cla = 0x00;
  197|       |
  198|    260|	card->drv_data = calloc(1, sizeof(itacns_drv_data_t));
  199|    260|	if (!card->drv_data)
  ------------------
  |  Branch (199:6): [True: 0, False: 260]
  ------------------
  200|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  201|       |
  202|    260|	if (card->type == SC_CARD_TYPE_ITACNS_CNS ||
  ------------------
  |  Branch (202:6): [True: 35, False: 225]
  ------------------
  203|    225|			card->type == SC_CARD_TYPE_ITACNS_CNS_JSIGN4)
  ------------------
  |  Branch (203:4): [True: 5, False: 220]
  ------------------
  204|     40|		itacns_init_cns_card(card);
  205|       |
  206|    260|	if (card->reader->atr_info.hist_bytes_len >= 6) {
  ------------------
  |  Branch (206:6): [True: 240, False: 20]
  ------------------
  207|    240|		DRVDATA(card)->ic_manufacturer_code = card->reader->atr_info.hist_bytes[2];
  ------------------
  |  |   64|    240|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  208|    240|		DRVDATA(card)->mask_manufacturer_code = card->reader->atr_info.hist_bytes[3];
  ------------------
  |  |   64|    240|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
  209|    240|		card->version.fw_major = card->reader->atr_info.hist_bytes[4];
  210|    240|		card->version.fw_minor = card->reader->atr_info.hist_bytes[5];
  211|    240|	}
  212|       |
  213|    260|	if (card->type == SC_CARD_TYPE_ITACNS_CNS_JSIGN4)
  ------------------
  |  Branch (213:6): [True: 5, False: 255]
  ------------------
  214|      5|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|      5|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  215|       |
  216|       |	/* Set up algorithm info. */
  217|    260|	flags = SC_ALGORITHM_NEED_USAGE
  ------------------
  |  |   95|    260|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  218|    260|		| SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  102|    260|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  219|    260|		| SC_ALGORITHM_RSA_HASHES
  ------------------
  |  |  142|    260|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  220|    260|		;
  221|       |
  222|    260|	if (card->type == SC_CARD_TYPE_ITACNS_CNS_JSIGN4 ||
  ------------------
  |  Branch (222:6): [True: 5, False: 255]
  ------------------
  223|    255|			(card->version.hw_major >= 1 && card->version.hw_minor >= 1) ||
  ------------------
  |  Branch (223:5): [True: 22, False: 233]
  |  Branch (223:36): [True: 13, False: 9]
  ------------------
  224|    242|			card->type == SC_CARD_TYPE_ITACNS_CNS_IDEMIA_2021) {
  ------------------
  |  Branch (224:4): [True: 130, False: 112]
  ------------------
  225|    148|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|    148|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  226|    148|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  227|    148|	} else {
  228|    112|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  229|    112|	}
  230|    260|	return SC_SUCCESS;
  ------------------
  |  |   28|    260|#define SC_SUCCESS				0
  ------------------
  231|    260|}
card-itacns.c:itacns_init_cns_card:
   67|     40|{
   68|     40|	if (15 != card->reader->atr_info.hist_bytes_len)
  ------------------
  |  Branch (68:6): [True: 4, False: 36]
  ------------------
   69|      4|		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: 32, False: 3]
  ------------------
   77|     32|		char version[8];
   78|     32|		snprintf(version, sizeof(version), "%d.%d", card->version.hw_major, card->version.hw_minor);
   79|     32|		sc_log(card->ctx, "CNS card version %s; no official specifications "
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   80|     32|		       "are published. Proceeding anyway.\n", version);
   81|     32|	}
   82|     36|}
card-itacns.c:itacns_finish:
  252|    260|{
  253|    260|	if(card->drv_data) {
  ------------------
  |  Branch (253:5): [True: 260, False: 0]
  ------------------
  254|    260|		free(card->drv_data);
  255|    260|	}
  256|    260|	return 0;
  257|    260|}
card-itacns.c:itacns_card_reader_lock_obtained:
  235|  4.05k|{
  236|  4.05k|	int r;
  237|       |
  238|  4.05k|	if (card->type != SC_CARD_TYPE_ITACNS_CNS_JSIGN4)
  ------------------
  |  Branch (238:6): [True: 4.04k, False: 5]
  ------------------
  239|  4.04k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.04k|#define SC_SUCCESS				0
  ------------------
  240|       |
  241|      5|	r = itacns_match_cns_model(card);
  242|      5|	if (r < 0)
  ------------------
  |  Branch (242:6): [True: 1, False: 4]
  ------------------
  243|      1|		return r;
  244|      4|	if (r > 0)
  ------------------
  |  Branch (244:6): [True: 1, False: 3]
  ------------------
  245|      1|		return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  246|       |
  247|      3|	return iso7816_select_aid(card, itacns_cns_aid, sizeof itacns_cns_aid,
  248|      3|			NULL, NULL);
  249|      4|}
card-itacns.c:itacns_pin_cmd:
  371|     13|{
  372|     13|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|     26|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (372:6): [True: 13, False: 0]
  ------------------
  373|     13|			card->type == SC_CARD_TYPE_ITACNS_CNS_JSIGN4 &&
  ------------------
  |  Branch (373:4): [True: 1, False: 12]
  ------------------
  374|      1|			data->pin_reference != 0x10 && data->pin_reference != 0x11) {
  ------------------
  |  Branch (374:4): [True: 1, False: 0]
  |  Branch (374:35): [True: 1, False: 0]
  ------------------
  375|      1|		data->pin1.tries_left = -1;
  376|      1|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  377|      1|	}
  378|       |
  379|     12|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     12|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  380|       |	/* Enable backtracking for STIncard cards. */
  381|     12|	if(DRVDATA(card)->mask_manufacturer_code == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   64|     12|#define DRVDATA(card) ((itacns_drv_data_t *) card->drv_data)
  ------------------
              	if(DRVDATA(card)->mask_manufacturer_code == ITACNS_MASKMAN_STINCARD) {
  ------------------
  |  |   13|     12|#define ITACNS_MASKMAN_STINCARD		0x09
  ------------------
  |  Branch (381:5): [True: 3, False: 9]
  ------------------
  382|      3|		data->pin_reference |= 0x80;
  383|      3|	}
  384|       |
  385|       |	/* FIXME: the following values depend on what pin length was
  386|       |	 * used when creating the BS objects */
  387|     12|	if (data->pin1.max_length == 0)
  ------------------
  |  Branch (387:6): [True: 12, False: 0]
  ------------------
  388|     12|		data->pin1.max_length = 8;
  389|     12|	if (data->pin2.max_length == 0)
  ------------------
  |  Branch (389:6): [True: 12, False: 0]
  ------------------
  390|     12|		data->pin2.max_length = 8;
  391|     12|	return default_ops->pin_cmd(card, data);
  392|     13|}
card-itacns.c:itacns_read_binary:
  397|    659|{
  398|    659|	size_t already_read = 0;
  399|    659|	size_t requested;
  400|    659|	int r;
  401|    753|	while(1) {
  ------------------
  |  Branch (401:8): [True: 753, Folded]
  ------------------
  402|    753|		requested = count - already_read;
  403|    753|		if(requested > ITACNS_MAX_PAYLOAD)
  ------------------
  |  |   36|    753|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  |  Branch (403:6): [True: 333, False: 420]
  ------------------
  404|    333|			requested = ITACNS_MAX_PAYLOAD;
  ------------------
  |  |   36|    333|#define ITACNS_MAX_PAYLOAD 0xff
  ------------------
  405|    753|		r = default_ops->read_binary(card, (unsigned)(idx + already_read),
  406|    753|			&buf[already_read], requested, flags);
  407|    753|		if(r < 0)
  ------------------
  |  Branch (407:6): [True: 97, False: 656]
  ------------------
  408|     97|			return r;
  409|    656|		already_read += r;
  410|    656|		if (r == 0 || (size_t)r < requested || already_read == count) {
  ------------------
  |  Branch (410:7): [True: 87, False: 569]
  |  Branch (410:17): [True: 339, False: 230]
  |  Branch (410:42): [True: 136, False: 94]
  ------------------
  411|       |			/* We have finished */
  412|    562|			return (int)already_read;
  413|    562|		}
  414|    656|	}
  415|    659|}
card-itacns.c:itacns_select_file:
  502|  2.14k|{
  503|  2.14k|	int r;
  504|       |
  505|  2.14k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.14k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.14k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.14k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.14k]
  |  |  ------------------
  ------------------
  506|  2.14k|	r = default_ops->select_file(card, in_path, file);
  507|  2.14k|	if (r >= 0 && file) {
  ------------------
  |  Branch (507:6): [True: 692, False: 1.45k]
  |  Branch (507:16): [True: 147, False: 545]
  ------------------
  508|    147|		parse_sec_attr((*file), (*file)->sec_attr,
  509|    147|			(*file)->sec_attr_len);
  510|    147|	}
  511|  2.14k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.14k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.14k|	int _ret = r; \
  |  |  |  |  155|  2.14k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.14k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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.45k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.45k, False: 692]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.14k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.14k|	return _ret; \
  |  |  |  |  163|  2.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  512|  2.14k|}
card-itacns.c:parse_sec_attr:
  484|    147|{
  485|    147|	size_t i;
  486|    147|	const int *idx;
  487|       |
  488|    147|	idx = (file->type == SC_FILE_TYPE_DF) ?  df_acl : ef_acl;
  ------------------
  |  |  214|    147|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (488:8): [True: 9, False: 138]
  ------------------
  489|       |
  490|       |	/* acl defaults to 0xFF if unspecified */
  491|  1.47k|	for (i = 0; i < 9; i++) {
  ------------------
  |  Branch (491:14): [True: 1.32k, False: 147]
  ------------------
  492|  1.32k|		if (idx[i] != -1) {
  ------------------
  |  Branch (492:7): [True: 1.02k, False: 294]
  ------------------
  493|  1.02k|			add_acl_entry(file, idx[i],
  494|  1.02k|				(u8)((i < len) ? buf[i] : 0xFF));
  ------------------
  |  Branch (494:10): [True: 130, False: 899]
  ------------------
  495|  1.02k|		}
  496|  1.32k|	}
  497|    147|}
card-itacns.c:add_acl_entry:
  431|  1.02k|{
  432|  1.02k|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.02k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  433|       |
  434|  1.02k|	switch (byte) {
  435|     44|	case 0x00:
  ------------------
  |  Branch (435:2): [True: 44, False: 985]
  ------------------
  436|     44|		method = SC_AC_NONE;
  ------------------
  |  |  150|     44|#define SC_AC_NONE			0x00000000
  ------------------
  437|     44|		break;
  438|    900|	case 0xFF:
  ------------------
  |  Branch (438:2): [True: 900, False: 129]
  ------------------
  439|    910|	case 0x66:
  ------------------
  |  Branch (439:2): [True: 10, False: 1.01k]
  ------------------
  440|    910|		method = SC_AC_NEVER;
  ------------------
  |  |  163|    910|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  441|    910|		break;
  442|     75|	default:
  ------------------
  |  Branch (442:2): [True: 75, False: 954]
  ------------------
  443|     75|		if (byte > 0x1F) {
  ------------------
  |  Branch (443:7): [True: 45, False: 30]
  ------------------
  444|     45|			method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     45|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  445|     45|		} else {
  446|     30|			method = SC_AC_CHV;
  ------------------
  |  |  151|     30|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  447|     30|			key_ref = byte;
  448|     30|		}
  449|     75|		break;
  450|  1.02k|	}
  451|  1.02k|	sc_file_add_acl_entry(file, op, method, key_ref);
  452|  1.02k|}
card-itacns.c:itacns_card_ctl:
  567|    408|{
  568|    408|	switch (cmd) {
  ------------------
  |  Branch (568:10): [True: 13, False: 395]
  ------------------
  569|     13|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (569:3): [True: 13, False: 395]
  ------------------
  570|     13|		return itacns_get_serialnr(card, ptr);
  571|    408|	}
  572|    395|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    395|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  573|    408|}
card-itacns.c:itacns_get_serialnr:
  515|     13|{
  516|     13|	sc_path_t path;
  517|     13|	sc_file_t *file;
  518|     13|	size_t    len;
  519|     13|	int r;
  520|     13|	u8        rbuf[256];
  521|       |
  522|     13|	if (!serial) return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  |  Branch (522:6): [True: 0, False: 13]
  ------------------
  523|       |
  524|       |	/* see if we have cached serial number */
  525|     13|	if (card->serialnr.len) {
  ------------------
  |  Branch (525:6): [True: 0, False: 13]
  ------------------
  526|      0|		memcpy(serial, &card->serialnr, sizeof(*serial));
  527|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  528|      0|	}
  529|       |
  530|     13|	sc_log(card->ctx, "Reading EF_IDCarta.\n");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  531|       |
  532|     13|	sc_format_path("3F0010001003", &path);
  533|       |
  534|     13|	r = sc_select_file(card, &path, &file);
  535|     13|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     13|#define SC_SUCCESS				0
  ------------------
  |  Branch (535:6): [True: 7, False: 6]
  ------------------
  536|      7|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      7|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  537|      7|	}
  538|      6|	len = file->size;
  539|      6|	sc_file_free(file);
  540|       |
  541|       |	//Returned file->size should be 16.
  542|       |	//We choose to not consider it as critical, because some cards
  543|       |	//do not return FCI/FCP templates that include the file size.
  544|       |	//Notify abnormal length anyway.
  545|      6|	if (len != 16) {
  ------------------
  |  Branch (545:6): [True: 5, False: 1]
  ------------------
  546|      5|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  547|      5|				"Unexpected file length of EF_IDCarta (%lu)\n",
  548|      5|				(unsigned long) len);
  549|      5|	}
  550|       |
  551|      6|	r = sc_read_binary(card, 0, rbuf, 256, 0);
  552|      6|	if ( r != 16 ) {
  ------------------
  |  Branch (552:7): [True: 5, False: 1]
  ------------------
  553|      5|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      5|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  554|      5|	}
  555|       |
  556|       |	/* cache serial number */
  557|      1|	memcpy(card->serialnr.value, rbuf, 16);
  558|      1|	card->serialnr.len = 16;
  559|       |	/* copy and return serial number */
  560|      1|	memcpy(serial, &card->serialnr, sizeof(*serial));
  561|       |
  562|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  563|      6|}

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

sc_get_lteid_driver:
  578|  16.1k|{
  579|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  580|       |
  581|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (581:6): [True: 1, False: 16.1k]
  ------------------
  582|      1|		iso_ops = iso_drv->ops;
  583|       |
  584|  16.1k|	lteid_ops = *iso_ops;
  585|  16.1k|	lteid_ops.init = lteid_init;
  586|  16.1k|	lteid_ops.finish = lteid_finish;
  587|  16.1k|	lteid_ops.set_security_env = lteid_set_security_env;
  588|  16.1k|	lteid_ops.compute_signature = lteid_compute_signature;
  589|  16.1k|	lteid_ops.pin_cmd = lteid_pin_cmd;
  590|  16.1k|	lteid_ops.logout = lteid_logout;
  591|  16.1k|	lteid_ops.process_fci = lteid_process_fci;
  592|       |
  593|  16.1k|	return &lteid_drv;
  594|  16.1k|}

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

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

sc_get_muscle_driver:
  925|  16.1k|{
  926|  16.1k|	return sc_get_driver();
  927|  16.1k|}
card-muscle.c:sc_get_driver:
  893|  16.1k|{
  894|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  895|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (895:6): [True: 1, False: 16.1k]
  ------------------
  896|      1|		iso_ops = iso_drv->ops;
  897|       |
  898|  16.1k|	muscle_ops = *iso_drv->ops;
  899|  16.1k|	muscle_ops.check_sw = muscle_check_sw;
  900|  16.1k|	muscle_ops.pin_cmd = muscle_pin_cmd;
  901|  16.1k|	muscle_ops.match_card = muscle_match_card;
  902|  16.1k|	muscle_ops.init = muscle_init;
  903|  16.1k|	muscle_ops.finish = muscle_finish;
  904|       |
  905|  16.1k|	muscle_ops.get_challenge = muscle_get_challenge;
  906|       |
  907|  16.1k|	muscle_ops.set_security_env = muscle_set_security_env;
  908|  16.1k|	muscle_ops.restore_security_env = muscle_restore_security_env;
  909|  16.1k|	muscle_ops.compute_signature = muscle_compute_signature;
  910|  16.1k|	muscle_ops.decipher = muscle_decipher;
  911|  16.1k|	muscle_ops.card_ctl = muscle_card_ctl;
  912|  16.1k|	muscle_ops.read_binary = muscle_read_binary;
  913|  16.1k|	muscle_ops.update_binary = muscle_update_binary;
  914|  16.1k|	muscle_ops.create_file = muscle_create_file;
  915|  16.1k|	muscle_ops.select_file = muscle_select_file;
  916|  16.1k|	muscle_ops.delete_file = muscle_delete_file;
  917|  16.1k|	muscle_ops.list_files = muscle_list_files;
  918|  16.1k|	muscle_ops.card_reader_lock_obtained = muscle_card_reader_lock_obtained;
  919|  16.1k|	muscle_ops.logout = muscle_logout;
  920|       |
  921|  16.1k|	return &muscle_drv;
  922|  16.1k|}
card-muscle.c:muscle_check_sw:
  831|  31.9k|static int muscle_check_sw(sc_card_t * card, unsigned int sw1, unsigned int sw2) {
  832|  31.9k|	if(sw1 == 0x9C) {
  ------------------
  |  Branch (832:5): [True: 151, False: 31.7k]
  ------------------
  833|    151|		switch(sw2) {
  ------------------
  |  Branch (833:10): [True: 141, False: 10]
  ------------------
  834|     14|			case 0x01: /* SW_NO_MEMORY_LEFT */
  ------------------
  |  Branch (834:4): [True: 14, False: 137]
  ------------------
  835|     14|				return SC_ERROR_NOT_ENOUGH_MEMORY;
  ------------------
  |  |   67|     14|#define SC_ERROR_NOT_ENOUGH_MEMORY		-1217
  ------------------
  836|     10|			case 0x02: /* SW_AUTH_FAILED */
  ------------------
  |  Branch (836:4): [True: 10, False: 141]
  ------------------
  837|     10|				return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     10|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  838|     10|			case 0x03: /* SW_OPERATION_NOT_ALLOWED */
  ------------------
  |  Branch (838:4): [True: 10, False: 141]
  ------------------
  839|     10|				return SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|     10|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  840|     10|			case 0x05: /* SW_UNSUPPORTED_FEATURE */
  ------------------
  |  Branch (840:4): [True: 10, False: 141]
  ------------------
  841|     10|				return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|     10|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  842|     10|			case 0x06: /* SW_UNAUTHORIZED */
  ------------------
  |  Branch (842:4): [True: 10, False: 141]
  ------------------
  843|     10|				return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     10|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  844|     11|			case 0x07: /* SW_OBJECT_NOT_FOUND */
  ------------------
  |  Branch (844:4): [True: 11, False: 140]
  ------------------
  845|     11|				return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|     11|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  846|     12|			case 0x08: /* SW_OBJECT_EXISTS */
  ------------------
  |  Branch (846:4): [True: 12, False: 139]
  ------------------
  847|     12|				return SC_ERROR_FILE_ALREADY_EXISTS;
  ------------------
  |  |   65|     12|#define SC_ERROR_FILE_ALREADY_EXISTS		-1215
  ------------------
  848|     12|			case 0x09: /* SW_INCORRECT_ALG */
  ------------------
  |  Branch (848:4): [True: 12, False: 139]
  ------------------
  849|     12|				return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|     12|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  850|     10|			case 0x0B: /* SW_SIGNATURE_INVALID */
  ------------------
  |  Branch (850:4): [True: 10, False: 141]
  ------------------
  851|     10|				return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|     10|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  852|     10|			case 0x0C: /* SW_IDENTITY_BLOCKED */
  ------------------
  |  Branch (852:4): [True: 10, False: 141]
  ------------------
  853|     10|				return SC_ERROR_AUTH_METHOD_BLOCKED;
  ------------------
  |  |   62|     10|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  854|     11|			case 0x0F: /* SW_INVALID_PARAMETER */
  ------------------
  |  Branch (854:4): [True: 11, False: 140]
  ------------------
  855|     22|			case 0x10: /* SW_INCORRECT_P1 */
  ------------------
  |  Branch (855:4): [True: 11, False: 140]
  ------------------
  856|     32|			case 0x11: /* SW_INCORRECT_P2 */
  ------------------
  |  Branch (856:4): [True: 10, False: 141]
  ------------------
  857|     32|				return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|     32|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  858|    151|		}
  859|    151|	}
  860|  31.7k|	return iso_ops->check_sw(card, sw1, sw2);
  861|  31.9k|}
card-muscle.c:muscle_match_card:
   82|  6.76k|{
   83|  6.76k|	sc_apdu_t apdu;
   84|  6.76k|	u8 response[64];
   85|  6.76k|	int r;
   86|       |
   87|  6.76k|	if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) == 1) {
  ------------------
  |  Branch (87:6): [True: 428, False: 6.33k]
  ------------------
   88|       |		/* Muscle applet is present, check the protocol version to be sure */
   89|    428|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x3C, 0x00, 0x00);
  ------------------
  |  |  301|    428|#define SC_APDU_CASE_2			0x22
  ------------------
   90|    428|		apdu.cla = 0xB0;
   91|    428|		apdu.le = 64;
   92|    428|		apdu.resplen = 64;
   93|    428|		apdu.resp = response;
   94|    428|		r = sc_transmit_apdu(card, &apdu);
   95|    428|		if (r == SC_SUCCESS && apdu.resplen > 1 && response[0] == 0x01) {
  ------------------
  |  |   28|    856|#define SC_SUCCESS				0
  ------------------
  |  Branch (95:7): [True: 403, False: 25]
  |  Branch (95:26): [True: 46, False: 357]
  |  Branch (95:46): [True: 3, False: 43]
  ------------------
   96|      3|			card->type = SC_CARD_TYPE_MUSCLE_V1;
   97|    425|		} else {
   98|    425|			card->type = SC_CARD_TYPE_MUSCLE_GENERIC;
   99|    425|		}
  100|    428|		return 1;
  101|    428|	}
  102|  6.33k|	return 0;
  103|  6.76k|}
card-muscle.c:muscle_init:
  473|    428|{
  474|    428|	muscle_private_t *priv;
  475|    428|	int r;
  476|       |
  477|    428|	card->name = "MuscleApplet";
  478|    428|	card->drv_data = malloc(sizeof(muscle_private_t));
  479|    428|	if(!card->drv_data) {
  ------------------
  |  Branch (479:5): [True: 0, False: 428]
  ------------------
  480|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|      0|	}
  482|    428|	memset(card->drv_data, 0, sizeof(muscle_private_t));
  483|    428|	priv = MUSCLE_DATA(card);
  ------------------
  |  |   57|    428|#define MUSCLE_DATA(card) ( (muscle_private_t*)card->drv_data )
  ------------------
  484|    428|	priv->verifiedPins = 0;
  485|    428|	priv->fs = mscfs_new();
  486|    428|	if(!priv->fs) {
  ------------------
  |  Branch (486:5): [True: 0, False: 428]
  ------------------
  487|      0|		free(card->drv_data);
  488|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  489|      0|	}
  490|    428|	priv->fs->udata = card;
  491|    428|	priv->fs->listFile = _listFile;
  492|       |
  493|    428|	card->cla = 0xB0;
  494|       |
  495|    428|	card->flags |= SC_CARD_FLAG_RNG;
  ------------------
  |  |  536|    428|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  496|    428|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    428|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  497|       |
  498|       |	/* Card type detection */
  499|    428|	r = _sc_match_atr(card, muscle_atrs, &card->type);
  500|    428|	if (r < 0) {
  ------------------
  |  Branch (500:6): [True: 427, False: 1]
  ------------------
  501|    427|		sc_log(card->ctx, "Failed to match the ATRs");
  ------------------
  |  |   71|    427|#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|    427|	}
  503|    428|	if(card->type == SC_CARD_TYPE_MUSCLE_ETOKEN_72K) {
  ------------------
  |  Branch (503:5): [True: 0, False: 428]
  ------------------
  504|      0|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|      0|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  505|      0|	}
  506|    428|	if(card->type == SC_CARD_TYPE_MUSCLE_JCOP241) {
  ------------------
  |  Branch (506:5): [True: 1, False: 427]
  ------------------
  507|      1|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|      1|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  508|      1|	}
  509|    428|	if (!(card->caps & SC_CARD_CAP_APDU_EXT)) {
  ------------------
  |  |  547|    428|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (509:6): [True: 427, False: 1]
  ------------------
  510|    427|		card->max_recv_size = 255;
  511|    427|		card->max_send_size = 255;
  512|    427|	}
  513|    428|	if(card->type == SC_CARD_TYPE_MUSCLE_JCOP242R2_NO_EXT_APDU) {
  ------------------
  |  Branch (513:5): [True: 0, False: 428]
  ------------------
  514|       |	        /* Tyfone JCOP v242R2 card that doesn't support extended APDUs */
  515|      0|	}
  516|       |
  517|       |
  518|       |	/* FIXME: Card type detection */
  519|    428|	if (1) {
  ------------------
  |  Branch (519:6): [True: 428, Folded]
  ------------------
  520|    428|		unsigned long flags;
  521|       |
  522|    428|		flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    428|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  523|    428|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    428|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  524|    428|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    428|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  525|       |
  526|    428|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  527|    428|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  528|    428|	}
  529|    428|	return SC_SUCCESS;
  ------------------
  |  |   28|    428|#define SC_SUCCESS				0
  ------------------
  530|    428|}
card-muscle.c:_listFile:
  467|  31.9k|{
  468|  31.9k|	int next = reset ? 0x00 : 0x01;
  ------------------
  |  Branch (468:13): [True: 1.14k, False: 30.8k]
  ------------------
  469|  31.9k|	return msc_list_objects( (sc_card_t*)udata, next, file);
  470|  31.9k|}
card-muscle.c:muscle_finish:
   68|    428|{
   69|    428|	muscle_private_t *priv = MUSCLE_DATA(card);
  ------------------
  |  |   57|    428|#define MUSCLE_DATA(card) ( (muscle_private_t*)card->drv_data )
  ------------------
   70|    428|	if (priv) {
  ------------------
  |  Branch (70:6): [True: 428, False: 0]
  ------------------
   71|    428|		mscfs_free(priv->fs);
   72|    428|		free(priv);
   73|       |		card->drv_data = NULL;
   74|    428|	}
   75|    428|	return 0;
   76|    428|}
card-muscle.c:muscle_read_binary:
  202|    367|{
  203|    367|	mscfs_t *fs = MUSCLE_FS(card);
  ------------------
  |  |   58|    367|#define MUSCLE_FS(card) ( ((muscle_private_t*)card->drv_data)->fs )
  ------------------
  204|    367|	int r;
  205|    367|	msc_id objectId;
  206|    367|	u8* oid = objectId.id;
  207|    367|	mscfs_file_t *file;
  208|       |
  209|    367|	r = mscfs_check_selection(fs, -1);
  210|    367|	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 (210:5): [True: 0, False: 367]
  ------------------
  211|    367|	file = &fs->cache.array[fs->currentFileIndex];
  212|    367|	objectId = file->objectId;
  213|       |	/* memcpy(objectId.id, file->objectId.id, 4); */
  214|    367|	if(!file->ef) {
  ------------------
  |  Branch (214:5): [True: 67, False: 300]
  ------------------
  215|     67|		oid[0] = oid[2];
  216|     67|		oid[1] = oid[3];
  217|     67|		oid[2] = oid[3] = 0;
  218|     67|	}
  219|    367|	r = msc_read_object(card, objectId, idx, buf, count);
  220|    367|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    367|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    367|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    367|	int _ret = r; \
  |  |  |  |  155|    367|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 80, False: 287]
  |  |  |  |  ------------------
  |  |  |  |  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|     80|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 80, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     80|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    287|	} else { \
  |  |  |  |  159|    287|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    287|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    287|	} \
  |  |  |  |  162|    367|	return _ret; \
  |  |  |  |  163|    367|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  221|    367|}
card-muscle.c:muscle_select_file:
  443|  2.11k|{
  444|  2.11k|	int r;
  445|       |
  446|  2.11k|	if (card == NULL || path_in == NULL)
  ------------------
  |  Branch (446:6): [True: 0, False: 2.11k]
  |  Branch (446:22): [True: 0, False: 2.11k]
  ------------------
  447|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  448|       |
  449|  2.11k|	switch (path_in->type) {
  450|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (450:2): [True: 0, False: 2.11k]
  ------------------
  451|      0|		r = select_item(card, path_in, file_out, 1);
  452|      0|		break;
  453|    822|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    822|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (453:2): [True: 822, False: 1.29k]
  ------------------
  454|    822|		r = select_item(card, path_in, file_out, 0);
  455|    822|		break;
  456|  1.29k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  1.29k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (456:2): [True: 1.29k, False: 822]
  ------------------
  457|  1.29k|		r = select_item(card, path_in, file_out, -1);
  458|  1.29k|		break;
  459|      0|	default:
  ------------------
  |  Branch (459:2): [True: 0, False: 2.11k]
  ------------------
  460|      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]
  |  |  ------------------
  ------------------
  461|  2.11k|	}
  462|  2.11k|	if(r > 0) r = 0;
  ------------------
  |  Branch (462:5): [True: 0, False: 2.11k]
  ------------------
  463|  2.11k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
  ------------------
  |  |  153|  2.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.11k|	int _ret = r; \
  |  |  155|  2.11k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.11k, False: 0]
  |  |  ------------------
  |  |  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|  1.65k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.65k, False: 460]
  |  |  ------------------
  |  |  157|  2.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.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|  2.11k|	return _ret; \
  |  |  163|  2.11k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  464|  2.11k|}
card-muscle.c:select_item:
  377|  2.11k|{
  378|  2.11k|	mscfs_t *fs = MUSCLE_FS(card);
  ------------------
  |  |   58|  2.11k|#define MUSCLE_FS(card) ( ((muscle_private_t*)card->drv_data)->fs )
  ------------------
  379|  2.11k|	mscfs_file_t *file_data = NULL;
  380|  2.11k|	size_t pathlen = path_in->len;
  381|  2.11k|	int r = 0;
  382|  2.11k|	int objectIndex;
  383|  2.11k|	u8* oid;
  384|       |
  385|  2.11k|	r = mscfs_check_cache(fs);
  386|  2.11k|	if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    947|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    947|	int _ret = r; \
  |  |  155|    947|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 947, False: 0]
  |  |  ------------------
  |  |  156|    947|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    947|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 947, False: 0]
  |  |  ------------------
  |  |  157|    947|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    947|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    947|	return _ret; \
  |  |  163|    947|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (386:5): [True: 947, False: 1.16k]
  ------------------
  387|  1.16k|	r = mscfs_loadFileInfo(fs, path_in->value, path_in->len, &file_data, &objectIndex);
  388|  1.16k|	if(r < 0) SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
  ------------------
  |  |  153|    708|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    708|	int _ret = r; \
  |  |  155|    708|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 708, False: 0]
  |  |  ------------------
  |  |  156|    708|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    708|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 708, False: 0]
  |  |  ------------------
  |  |  157|    708|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    708|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    708|	return _ret; \
  |  |  163|    708|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (388:5): [True: 708, False: 461]
  ------------------
  389|       |
  390|       |	/* Check if its the right type */
  391|    461|	if(requiredType >= 0 && requiredType != file_data->ef) {
  ------------------
  |  Branch (391:5): [True: 3, False: 458]
  |  Branch (391:26): [True: 1, False: 2]
  ------------------
  392|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  393|      1|	}
  394|    460|	oid = file_data->objectId.id;
  395|       |	/* Is it a file or directory */
  396|    460|	if(file_data->ef) {
  ------------------
  |  Branch (396:5): [True: 225, False: 235]
  ------------------
  397|    225|		fs->currentPath[0] = oid[0];
  398|    225|		fs->currentPath[1] = oid[1];
  399|    225|		fs->currentFile[0] = oid[2];
  400|    225|		fs->currentFile[1] = oid[3];
  401|    235|	} else {
  402|    235|		if(pathlen < 2) {
  ------------------
  |  Branch (402:6): [True: 0, False: 235]
  ------------------
  403|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  404|      0|		}
  405|    235|		fs->currentPath[0] = oid[pathlen - 2];
  406|    235|		fs->currentPath[1] = oid[pathlen - 1];
  407|    235|		fs->currentFile[0] = 0;
  408|    235|		fs->currentFile[1] = 0;
  409|    235|	}
  410|       |
  411|    460|	fs->currentFileIndex = objectIndex;
  412|    460|	if(file_out) {
  ------------------
  |  Branch (412:5): [True: 234, False: 226]
  ------------------
  413|    234|		sc_file_t *file;
  414|    234|		file = sc_file_new();
  415|    234|		if (!file)
  ------------------
  |  Branch (415:7): [True: 0, False: 234]
  ------------------
  416|      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]
  |  |  ------------------
  ------------------
  417|    234|		file->path = *path_in;
  418|    234|		file->size = file_data->size;
  419|    234|		file->id = (oid[2] << 8) | oid[3];
  420|    234|		if(!file_data->ef) {
  ------------------
  |  Branch (420:6): [True: 9, False: 225]
  ------------------
  421|      9|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      9|#define SC_FILE_TYPE_DF			0x04
  ------------------
  422|    225|		} else {
  423|    225|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    225|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  424|    225|			file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    225|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  425|    225|		}
  426|       |
  427|       |		/* Setup ACLS */
  428|    234|		if(file_data->ef) {
  ------------------
  |  Branch (428:6): [True: 225, False: 9]
  ------------------
  429|    225|			muscle_load_file_acls(file, file_data);
  430|    225|		} else {
  431|      9|			muscle_load_dir_acls(file, file_data);
  432|       |			/* Setup directory acls... */
  433|      9|		}
  434|       |
  435|    234|		file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    234|#define SC_FILE_MAGIC			0x14426950
  ------------------
  436|    234|		*file_out = file;
  437|    234|	}
  438|    460|	return 0;
  439|    460|}
card-muscle.c:muscle_load_file_acls:
  360|    225|{
  361|    225|	muscle_load_single_acl(file, SC_AC_OP_READ, file_data->read);
  ------------------
  |  |  188|    225|#define SC_AC_OP_READ			22
  ------------------
  362|    225|	muscle_load_single_acl(file, SC_AC_OP_WRITE, file_data->write);
  ------------------
  |  |  190|    225|#define SC_AC_OP_WRITE			24
  ------------------
  363|    225|	muscle_load_single_acl(file, SC_AC_OP_UPDATE, file_data->write);
  ------------------
  |  |  189|    225|#define SC_AC_OP_UPDATE			23
  ------------------
  364|    225|	muscle_load_single_acl(file, SC_AC_OP_DELETE, file_data->delete);
  ------------------
  |  |  168|    225|#define SC_AC_OP_DELETE			2
  ------------------
  365|    225|}
card-muscle.c:muscle_load_single_acl:
  345|    945|{
  346|    945|	int key;
  347|       |	/* Everybody by default.... */
  348|    945|	sc_file_add_acl_entry(file, operation, SC_AC_NONE, 0);
  ------------------
  |  |  150|    945|#define SC_AC_NONE			0x00000000
  ------------------
  349|    945|	if(acl == 0xFFFF) {
  ------------------
  |  Branch (349:5): [True: 70, False: 875]
  ------------------
  350|     70|		sc_file_add_acl_entry(file, operation, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     70|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  351|     70|		return;
  352|     70|	}
  353|  14.8k|	for(key = 0; key < 16; key++) {
  ------------------
  |  Branch (353:15): [True: 14.0k, False: 875]
  ------------------
  354|  14.0k|		if(acl >> key & 1) {
  ------------------
  |  Branch (354:6): [True: 5.21k, False: 8.79k]
  ------------------
  355|  5.21k|			sc_file_add_acl_entry(file, operation, SC_AC_CHV, key);
  ------------------
  |  |  151|  5.21k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  356|  5.21k|		}
  357|  14.0k|	}
  358|    875|}
card-muscle.c:muscle_load_dir_acls:
  367|      9|{
  368|      9|	muscle_load_single_acl(file, SC_AC_OP_SELECT, 0);
  ------------------
  |  |  166|      9|#define SC_AC_OP_SELECT			0
  ------------------
  369|      9|	muscle_load_single_acl(file, SC_AC_OP_LIST_FILES, 0);
  ------------------
  |  |  172|      9|#define SC_AC_OP_LIST_FILES		6
  ------------------
  370|      9|	muscle_load_single_acl(file, SC_AC_OP_LOCK, 0xFFFF);
  ------------------
  |  |  167|      9|#define SC_AC_OP_LOCK			1
  ------------------
  371|      9|	muscle_load_single_acl(file, SC_AC_OP_DELETE, file_data->delete);
  ------------------
  |  |  168|      9|#define SC_AC_OP_DELETE			2
  ------------------
  372|      9|	muscle_load_single_acl(file, SC_AC_OP_CREATE, file_data->write);
  ------------------
  |  |  169|      9|#define SC_AC_OP_CREATE			3
  ------------------
  373|      9|}
card-muscle.c:muscle_card_reader_lock_obtained:
  864|  7.62k|{
  865|  7.62k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  7.62k|#define SC_SUCCESS				0
  ------------------
  866|       |
  867|  7.62k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.62k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.62k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.62k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.62k]
  |  |  ------------------
  ------------------
  868|       |
  869|  7.62k|	if (was_reset > 0) {
  ------------------
  |  Branch (869:6): [True: 0, False: 7.62k]
  ------------------
  870|      0|		if (msc_select_applet(card, muscleAppletId, sizeof muscleAppletId) != 1) {
  ------------------
  |  Branch (870:7): [True: 0, False: 0]
  ------------------
  871|      0|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|      0|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  872|      0|		}
  873|      0|	}
  874|       |
  875|  7.62k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  7.62k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.62k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.62k|	int _ret = r; \
  |  |  |  |  155|  7.62k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.62k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7.62k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.62k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.62k|	return _ret; \
  |  |  |  |  163|  7.62k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  876|  7.62k|}

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

sc_get_npa_driver:
  812|  16.1k|{
  813|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  814|       |
  815|  16.1k|	npa_ops = *iso_drv->ops;
  816|  16.1k|	npa_ops.match_card = npa_match_card;
  817|  16.1k|	npa_ops.init = npa_init;
  818|  16.1k|	npa_ops.finish = npa_finish;
  819|  16.1k|	npa_ops.set_security_env = npa_set_security_env;
  820|  16.1k|	npa_ops.pin_cmd = npa_pin_cmd;
  821|  16.1k|	npa_ops.logout = npa_logout;
  822|       |
  823|  16.1k|	return &npa_drv;
  824|  16.1k|}
card-npa.c:npa_match_card:
  156|  2.82k|{
  157|  2.82k|	unsigned char dir_content[sizeof dir_content_ref];
  158|  2.82k|	unsigned char id[] = {0x2F, 0x00};
  159|  2.82k|	sc_apdu_t select_ef_dir;
  160|       |
  161|  2.82k|	sc_format_apdu_ex(&select_ef_dir, 0x00, 0xA4, 0x02, 0x0C, id, sizeof id, NULL, 0);
  162|       |
  163|  2.82k|	if (SC_SUCCESS == sc_select_file(card, sc_get_mf_path(), NULL)
  ------------------
  |  |   28|  2.82k|#define SC_SUCCESS				0
  ------------------
  |  Branch (163:6): [True: 65, False: 2.75k]
  ------------------
  164|     65|			&& SC_SUCCESS == sc_transmit_apdu(card, &select_ef_dir)
  ------------------
  |  |   28|     65|#define SC_SUCCESS				0
  ------------------
  |  Branch (164:7): [True: 63, False: 2]
  ------------------
  165|     63|			&& select_ef_dir.sw1 == 0x90 && select_ef_dir.sw2 == 0x00
  ------------------
  |  Branch (165:7): [True: 45, False: 18]
  |  Branch (165:36): [True: 41, False: 4]
  ------------------
  166|     41|			&& sizeof dir_content == sc_read_binary(card, 0, dir_content, sizeof dir_content, 0)
  ------------------
  |  Branch (166:7): [True: 20, False: 21]
  ------------------
  167|     20|			&& 0 == memcmp(dir_content_ref, dir_content, sizeof dir_content))
  ------------------
  |  Branch (167:7): [True: 0, False: 20]
  ------------------
  168|      0|		return 1;
  169|       |
  170|  2.82k|	return 0;
  171|  2.82k|}

nqapplet_set_security_env:
  259|    642|{
  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|    642|	nqapplet_driver_data_ptr data;
  263|    642|	u8 key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|    642|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
  264|       |
  265|    642|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    642|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    642|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    642|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    642|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 642]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  266|       |
  267|    642|	data = (nqapplet_driver_data_ptr)card->drv_data;
  268|    642|	data->key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|    642|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
  269|       |
  270|    642|	if (se_num != 0) {
  ------------------
  |  Branch (270:6): [True: 0, False: 642]
  ------------------
  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|    642|	if (env->key_ref_len == 1) {
  ------------------
  |  Branch (274:6): [True: 642, False: 0]
  ------------------
  275|    642|		key_reference = env->key_ref[0];
  276|    642|	}
  277|       |
  278|    642|	switch (env->operation) {
  279|    473|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    473|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (279:2): [True: 473, False: 169]
  ------------------
  280|    473|		if (key_reference != KEY_REFERENCE_AUTH_KEY && key_reference != KEY_REFERENCE_ENCR_KEY) {
  ------------------
  |  |   48|    946|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
              		if (key_reference != KEY_REFERENCE_AUTH_KEY && key_reference != KEY_REFERENCE_ENCR_KEY) {
  ------------------
  |  |   49|    133|#define KEY_REFERENCE_ENCR_KEY 0x02
  ------------------
  |  Branch (280:7): [True: 133, False: 340]
  |  Branch (280:50): [True: 0, False: 133]
  ------------------
  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|    473|		data->key_reference = key_reference;
  285|    473|		break;
  286|    169|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    169|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (286:2): [True: 169, False: 473]
  ------------------
  287|    169|		if (key_reference != KEY_REFERENCE_AUTH_KEY) {
  ------------------
  |  |   48|    169|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
  |  Branch (287:7): [True: 0, False: 169]
  ------------------
  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|    169|		data->key_reference = key_reference;
  292|    169|		break;
  293|      0|	default:
  ------------------
  |  Branch (293:2): [True: 0, False: 642]
  ------------------
  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|    642|	}
  296|       |
  297|    642|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    642|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    642|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    642|	int _ret = r; \
  |  |  |  |  155|    642|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 642, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    642|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 642]
  |  |  |  |  ------------------
  |  |  |  |  157|    642|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    642|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    642|	return _ret; \
  |  |  |  |  163|    642|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|    642|}
sc_get_nqApplet_driver:
  471|  16.1k|{
  472|  16.1k|	sc_card_driver_t *iso_driver = sc_get_iso7816_driver();
  473|       |
  474|  16.1k|	if (iso_operations == NULL) {
  ------------------
  |  Branch (474:6): [True: 1, False: 16.1k]
  ------------------
  475|      1|		iso_operations = iso_driver->ops;
  476|      1|	}
  477|       |
  478|  16.1k|	nqapplet_operations = *iso_driver->ops;
  479|       |
  480|       |	/* supported operations */
  481|  16.1k|	nqapplet_operations.match_card = nqapplet_match_card;
  482|  16.1k|	nqapplet_operations.init = nqapplet_init;
  483|  16.1k|	nqapplet_operations.finish = nqapplet_finish;
  484|  16.1k|	nqapplet_operations.get_response = nqapplet_get_response;
  485|  16.1k|	nqapplet_operations.get_challenge = nqapplet_get_challenge;
  486|  16.1k|	nqapplet_operations.logout = nqapplet_logout;
  487|  16.1k|	nqapplet_operations.set_security_env = nqapplet_set_security_env;
  488|  16.1k|	nqapplet_operations.decipher = nqapplet_decipher;
  489|  16.1k|	nqapplet_operations.compute_signature = nqapplet_compute_signature;
  490|  16.1k|	nqapplet_operations.check_sw = nqapplet_check_sw;
  491|  16.1k|	nqapplet_operations.get_data = nqapplet_get_data;
  492|  16.1k|	nqapplet_operations.select_file = nqapplet_select_file;
  493|  16.1k|	nqapplet_operations.card_ctl = nqapplet_card_ctl;
  494|  16.1k|	nqapplet_operations.pin_cmd = nqapplet_pin_cmd;
  495|       |
  496|       |	/* unsupported operations */
  497|  16.1k|	nqapplet_operations.read_binary = NULL;
  498|  16.1k|	nqapplet_operations.write_binary = NULL;
  499|  16.1k|	nqapplet_operations.update_binary = NULL;
  500|  16.1k|	nqapplet_operations.erase_binary = NULL;
  501|  16.1k|	nqapplet_operations.read_record = NULL;
  502|  16.1k|	nqapplet_operations.write_record = NULL;
  503|  16.1k|	nqapplet_operations.append_record = NULL;
  504|  16.1k|	nqapplet_operations.update_record = NULL;
  505|       |
  506|  16.1k|	nqapplet_operations.verify = NULL;
  507|  16.1k|	nqapplet_operations.restore_security_env = NULL;
  508|  16.1k|	nqapplet_operations.change_reference_data = NULL;
  509|  16.1k|	nqapplet_operations.reset_retry_counter = NULL;
  510|  16.1k|	nqapplet_operations.create_file = NULL;
  511|  16.1k|	nqapplet_operations.delete_file = NULL;
  512|  16.1k|	nqapplet_operations.list_files = NULL;
  513|  16.1k|	nqapplet_operations.process_fci = NULL;
  514|  16.1k|	nqapplet_operations.construct_fci = NULL;
  515|  16.1k|	nqapplet_operations.put_data = NULL;
  516|  16.1k|	nqapplet_operations.delete_record = NULL;
  517|  16.1k|	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.1k|	return &nqapplet_driver;
  526|  16.1k|}
card-nqApplet.c:nqapplet_match_card:
  143|  2.67k|{
  144|  2.67k|	int rv = _sc_match_atr(card, nqapplet_atrs, &card->type);
  145|  2.67k|	return (rv >= 0);
  146|  2.67k|}
card-nqApplet.c:nqapplet_init:
  149|    244|{
  150|    244|	u8 version_major;
  151|    244|	u8 version_minor;
  152|    244|	u8 serial_nr[APPLET_SERIALNR_LEN];
  153|    244|	size_t cb_serial_nr = sizeof(serial_nr);
  154|    244|	unsigned long rsa_flags = 0;
  155|       |
  156|    244|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|    244|	int rv =
  158|    244|		select_nqapplet(card, &version_major, &version_minor, serial_nr, cb_serial_nr, &cb_serial_nr);
  159|    244|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    244|#define SC_SUCCESS				0
  ------------------
  |  Branch (159:6): [True: 62, False: 182]
  ------------------
  160|     62|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_CARD, "Cannot select NQ-Applet.");
  ------------------
  |  |  174|     62|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     62|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     62|	int _ret = (r); \
  |  |  |  |  168|     62|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     62|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     62|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     62|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     62|		return _ret; \
  |  |  |  |  172|     62|	} \
  |  |  |  |  173|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|     62|	}
  162|       |
  163|    182|	rv = init_driver_data(card, version_major, version_minor);
  164|    182|	LOG_TEST_RET(card->ctx, rv, "Failed to initialize driver data.");
  ------------------
  |  |  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: 0, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 182]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|       |
  166|    182|	card->max_send_size = 255;
  167|    182|	card->max_recv_size = 256;
  168|    182|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    182|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    182|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  169|    182|	rsa_flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|    182|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  170|    182|	_sc_card_add_rsa_alg(card, 3072, rsa_flags, 0);
  171|       |
  172|    182|	card->serialnr.len = MIN(sizeof(card->serialnr.value), cb_serial_nr);
  ------------------
  |  |   69|    182|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 182]
  |  |  ------------------
  ------------------
  173|    182|	memcpy(card->serialnr.value, serial_nr, card->serialnr.len);
  174|       |
  175|    182|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  176|    182|}
card-nqApplet.c:select_nqapplet:
  110|    255|{
  111|    255|	int rv;
  112|    255|	sc_context_t *ctx = card->ctx;
  113|    255|	u8 buffer[APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN + 2];
  114|    255|	size_t cb_buffer = sizeof(buffer);
  115|    255|	size_t cb_aid = sizeof(nqapplet_aid);
  116|       |
  117|    255|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    255|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    255|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    255|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    255|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  118|       |
  119|    255|	rv = iso7816_select_aid(card, nqapplet_aid, cb_aid, buffer, &cb_buffer);
  120|    255|	LOG_TEST_RET(card->ctx, rv, "Failed to select NQ-Applet.");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 57, False: 198]
  |  |  |  |  ------------------
  |  |  |  |  169|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     57|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     57|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     57|		return _ret; \
  |  |  |  |  172|     57|	} \
  |  |  |  |  173|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 198]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|    198|	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   30|    198|#define APPLET_VERSION_LEN  2
  ------------------
              	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   31|    198|#define APPLET_MEMTYPE_LEN  1
  ------------------
              	if (cb_buffer < APPLET_VERSION_LEN + APPLET_MEMTYPE_LEN + APPLET_SERIALNR_LEN) {
  ------------------
  |  |   32|    198|#define APPLET_SERIALNR_LEN 8
  ------------------
  |  Branch (122:6): [True: 15, False: 183]
  ------------------
  123|     15|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  124|     15|	}
  125|       |
  126|    183|	if (version_major != NULL) {
  ------------------
  |  Branch (126:6): [True: 182, False: 1]
  ------------------
  127|    182|		*version_major = buffer[0];
  128|    182|	}
  129|    183|	if (version_minor != NULL) {
  ------------------
  |  Branch (129:6): [True: 182, False: 1]
  ------------------
  130|    182|		*version_minor = buffer[1];
  131|    182|	}
  132|    183|	if (serial_nr != NULL && cb_serial_nr > 0 && serial_nr_len != NULL) {
  ------------------
  |  Branch (132:6): [True: 182, False: 1]
  |  Branch (132:27): [True: 182, False: 0]
  |  Branch (132:47): [True: 182, False: 0]
  ------------------
  133|    182|		size_t cb = MIN(APPLET_SERIALNR_LEN, cb_serial_nr);
  ------------------
  |  |   69|    182|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 182]
  |  |  ------------------
  ------------------
  134|    182|		memcpy(serial_nr, buffer + 3, cb);
  135|    182|		*serial_nr_len = cb;
  136|    182|	}
  137|       |
  138|    183|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    183|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    183|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    183|	int _ret = r; \
  |  |  |  |  155|    183|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 183, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    183|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 183]
  |  |  |  |  ------------------
  |  |  |  |  157|    183|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    183|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    183|	return _ret; \
  |  |  |  |  163|    183|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  139|    183|}
card-nqApplet.c:init_driver_data:
   82|    182|{
   83|    182|	nqapplet_driver_data_ptr data = calloc(1, sizeof(struct nqapplet_driver_data));
   84|    182|	if (data == NULL) {
  ------------------
  |  Branch (84:6): [True: 0, False: 182]
  ------------------
   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|    182|	data->version_major = version_major;
   89|    182|	data->version_minor = version_minor;
   90|    182|	data->key_reference = KEY_REFERENCE_NO_KEY;
  ------------------
  |  |   47|    182|#define KEY_REFERENCE_NO_KEY   0x00
  ------------------
   91|    182|	card->drv_data = (void *)data;
   92|    182|	return SC_SUCCESS;
  ------------------
  |  |   28|    182|#define SC_SUCCESS				0
  ------------------
   93|    182|}
card-nqApplet.c:nqapplet_finish:
  179|    182|{
  180|    182|	nqapplet_driver_data_ptr data = (nqapplet_driver_data_ptr)card->drv_data;
  181|       |
  182|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|    182|	if (data != NULL) {
  ------------------
  |  Branch (183:6): [True: 182, False: 0]
  ------------------
  184|    182|		free(data);
  185|    182|		card->drv_data = NULL;
  186|    182|	}
  187|    182|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|    182|}
card-nqApplet.c:nqapplet_get_response:
  192|  2.20k|{
  193|  2.20k|	struct sc_apdu apdu = {0};
  194|  2.20k|	int rv;
  195|  2.20k|	size_t resplen;
  196|       |
  197|  2.20k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.20k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.20k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.20k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.20k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  198|  2.20k|	resplen = MIN(sc_get_max_recv_size(card), *cb_resp);
  ------------------
  |  |   69|  2.20k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 2.20k]
  |  |  ------------------
  ------------------
  199|       |
  200|  2.20k|	sc_format_apdu_ex(&apdu, 0x80, 0xC0, 0x00, 0x00, NULL, 0, resp, resplen);
  201|  2.20k|	apdu.flags |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  2.20k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  202|       |
  203|  2.20k|	rv = sc_transmit_apdu(card, &apdu);
  204|  2.20k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  2.20k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.20k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.20k|	int _ret = (r); \
  |  |  |  |  168|  2.20k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 2.19k]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|  2.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|       |
  206|  2.19k|	*cb_resp = apdu.resplen;
  207|       |
  208|  2.19k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (208:6): [True: 51, False: 2.14k]
  ------------------
  209|     51|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|     38|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 38, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  210|     51|	}
  211|  2.14k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (211:6): [True: 88, False: 2.05k]
  |  Branch (211:26): [True: 28, False: 60]
  ------------------
  212|     28|		rv = SC_SUCCESS;
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  213|  2.11k|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (213:13): [True: 1.91k, False: 201]
  ------------------
  214|  1.91k|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (214:8): [True: 1.54k, False: 368]
  ------------------
  215|  1.91k|	} else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (215:13): [True: 21, False: 180]
  |  Branch (215:33): [True: 10, False: 11]
  ------------------
  216|     10|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  217|     10|	}
  218|       |
  219|  2.14k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  2.14k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.14k|	int _ret = r; \
  |  |  |  |  155|  2.14k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 229, False: 1.91k]
  |  |  |  |  ------------------
  |  |  |  |  156|    229|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 219]
  |  |  |  |  ------------------
  |  |  |  |  157|    229|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.91k|	} else { \
  |  |  |  |  159|  1.91k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.91k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.91k|	} \
  |  |  |  |  162|  2.14k|	return _ret; \
  |  |  |  |  163|  2.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|  2.14k|}
card-nqApplet.c:nqapplet_decipher:
  301|    411|{
  302|    411|	int rv;
  303|    411|	struct sc_apdu apdu;
  304|    411|	u8 p1 = 0x80;
  305|    411|	u8 p2 = 0x86;
  306|    411|	nqapplet_driver_data_ptr drv_data;
  307|       |
  308|    411|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    411|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    411|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    411|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    411|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 411]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|       |
  310|    411|	drv_data = (nqapplet_driver_data_ptr)card->drv_data;
  311|       |
  312|    411|	if (drv_data->key_reference == KEY_REFERENCE_AUTH_KEY) {
  ------------------
  |  |   48|    411|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
  |  Branch (312:6): [True: 292, False: 119]
  ------------------
  313|    292|		p1 = 0x9E;
  314|    292|		p2 = 0x9A;
  315|    292|	} else if (drv_data->key_reference != KEY_REFERENCE_ENCR_KEY) {
  ------------------
  |  |   49|    119|#define KEY_REFERENCE_ENCR_KEY 0x02
  ------------------
  |  Branch (315:13): [True: 0, False: 119]
  ------------------
  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|    411|	sc_format_apdu_ex(&apdu, 0x80, 0x2A, p1, p2, data, cb_data, out, outlen);
  323|    411|	apdu.le = 256;
  324|    411|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    411|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  325|    411|	rv = sc_transmit_apdu(card, &apdu);
  326|    411|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    411|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    411|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    411|	int _ret = (r); \
  |  |  |  |  168|    411|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 109, False: 302]
  |  |  |  |  ------------------
  |  |  |  |  169|    109|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    109|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    109|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    109|		return _ret; \
  |  |  |  |  172|    109|	} \
  |  |  |  |  173|    411|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 302]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|       |
  328|    302|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (328:6): [True: 94, False: 208]
  |  Branch (328:26): [True: 72, False: 22]
  ------------------
  329|     72|		rv = (int)apdu.resplen;
  330|    230|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (330:13): [True: 0, False: 230]
  ------------------
  331|      0|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (331:8): [True: 0, False: 0]
  ------------------
  332|    230|	} else {
  333|    230|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  334|    230|	}
  335|       |
  336|    302|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    302|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    302|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    302|	int _ret = r; \
  |  |  |  |  155|    302|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    230|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 230, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|     64|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     64|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     64|	} \
  |  |  |  |  162|    302|	return _ret; \
  |  |  |  |  163|    302|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|    302|}
card-nqApplet.c:nqapplet_compute_signature:
  341|    169|{
  342|    169|	int rv;
  343|    169|	struct sc_apdu apdu;
  344|    169|	nqapplet_driver_data_ptr drv_data;
  345|       |
  346|    169|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    169|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    169|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    169|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    169|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 169]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|    169|	drv_data = (nqapplet_driver_data_ptr)card->drv_data;
  348|       |
  349|    169|	if (drv_data->key_reference != KEY_REFERENCE_AUTH_KEY) {
  ------------------
  |  |   48|    169|#define KEY_REFERENCE_AUTH_KEY 0x01
  ------------------
  |  Branch (349:6): [True: 0, False: 169]
  ------------------
  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|    169|	sc_format_apdu_ex(&apdu, 0x80, 0x2A, 0x9E, 0x9A, data, cb_data, out, outlen);
  357|    169|	apdu.le = 256;
  358|    169|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    169|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
  359|    169|	rv = sc_transmit_apdu(card, &apdu);
  360|    169|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    169|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    169|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    169|	int _ret = (r); \
  |  |  |  |  168|    169|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 143, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|    169|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  361|       |
  362|     26|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (362:6): [True: 21, False: 5]
  |  Branch (362:26): [True: 19, False: 2]
  ------------------
  363|     19|		rv = (int)apdu.resplen;
  364|     19|	} 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|     26|	LOG_FUNC_RETURN(card->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: 8, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  156|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      8|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     18|	} else { \
  |  |  |  |  159|     18|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     18|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     18|	} \
  |  |  |  |  162|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  371|     26|}
card-nqApplet.c:nqapplet_check_sw:
  374|  1.32k|{
  375|  1.32k|	const int nqapplet_error_count = sizeof(nqapplet_errors) / sizeof(struct sc_card_error);
  376|  1.32k|	int i;
  377|       |
  378|  1.32k|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|  1.32k|	sc_log(card->ctx, "Checking sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  380|       |
  381|  13.7k|	for (i = 0; i < nqapplet_error_count; i++) {
  ------------------
  |  Branch (381:14): [True: 12.9k, False: 757]
  ------------------
  382|  12.9k|		if (nqapplet_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (382:7): [True: 572, False: 12.4k]
  ------------------
  383|    572|			LOG_TEST_RET(card->ctx, nqapplet_errors[i].errorno, nqapplet_errors[i].errorstr);
  ------------------
  |  |  174|    572|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    572|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    572|	int _ret = (r); \
  |  |  |  |  168|    572|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 572, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    572|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    572|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    572|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    572|		return _ret; \
  |  |  |  |  172|    572|	} \
  |  |  |  |  173|    572|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|    572|		}
  385|  12.9k|	}
  386|       |
  387|    757|	return iso_operations->check_sw(card, sw1, sw2);
  388|  1.32k|}
card-nqApplet.c:nqapplet_get_data:
  391|    347|{
  392|    347|	struct sc_apdu apdu;
  393|    347|	int rv;
  394|       |
  395|    347|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    347|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    347|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    347|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    347|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 347]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|       |
  397|    347|	sc_format_apdu_ex(&apdu, 0x80, 0xB0, 0x00, (u8)id, NULL, 0, resp, cb_resp);
  398|    347|	apdu.le = 256;
  399|       |
  400|    347|	rv = sc_transmit_apdu(card, &apdu);
  401|    347|	LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 19, False: 328]
  |  |  |  |  ------------------
  |  |  |  |  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|    347|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 328]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|       |
  403|    328|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (403:6): [True: 237, False: 91]
  |  Branch (403:26): [True: 236, False: 1]
  ------------------
  404|    236|		rv = (int)apdu.resplen;
  405|    236|	} else if (apdu.sw1 == 0x61) {
  ------------------
  |  Branch (405:13): [True: 0, False: 92]
  ------------------
  406|      0|		rv = apdu.sw2 == 0 ? 256 : apdu.sw2;
  ------------------
  |  Branch (406:8): [True: 0, False: 0]
  ------------------
  407|     92|	} else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82) {
  ------------------
  |  Branch (407:13): [True: 11, False: 81]
  |  Branch (407:33): [True: 1, False: 10]
  ------------------
  408|      1|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  409|      1|	}
  410|       |
  411|    328|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    328|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    328|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    328|	int _ret = r; \
  |  |  |  |  155|    328|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 99, False: 229]
  |  |  |  |  ------------------
  |  |  |  |  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|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 98]
  |  |  |  |  ------------------
  |  |  |  |  157|     99|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    229|	} else { \
  |  |  |  |  159|    229|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    229|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    229|	} \
  |  |  |  |  162|    328|	return _ret; \
  |  |  |  |  163|    328|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|    328|}
card-nqApplet.c:nqapplet_select_file:
  416|    415|{
  417|    415|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    415|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|    415|	if (in_path->type == SC_PATH_TYPE_PATH && in_path->len == 2 &&
  ------------------
  |  |  119|    830|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (421:6): [True: 51, False: 364]
  |  Branch (421:44): [True: 0, False: 51]
  ------------------
  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|    415|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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|    415|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 415, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  436|    415|}
card-nqApplet.c:nqapplet_pin_cmd:
  455|    240|{
  456|    240|	int r;
  457|       |
  458|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  459|    240|	r = iso_operations->pin_cmd(card, data);
  460|    240|	if (r == SC_ERROR_OBJECT_NOT_FOUND) {
  ------------------
  |  |   88|    240|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (460:6): [True: 11, False: 229]
  ------------------
  461|       |		/* it is possible that the NQ-Applet is not active, try to activate it */
  462|     11|		r = select_nqapplet(card, NULL, NULL, NULL, 0, NULL);
  463|     11|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
  |  Branch (463:7): [True: 1, False: 10]
  ------------------
  464|      1|			r = iso_operations->pin_cmd(card, data);
  465|      1|		}
  466|     11|	}
  467|    240|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    240|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    240|	int _ret = r; \
  |  |  155|    240|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 240, False: 0]
  |  |  ------------------
  |  |  156|    240|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    155|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 155, False: 85]
  |  |  ------------------
  |  |  157|    240|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    240|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    240|	return _ret; \
  |  |  163|    240|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  468|    240|}

sc_get_oberthur_driver:
 2332|  16.1k|{
 2333|  16.1k|	return sc_get_driver();
 2334|  16.1k|}
card-oberthur.c:sc_get_driver:
 2301|  16.1k|{
 2302|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2302:6): [True: 1, False: 16.1k]
  ------------------
 2303|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2304|       |
 2305|  16.1k|	auth_ops = *iso_ops;
 2306|  16.1k|	auth_ops.match_card = auth_match_card;
 2307|  16.1k|	auth_ops.init = auth_init;
 2308|  16.1k|	auth_ops.finish = auth_finish;
 2309|  16.1k|	auth_ops.select_file = auth_select_file;
 2310|  16.1k|	auth_ops.list_files = auth_list_files;
 2311|  16.1k|	auth_ops.delete_file = auth_delete_file;
 2312|  16.1k|	auth_ops.create_file = auth_create_file;
 2313|  16.1k|	auth_ops.read_binary = auth_read_binary;
 2314|  16.1k|	auth_ops.update_binary = auth_update_binary;
 2315|  16.1k|	auth_ops.read_record = auth_read_record;
 2316|  16.1k|	auth_ops.delete_record = auth_delete_record;
 2317|  16.1k|	auth_ops.card_ctl = auth_card_ctl;
 2318|  16.1k|	auth_ops.set_security_env = auth_set_security_env;
 2319|  16.1k|	auth_ops.restore_security_env = auth_restore_security_env;
 2320|  16.1k|	auth_ops.compute_signature = auth_compute_signature;
 2321|  16.1k|	auth_ops.decipher = auth_decipher;
 2322|  16.1k|	auth_ops.process_fci = auth_process_fci;
 2323|  16.1k|	auth_ops.pin_cmd = auth_pin_cmd;
 2324|  16.1k|	auth_ops.logout = auth_logout;
 2325|  16.1k|	auth_ops.check_sw = auth_check_sw;
 2326|  16.1k|	return &auth_drv;
 2327|  16.1k|}
card-oberthur.c:auth_match_card:
  204|  11.8k|{
  205|  11.8k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 10.9k, False: 903]
  ------------------
  206|  10.9k|		return 0;
  207|    903|	else
  208|    903|		return 1;
  209|  11.8k|}
card-oberthur.c:auth_init:
  214|    903|{
  215|    903|	struct auth_private_data *data;
  216|    903|	struct sc_path path;
  217|    903|	unsigned long flags;
  218|    903|	int rv = 0;
  219|       |
  220|    903|	data = calloc(1, sizeof(struct auth_private_data));
  221|    903|	if (!data)
  ------------------
  |  Branch (221:6): [True: 0, False: 903]
  ------------------
  222|    903|		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|    903|	card->cla = 0x00;
  225|    903|	card->drv_data = data;
  226|       |
  227|    903|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|    903|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  228|    903|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  557|    903|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  229|       |
  230|    903|	if (auth_select_aid(card)) {
  ------------------
  |  Branch (230:6): [True: 62, False: 841]
  ------------------
  231|     62|		sc_log(card->ctx, "Failed to initialize %s", card->name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     62|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     62|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  233|     62|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Failed to initialize");
  ------------------
  |  |  184|     62|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     62|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     62|	int _ret = (r); \
  |  |  |  |  178|     62|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 62, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     62|	}
  235|       |
  236|    841|	sc_format_path("3F00", &path);
  237|    841|	rv = auth_select_file(card, &path, NULL);
  238|       |
  239|    903|err:
  240|    903|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    903|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:6): [True: 841, False: 62]
  ------------------
  241|    841|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  111|    841|#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|    841|#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|    841|#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|    841|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  242|    841|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|    841|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    841|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    841|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|       |
  245|    841|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  246|    841|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  247|    841|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  248|    841|	} else {
  249|     62|		free(card->drv_data);
  250|     62|		card->drv_data = NULL;
  251|     62|	}
  252|       |
  253|    903|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    903|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    903|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    903|	int _ret = r; \
  |  |  |  |  155|    903|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 903, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    903|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 841]
  |  |  |  |  ------------------
  |  |  |  |  157|    903|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    903|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    903|	return _ret; \
  |  |  |  |  163|    903|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|    903|}
card-oberthur.c:auth_select_aid:
  145|    903|{
  146|    903|	struct sc_apdu apdu;
  147|    903|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  148|    903|	struct auth_private_data *data = (struct auth_private_data *)card->drv_data;
  149|    903|	int rv, ii;
  150|    903|	struct sc_path tmp_path;
  151|       |
  152|       |	/* Select Card Manager (to deselect previously selected application) */
  153|    903|	rv = gp_select_card_manager(card);
  154|    903|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    903|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    903|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    903|	int _ret = (r); \
  |  |  |  |  168|    903|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 863]
  |  |  |  |  ------------------
  |  |  |  |  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|    903|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 863]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Get smart card serial number */
  157|    863|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  292|    863|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  158|    863|	apdu.cla = 0x80;
  159|    863|	apdu.le = 0x2D;
  160|    863|	apdu.resplen = 0x30;
  161|    863|	apdu.resp = apdu_resp;
  162|       |
  163|    863|	rv = sc_transmit_apdu(card, &apdu);
  164|    863|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    863|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    863|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    863|	int _ret = (r); \
  |  |  |  |  168|    863|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 859]
  |  |  |  |  ------------------
  |  |  |  |  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|    863|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 859]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|    859|	if (apdu.resplen < 20) {
  ------------------
  |  Branch (165:6): [True: 7, False: 852]
  ------------------
  166|      7|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      7|	}
  168|    852|	card->serialnr.len = 4;
  169|    852|	memcpy(card->serialnr.value, apdu.resp+15, 4);
  170|       |
  171|  4.26k|	for (ii=0, data->sn = 0; ii < 4; ii++)
  ------------------
  |  Branch (171:27): [True: 3.40k, False: 852]
  ------------------
  172|  3.40k|		data->sn += (long int)(*(apdu.resp + 15 + ii)) << (3-ii)*8;
  173|       |
  174|    852|	sc_log(card->ctx, "serial number %li/0x%lX", data->sn, data->sn);
  ------------------
  |  |   71|    852|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  175|       |
  176|    852|	memset(&tmp_path, 0, sizeof(struct sc_path));
  177|    852|	tmp_path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    852|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  178|    852|	memcpy(tmp_path.value, aidAuthentIC_V5, lenAidAuthentIC_V5);
  179|    852|	tmp_path.len = lenAidAuthentIC_V5;
  180|       |
  181|    852|	rv = iso_ops->select_file(card, &tmp_path, NULL);
  182|    852|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    852|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    852|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    852|	int _ret = (r); \
  |  |  |  |  168|    852|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 848]
  |  |  |  |  ------------------
  |  |  |  |  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|    852|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 848]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    848|	sc_format_path("3F00", &tmp_path);
  185|    848|	sc_file_free(auth_current_df);
  186|    848|	auth_current_df = NULL;
  187|    848|	rv = iso_ops->select_file(card, &tmp_path, &auth_current_df);
  188|    848|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    848|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    848|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    848|	int _ret = (r); \
  |  |  |  |  168|    848|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 841]
  |  |  |  |  ------------------
  |  |  |  |  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|    848|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 841]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|       |
  190|    841|	sc_file_free(auth_current_ef);
  191|    841|	auth_current_ef = NULL;
  192|    841|	sc_file_dup(&auth_current_ef, auth_current_df);
  193|       |
  194|    841|	memcpy(data->aid, aidAuthentIC_V5, lenAidAuthentIC_V5);
  195|    841|	data->aid_len = lenAidAuthentIC_V5;
  196|    841|	card->name = nameAidAuthentIC_V5;
  197|       |
  198|    841|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    841|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    841|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    841|	int _ret = r; \
  |  |  |  |  155|    841|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 841, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    841|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 841]
  |  |  |  |  ------------------
  |  |  |  |  157|    841|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    841|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    841|	return _ret; \
  |  |  |  |  163|    841|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|    841|}
card-oberthur.c:auth_finish:
  137|    841|{
  138|    841|	free(card->drv_data);
  139|    841|	return SC_SUCCESS;
  ------------------
  |  |   28|    841|#define SC_SUCCESS				0
  ------------------
  140|    841|}
card-oberthur.c:auth_select_file:
  443|  17.7k|{
  444|  17.7k|	struct sc_path path;
  445|  17.7k|	struct sc_file *tmp_file = NULL;
  446|  17.7k|	size_t offs, ii;
  447|  17.7k|	int rv;
  448|       |
  449|  17.7k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (449:6): [True: 0, False: 17.7k]
  |  Branch (449:22): [True: 0, False: 17.7k]
  ------------------
  450|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  451|       |
  452|  17.7k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  17.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  17.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  17.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  17.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 17.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  453|       |
  454|  17.7k|	memcpy(&path, in_path, sizeof(struct sc_path));
  455|       |
  456|  17.7k|	if (!auth_current_df)
  ------------------
  |  Branch (456:6): [True: 0, False: 17.7k]
  ------------------
  457|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  458|       |
  459|  17.7k|	sc_log(card->ctx, "in_path; type=%d, path=%s, out %p",
  ------------------
  |  |   71|  17.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  460|  17.7k|			in_path->type, sc_print_path(in_path), file_out);
  461|  17.7k|	sc_log(card->ctx, "current path; type=%d, path=%s",
  ------------------
  |  |   71|  17.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  462|  17.7k|			auth_current_df->path.type, sc_print_path(&auth_current_df->path));
  463|  17.7k|	if (auth_current_ef)
  ------------------
  |  Branch (463:6): [True: 11.0k, False: 6.76k]
  ------------------
  464|  11.0k|		sc_log(card->ctx, "current file; type=%d, path=%s",
  ------------------
  |  |   71|  11.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  465|  17.7k|				auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
  466|       |
  467|  17.7k|	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  123|  35.5k|#define SC_PATH_TYPE_PARENT		5
  ------------------
              	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  17.6k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (467:6): [True: 143, False: 17.6k]
  |  Branch (467:42): [True: 8.89k, False: 8.75k]
  ------------------
  468|  9.03k|		sc_file_free(auth_current_ef);
  469|  9.03k|		auth_current_ef = NULL;
  470|       |
  471|  9.03k|		rv = iso_ops->select_file(card, &path, &tmp_file);
  472|  9.03k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  9.03k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.03k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.03k|	int _ret = (r); \
  |  |  |  |  168|  9.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.97k, False: 6.06k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.97k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.97k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.97k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.97k|		return _ret; \
  |  |  |  |  172|  2.97k|	} \
  |  |  |  |  173|  9.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.06k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  473|  6.06k|		if (!tmp_file)
  ------------------
  |  Branch (473:7): [True: 0, False: 6.06k]
  ------------------
  474|      0|			return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  475|       |
  476|  6.06k|		if (path.type == SC_PATH_TYPE_PARENT) {
  ------------------
  |  |  123|  6.06k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (476:7): [True: 62, False: 6.00k]
  ------------------
  477|     62|			memcpy(&tmp_file->path, &auth_current_df->path, sizeof(struct sc_path));
  478|     62|			if (tmp_file->path.len > 2)
  ------------------
  |  Branch (478:8): [True: 62, False: 0]
  ------------------
  479|     62|				tmp_file->path.len -= 2;
  480|       |
  481|     62|			sc_file_free(auth_current_df);
  482|     62|			auth_current_df = NULL;
  483|     62|			sc_file_dup(&auth_current_df, tmp_file);
  484|  6.00k|		} else {
  485|  6.00k|			if (tmp_file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  6.00k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (485:8): [True: 248, False: 5.75k]
  ------------------
  486|    248|				sc_concatenate_path(&tmp_file->path, &auth_current_df->path, &path);
  487|       |
  488|    248|				sc_file_free(auth_current_df);
  489|    248|				auth_current_df = NULL;
  490|    248|				sc_file_dup(&auth_current_df, tmp_file);
  491|  5.75k|			} else {
  492|  5.75k|				sc_file_free(auth_current_ef);
  493|  5.75k|				auth_current_ef = NULL;
  494|       |
  495|  5.75k|				sc_file_dup(&auth_current_ef, tmp_file);
  496|  5.75k|				sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path);
  497|  5.75k|			}
  498|  6.00k|		}
  499|  6.06k|		if (file_out) {
  ------------------
  |  Branch (499:7): [True: 4.83k, False: 1.23k]
  ------------------
  500|  4.83k|			sc_file_free(*file_out);
  501|  4.83k|			sc_file_dup(file_out, tmp_file);
  502|  4.83k|		}
  503|       |
  504|  6.06k|		sc_file_free(tmp_file);
  505|  8.75k|	} else if (path.type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  8.75k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (505:13): [True: 1.32k, False: 7.42k]
  ------------------
  506|  1.32k|		rv = iso_ops->select_file(card, &path, NULL);
  507|  1.32k|		if (rv) {
  ------------------
  |  Branch (507:7): [True: 1.26k, False: 59]
  ------------------
  508|  1.26k|			sc_file_free(auth_current_ef);
  509|  1.26k|			auth_current_ef = NULL;
  510|  1.26k|		}
  511|  1.32k|		LOG_TEST_RET(card->ctx, rv, "select file 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: 1.26k, False: 59]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.26k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.26k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.26k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.26k|		return _ret; \
  |  |  |  |  172|  1.26k|	} \
  |  |  |  |  173|  1.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 59]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  512|  7.42k|	} else {
  513|  16.0k|		for (offs = 0; offs < path.len && offs < auth_current_df->path.len; offs += 2)
  ------------------
  |  Branch (513:18): [True: 14.8k, False: 1.24k]
  |  Branch (513:37): [True: 8.83k, False: 5.99k]
  ------------------
  514|  8.83k|			if (path.value[offs] != auth_current_df->path.value[offs] ||
  ------------------
  |  Branch (514:8): [True: 148, False: 8.69k]
  ------------------
  515|  8.69k|					path.value[offs + 1] != auth_current_df->path.value[offs + 1])
  ------------------
  |  Branch (515:6): [True: 39, False: 8.65k]
  ------------------
  516|    187|				break;
  517|       |
  518|  7.42k|		sc_log(card->ctx, "offs %zu", offs);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
  519|  7.42k|		if (offs && offs < auth_current_df->path.len) {
  ------------------
  |  Branch (519:7): [True: 7.36k, False: 56]
  |  Branch (519:15): [True: 131, False: 7.23k]
  ------------------
  520|    131|			size_t deep = auth_current_df->path.len - offs;
  521|       |
  522|    131|			sc_log(card->ctx, "deep %zu", deep);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  523|    193|			for (ii = 0; ii < deep; ii += 2) {
  ------------------
  |  Branch (523:17): [True: 143, False: 50]
  ------------------
  524|    143|				struct sc_path tmp_path;
  525|       |
  526|    143|				memcpy(&tmp_path, &auth_current_df->path,  sizeof(struct sc_path));
  527|    143|				tmp_path.type = SC_PATH_TYPE_PARENT;
  ------------------
  |  |  123|    143|#define SC_PATH_TYPE_PARENT		5
  ------------------
  528|       |
  529|    143|				if (file_out) {
  ------------------
  |  Branch (529:9): [True: 17, False: 126]
  ------------------
  530|     17|					sc_file_free(*file_out);
  531|     17|					*file_out = NULL;
  532|     17|				}
  533|       |
  534|    143|				rv = auth_select_file (card, &tmp_path, file_out);
  535|    143|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|    143|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    143|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    143|	int _ret = (r); \
  |  |  |  |  168|    143|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  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|    143|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 62]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|    143|			}
  537|    131|		}
  538|       |
  539|  7.34k|		if (path.len > offs) {
  ------------------
  |  Branch (539:7): [True: 6.09k, False: 1.24k]
  ------------------
  540|  6.09k|			struct sc_path tmp_path;
  541|       |
  542|  6.09k|			memset(&tmp_path, 0, sizeof(struct sc_path));
  543|  6.09k|			tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  6.09k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  544|  6.09k|			tmp_path.len = 2;
  545|       |
  546|  12.0k|			for (ii = 0; ii < path.len - offs; ii += 2) {
  ------------------
  |  Branch (546:17): [True: 8.89k, False: 3.20k]
  ------------------
  547|  8.89k|				memcpy(tmp_path.value, path.value + offs + ii, 2);
  548|       |
  549|  8.89k|				if (file_out) {
  ------------------
  |  Branch (549:9): [True: 6.31k, False: 2.57k]
  ------------------
  550|  6.31k|					sc_file_free(*file_out);
  551|  6.31k|					*file_out = NULL;
  552|  6.31k|				}
  553|       |
  554|  8.89k|				rv = auth_select_file(card, &tmp_path, file_out);
  555|  8.89k|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  8.89k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.89k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.89k|	int _ret = (r); \
  |  |  |  |  168|  8.89k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.89k, False: 6.00k]
  |  |  |  |  ------------------
  |  |  |  |  169|  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
  |  |  |  |  ------------------
  |  |  |  |  170|  2.89k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.89k|		return _ret; \
  |  |  |  |  172|  2.89k|	} \
  |  |  |  |  173|  8.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  8.89k|			}
  557|  6.09k|		} else if (path.len - offs == 0 && file_out) {
  ------------------
  |  Branch (557:14): [True: 1.24k, False: 0]
  |  Branch (557:38): [True: 0, False: 1.24k]
  ------------------
  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.34k|	}
  569|       |
  570|  10.5k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10.5k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|  10.5k|}
card-oberthur.c:auth_read_binary:
 2115|  2.16k|{
 2116|  2.16k|	int rv;
 2117|  2.16k|	size_t sz;
 2118|  2.16k|	struct sc_pkcs15_bignum bn[2];
 2119|  2.16k|	unsigned char *out = NULL;
 2120|  2.16k|	bn[0].data = NULL;
 2121|  2.16k|	bn[1].data = NULL;
 2122|       |
 2123|  2.16k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.16k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.16k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.16k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.16k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.16k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2124|       |
 2125|  2.16k|	if (!auth_current_ef)
  ------------------
  |  Branch (2125:6): [True: 21, False: 2.14k]
  ------------------
 2126|  2.16k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2127|       |
 2128|  2.14k|	sc_log(card->ctx, "offset %i; size %zu; flags 0x%lX", offset, count, flags ? *flags : 0);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 2.14k]
  |  |  ------------------
  ------------------
 2129|  2.14k|	sc_log(card->ctx, "last selected : magic %X; ef %X",
  ------------------
  |  |   71|  2.14k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2130|  2.14k|			auth_current_ef->magic, auth_current_ef->ef_structure);
 2131|       |
 2132|  2.14k|	if (offset & ~0x7FFF)
  ------------------
  |  Branch (2132:6): [True: 0, False: 2.14k]
  ------------------
 2133|  2.14k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2134|       |
 2135|  2.14k|	if (auth_current_ef->magic == SC_FILE_MAGIC &&
  ------------------
  |  |   56|  4.28k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  |  Branch (2135:6): [True: 2.14k, False: 0]
  ------------------
 2136|  2.14k|			auth_current_ef->ef_structure == SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC) {
  ------------------
  |  Branch (2136:4): [True: 122, False: 2.02k]
  ------------------
 2137|    122|		int jj;
 2138|    122|		unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 2139|    122|		size_t resp_len, out_len;
 2140|    122|		struct sc_pkcs15_pubkey_rsa key;
 2141|       |
 2142|    122|		resp_len = sizeof(resp);
 2143|    122|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2144|    122|				2, resp, resp_len);
 2145|    122|		LOG_TEST_RET(card->ctx, rv, "read component failed");
  ------------------
  |  |  174|    122|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    122|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    122|	int _ret = (r); \
  |  |  |  |  168|    122|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  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|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 93]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2146|       |
 2147|    418|		for (jj=0; jj<rv && *(resp+jj)==0; jj++)
  ------------------
  |  Branch (2147:14): [True: 410, False: 8]
  |  Branch (2147:23): [True: 325, False: 85]
  ------------------
 2148|    325|			;
 2149|       |
 2150|     93|		if (rv - jj == 0)
  ------------------
  |  Branch (2150:7): [True: 8, False: 85]
  ------------------
 2151|      8|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      8|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2152|     85|		bn[0].data = calloc(1, rv - jj);
 2153|     85|		if (!bn[0].data) {
  ------------------
  |  Branch (2153:7): [True: 0, False: 85]
  ------------------
 2154|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2155|      0|			goto err;
 2156|      0|		}
 2157|     85|		bn[0].len = rv - jj;
 2158|     85|		memcpy(bn[0].data, resp + jj, rv - jj);
 2159|       |
 2160|     85|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2161|     85|				1, resp, resp_len);
 2162|     85|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Cannot read RSA public key component");
  ------------------
  |  |  184|     85|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     85|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     85|	int _ret = (r); \
  |  |  |  |  178|     85|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 13, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  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|     85|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2163|       |
 2164|     72|		bn[1].data = calloc(1, rv);
 2165|     72|		if (!bn[1].data) {
  ------------------
  |  Branch (2165:7): [True: 0, False: 72]
  ------------------
 2166|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2167|      0|			goto err;
 2168|      0|		}
 2169|     72|		bn[1].len = rv;
 2170|     72|		memcpy(bn[1].data, resp, rv);
 2171|       |
 2172|     72|		key.exponent = bn[0];
 2173|     72|		key.modulus = bn[1];
 2174|       |
 2175|     72|		if (sc_pkcs15_encode_pubkey_rsa(card->ctx, &key, &out, &out_len) != SC_SUCCESS) {
  ------------------
  |  |   28|     72|#define SC_SUCCESS				0
  ------------------
  |  Branch (2175:7): [True: 5, False: 67]
  ------------------
 2176|      5|			rv = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      5|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2177|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2178|      5|		}
 2179|     67|		else {
 2180|     67|			if (out_len < offset) {
  ------------------
  |  Branch (2180:8): [True: 6, False: 61]
  ------------------
 2181|      6|				rv = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      6|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2182|      6|				goto err;
 2183|      6|			}
 2184|     61|			sz = MIN(out_len - offset, count);
  ------------------
  |  |   69|     61|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 41, False: 20]
  |  |  ------------------
  ------------------
 2185|     61|			memcpy(buf, out + offset, sz);
 2186|       |
 2187|     61|			sc_log_hex(card->ctx, "write_publickey", buf, sz);
  ------------------
  |  |  129|     61|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     61|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2188|     61|			rv = (int)sz;
 2189|     61|		}
 2190|  2.02k|	} else {
 2191|  2.02k|		rv = iso_ops->read_binary(card, offset, buf, count, 0);
 2192|  2.02k|	}
 2193|       |
 2194|  2.10k|err:
 2195|  2.10k|	free(bn[0].data);
 2196|  2.10k|	free(bn[1].data);
 2197|  2.10k|	free(out);
 2198|       |
 2199|  2.10k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  2.10k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.10k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.10k|	int _ret = r; \
  |  |  |  |  155|  2.10k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 161, False: 1.94k]
  |  |  |  |  ------------------
  |  |  |  |  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|    129|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 129, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  157|    161|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.94k|	} else { \
  |  |  |  |  159|  1.94k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.94k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.94k|	} \
  |  |  |  |  162|  2.10k|	return _ret; \
  |  |  |  |  163|  2.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2200|  2.10k|}
card-oberthur.c:auth_read_component:
 1476|    207|{
 1477|    207|	struct sc_apdu apdu;
 1478|    207|	int rv;
 1479|    207|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 1480|       |
 1481|    207|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    207|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    207|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    207|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    207|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1482|    207|	sc_log(card->ctx, "num %i, outlen %zu, type %i", num, outlen, type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1483|       |
 1484|    207|	if (!outlen || type!=SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC)
  ------------------
  |  Branch (1484:6): [True: 0, False: 207]
  |  Branch (1484:17): [True: 0, False: 207]
  ------------------
 1485|    207|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1486|       |
 1487|    207|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB4,	num, 0x00);
  ------------------
  |  |  292|    207|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1488|    207|	apdu.cla |= 0x80;
 1489|    207|	apdu.le = outlen;
 1490|    207|	apdu.resp = resp;
 1491|    207|	apdu.resplen = sizeof(resp);
 1492|    207|	rv = sc_transmit_apdu(card, &apdu);
 1493|    207|	LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 4, False: 203]
  |  |  |  |  ------------------
  |  |  |  |  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|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 203]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1494|       |
 1495|    203|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1496|    203|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  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: 38, False: 165]
  |  |  |  |  ------------------
  |  |  |  |  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|    203|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 165]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1497|       |
 1498|    165|	if (outlen < apdu.resplen)
  ------------------
  |  Branch (1498:6): [True: 0, False: 165]
  ------------------
 1499|    165|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1500|       |
 1501|    165|	memcpy(out, apdu.resp, apdu.resplen);
 1502|    165|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    165|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    165|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    165|	int _ret = r; \
  |  |  |  |  155|    165|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 155]
  |  |  |  |  ------------------
  |  |  |  |  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|    155|	} else { \
  |  |  |  |  159|    155|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    155|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    155|	} \
  |  |  |  |  162|    165|	return _ret; \
  |  |  |  |  163|    165|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1503|    165|}
card-oberthur.c:auth_read_record:
 2206|  4.46k|{
 2207|  4.46k|	struct sc_apdu apdu;
 2208|  4.46k|	int rv = 0;
 2209|  4.46k|	unsigned char recvbuf[SC_MAX_APDU_BUFFER_SIZE];
 2210|       |
 2211|  4.46k|	sc_log(card->ctx, "auth_read_record(): nr_rec %i; count %zu", nr_rec, count);
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 2212|       |
 2213|  4.46k|	if (nr_rec > 0xFF || idx != 0)
  ------------------
  |  Branch (2213:6): [True: 0, False: 4.46k]
  |  Branch (2213:23): [True: 962, False: 3.49k]
  ------------------
 2214|  4.46k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    962|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    962|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    962|	int _ret = r; \
  |  |  |  |  155|    962|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 962, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    962|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    962|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 962, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    962|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    962|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    962|	return _ret; \
  |  |  |  |  163|    962|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2215|       |
 2216|  3.49k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB2, nr_rec, 0);
  ------------------
  |  |  292|  3.49k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 2217|  3.49k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  3.49k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
 2218|  3.49k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  3.49k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (2218:6): [True: 3.49k, False: 0]
  ------------------
 2219|  3.49k|		apdu.p2 |= 0x04;
 2220|       |
 2221|  3.49k|	apdu.le = MIN(count, SC_MAX_APDU_BUFFER_SIZE);
  ------------------
  |  |   69|  3.49k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 3.49k, False: 0]
  |  |  ------------------
  ------------------
 2222|  3.49k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  3.49k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 2223|  3.49k|	apdu.resp = recvbuf;
 2224|       |
 2225|  3.49k|	rv = sc_transmit_apdu(card, &apdu);
 2226|  3.49k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  3.49k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.49k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.49k|	int _ret = (r); \
  |  |  |  |  168|  3.49k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 3.49k]
  |  |  |  |  ------------------
  |  |  |  |  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|  3.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.49k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2227|  3.49k|	if (apdu.resplen == 0)
  ------------------
  |  Branch (2227:6): [True: 1.36k, False: 2.12k]
  ------------------
 2228|  3.49k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  1.36k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.36k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.36k|	int _ret = r; \
  |  |  |  |  155|  1.36k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.36k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.36k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 41, False: 1.32k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.36k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.36k|	return _ret; \
  |  |  |  |  163|  1.36k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2229|  2.12k|	if (count < apdu.resplen)
  ------------------
  |  Branch (2229:6): [True: 4, False: 2.12k]
  ------------------
 2230|  2.12k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2231|  2.12k|	memcpy(buf, recvbuf, apdu.resplen);
 2232|       |
 2233|  2.12k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2234|  2.12k|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  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: 16, False: 2.10k]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.10k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2235|       |
 2236|  2.10k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.10k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.10k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.10k|	int _ret = r; \
  |  |  |  |  155|  2.10k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 2.10k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.10k|	} else { \
  |  |  |  |  159|  2.10k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.10k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.10k|	} \
  |  |  |  |  162|  2.10k|	return _ret; \
  |  |  |  |  163|  2.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2237|  2.10k|}
card-oberthur.c:auth_card_ctl:
 1448|      4|{
 1449|      4|	switch (cmd) {
 1450|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1450:2): [True: 0, False: 4]
  ------------------
 1451|      0|		return auth_get_default_key(card,
 1452|      0|				(struct sc_cardctl_default_key *) ptr);
 1453|      0|	case SC_CARDCTL_OBERTHUR_GENERATE_KEY:
  ------------------
  |  Branch (1453:2): [True: 0, False: 4]
  ------------------
 1454|      0|		return auth_generate_key(card, 0,
 1455|      0|				(struct sc_cardctl_oberthur_genkey_info *) ptr);
 1456|      0|	case SC_CARDCTL_OBERTHUR_UPDATE_KEY:
  ------------------
  |  Branch (1456:2): [True: 0, False: 4]
  ------------------
 1457|      0|		return auth_update_key(card,
 1458|      0|				(struct sc_cardctl_oberthur_updatekey_info *) ptr);
 1459|      0|	case SC_CARDCTL_OBERTHUR_CREATE_PIN:
  ------------------
  |  Branch (1459:2): [True: 0, False: 4]
  ------------------
 1460|      0|		return auth_create_reference_data(card,
 1461|      0|				(struct sc_cardctl_oberthur_createpin_info *) ptr);
 1462|      4|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1462:2): [True: 4, False: 0]
  ------------------
 1463|      4|		return auth_get_serialnr(card, (struct sc_serial_number *)ptr);
 1464|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1464:2): [True: 0, False: 4]
  ------------------
 1465|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1465:2): [True: 0, False: 4]
  ------------------
 1466|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1467|      0|	default:
  ------------------
  |  Branch (1467:2): [True: 0, False: 4]
  ------------------
 1468|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1469|      4|	}
 1470|      4|}
card-oberthur.c:auth_init_pin_info:
 1534|  1.30k|{
 1535|  1.30k|	pin->offset = 0;
 1536|  1.30k|	pin->pad_char   = 0xFF;
 1537|  1.30k|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|  1.30k|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1538|       |
 1539|  1.30k|	if (type == OBERTHUR_AUTH_TYPE_PIN) {
  ------------------
  |  |   92|  1.30k|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
  |  Branch (1539:6): [True: 1.30k, False: 2]
  ------------------
 1540|  1.30k|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|  1.30k|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1541|  1.30k|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|  1.30k|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1542|  1.30k|	} else {
 1543|      2|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      2|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1544|      2|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      2|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1545|      2|	}
 1546|  1.30k|}
card-oberthur.c:auth_get_serialnr:
 2262|      4|{
 2263|      4|	if (!serial)
  ------------------
  |  Branch (2263:6): [True: 0, False: 4]
  ------------------
 2264|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2265|       |
 2266|      4|	if (card->serialnr.len==0)
  ------------------
  |  Branch (2266:6): [True: 0, False: 4]
  ------------------
 2267|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2268|       |
 2269|      4|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2270|       |
 2271|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2272|      4|}
card-oberthur.c:auth_set_security_env:
  978|    537|{
  979|    537|	struct auth_senv *auth_senv = &((struct auth_private_data *) card->drv_data)->senv;
  980|    537|	struct sc_apdu apdu;
  981|    537|	long unsigned pads = env->algorithm_flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|    537|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  982|    537|	long unsigned supported_pads = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  111|    537|#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|    537|#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|    537|#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|    537|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  983|    537|	int rv;
  984|    537|	unsigned char rsa_sbuf[3] = {
  985|    537|		0x80, 0x01, 0xFF
  986|    537|	};
  987|    537|	unsigned char des_sbuf[13] = {
  988|    537|		0x80, 0x01, 0x01,
  989|    537|		0x87, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  990|    537|	};
  991|       |
  992|    537|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    537|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    537|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    537|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    537|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 537]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  993|    537|	sc_log(card->ctx,
  ------------------
  |  |   71|    537|#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|    537|	       "op %i; path %s; key_ref 0x%X; algos 0x%lX; flags 0x%lX",
  995|    537|	       env->operation, sc_print_path(&env->file_ref), env->key_ref[0],
  996|    537|	       env->algorithm_flags, env->flags);
  997|       |
  998|    537|	memset(auth_senv, 0, sizeof(struct auth_senv));
  999|       |
 1000|    537|	if (!(env->flags & SC_SEC_ENV_FILE_REF_PRESENT))
  ------------------
  |  |   57|    537|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1000:6): [True: 0, False: 537]
  ------------------
 1001|    537|		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|    537|	switch (env->algorithm) {
 1004|      0|	case SC_ALGORITHM_DES:
  ------------------
  |  |   76|      0|#define SC_ALGORITHM_DES		64
  ------------------
  |  Branch (1004:2): [True: 0, False: 537]
  ------------------
 1005|      0|	case SC_ALGORITHM_3DES:
  ------------------
  |  |   77|      0|#define SC_ALGORITHM_3DES		65
  ------------------
  |  Branch (1005:2): [True: 0, False: 537]
  ------------------
 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|    537|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    537|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1021:2): [True: 537, False: 0]
  ------------------
 1022|    537|		sc_log(card->ctx, "algo SC_ALGORITHM_RSA");
  ------------------
  |  |   71|    537|#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|    537|		if (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES) {
  ------------------
  |  |  142|    537|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1023:7): [True: 0, False: 537]
  ------------------
 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|    537|		if (pads & (~supported_pads)) {
  ------------------
  |  Branch (1027:7): [True: 0, False: 537]
  ------------------
 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|    537|		if (env->operation == SC_SEC_OPERATION_SIGN) {
  ------------------
  |  |   48|    537|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1032:7): [True: 326, False: 211]
  ------------------
 1033|    326|			rsa_sbuf[2] = 0x11;
 1034|       |
 1035|    326|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB6);
  ------------------
  |  |  293|    326|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1036|    326|			apdu.lc = sizeof(rsa_sbuf);
 1037|    326|			apdu.datalen = sizeof(rsa_sbuf);
 1038|    326|			apdu.data = rsa_sbuf;
 1039|    326|		} else if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   47|    211|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1039:14): [True: 211, False: 0]
  ------------------
 1040|    211|			rsa_sbuf[2] = 0x11;
 1041|       |
 1042|    211|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB8);
  ------------------
  |  |  293|    211|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1043|    211|			apdu.lc = sizeof(rsa_sbuf);
 1044|    211|			apdu.datalen = sizeof(rsa_sbuf);
 1045|    211|			apdu.data = rsa_sbuf;
 1046|    211|		} 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|    537|		break;
 1052|    537|	default:
  ------------------
  |  Branch (1052:2): [True: 0, False: 537]
  ------------------
 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|    537|	}
 1055|       |
 1056|    537|	rv = sc_transmit_apdu(card, &apdu);
 1057|    537|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    537|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    537|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    537|	int _ret = (r); \
  |  |  |  |  168|    537|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 518]
  |  |  |  |  ------------------
  |  |  |  |  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|    537|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 518]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1058|    518|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1059|    518|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    518|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    518|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    518|	int _ret = (r); \
  |  |  |  |  168|    518|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 186, False: 332]
  |  |  |  |  ------------------
  |  |  |  |  169|    186|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    186|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    186|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    186|		return _ret; \
  |  |  |  |  172|    186|	} \
  |  |  |  |  173|    518|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 332]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1060|       |
 1061|    332|	auth_senv->algorithm = env->algorithm;
 1062|       |
 1063|    332|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    332|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    332|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    332|	int _ret = r; \
  |  |  |  |  155|    332|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 332, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    332|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 332]
  |  |  |  |  ------------------
  |  |  |  |  157|    332|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    332|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    332|	return _ret; \
  |  |  |  |  163|    332|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1064|    332|}
card-oberthur.c:auth_compute_signature:
 1077|    182|{
 1078|    182|	struct sc_apdu apdu;
 1079|    182|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1080|    182|	int rv;
 1081|       |
 1082|    182|	if (!card || !in || !out) {
  ------------------
  |  Branch (1082:6): [True: 0, False: 182]
  |  Branch (1082:15): [True: 0, False: 182]
  |  Branch (1082:22): [True: 0, False: 182]
  ------------------
 1083|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1084|    182|	} else if (ilen > 96) {
  ------------------
  |  Branch (1084:13): [True: 65, False: 117]
  ------------------
 1085|     65|		sc_log(card->ctx, "Illegal input length %zu", ilen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1086|     65|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Illegal input length");
  ------------------
  |  |  174|     65|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     65|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     65|	int _ret = (r); \
  |  |  |  |  168|     65|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 65, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     65|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     65|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     65|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     65|		return _ret; \
  |  |  |  |  172|     65|	} \
  |  |  |  |  173|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1087|     65|	}
 1088|       |
 1089|    117|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    117|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    117|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    117|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    117|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 117]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1090|    117|	sc_log(card->ctx, "inlen %zu, outlen %zu", ilen, olen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1091|       |
 1092|    117|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  294|    117|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1093|    117|	apdu.datalen = ilen;
 1094|    117|	apdu.data = in;
 1095|    117|	apdu.lc = ilen;
 1096|    117|	apdu.le = MIN(olen, SC_MAX_APDU_RESP_SIZE);
  ------------------
  |  |   69|    117|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 0, False: 117]
  |  |  ------------------
  ------------------
 1097|    117|	apdu.resp = resp;
 1098|    117|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    117|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1099|       |
 1100|    117|	rv = sc_transmit_apdu(card, &apdu);
 1101|    117|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    117|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    117|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    117|	int _ret = (r); \
  |  |  |  |  168|    117|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 30, False: 87]
  |  |  |  |  ------------------
  |  |  |  |  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|    117|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 87]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1102|     87|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1103|     87|	LOG_TEST_RET(card->ctx, rv, "Compute signature failed");
  ------------------
  |  |  174|     87|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     87|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     87|	int _ret = (r); \
  |  |  |  |  168|     87|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 62]
  |  |  |  |  ------------------
  |  |  |  |  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|     87|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 62]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|       |
 1105|     62|	if (apdu.resplen > olen) {
  ------------------
  |  Branch (1105:6): [True: 0, False: 62]
  ------------------
 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|     62|	memcpy(out, apdu.resp, apdu.resplen);
 1111|       |
 1112|     62|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 23, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  156|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  157|     23|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     39|	} else { \
  |  |  |  |  159|     39|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     39|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     39|	} \
  |  |  |  |  162|     62|	return _ret; \
  |  |  |  |  163|     62|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1113|     62|}
card-oberthur.c:auth_decipher:
 1119|    150|{
 1120|    150|	struct sc_apdu apdu;
 1121|    150|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1122|    150|	int rv;
 1123|    150|	size_t _inlen = inlen;
 1124|       |
 1125|    150|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    150|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    150|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    150|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    150|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1126|    150|	sc_log(card->ctx, "crgram_len %zu;  outlen %zu", inlen, outlen);
  ------------------
  |  |   71|    150|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1127|    150|	if (!out || !outlen || inlen > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|    150|#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: 150]
  |  Branch (1127:14): [True: 0, False: 150]
  |  Branch (1127:25): [True: 13, False: 137]
  ------------------
 1128|    150|		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|    137|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|    137|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1131|       |
 1132|    137|	sc_log(card->ctx, "algorithm SC_ALGORITHM_RSA");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1133|    137|	if (inlen % 64) {
  ------------------
  |  Branch (1133:6): [True: 64, False: 73]
  ------------------
 1134|     64|		rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     64|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1135|     64|		goto done;
 1136|     64|	}
 1137|       |
 1138|     73|	_inlen = inlen;
 1139|     73|	if (_inlen == SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|     73|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (1139:6): [True: 40, False: 33]
  ------------------
 1140|     40|		apdu.cla |= 0x10;
 1141|     40|		apdu.data = in;
 1142|     40|		apdu.datalen = 8;
 1143|     40|		apdu.resp = resp;
 1144|     40|		apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     40|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1145|     40|		apdu.lc = 8;
 1146|     40|		apdu.le = SC_MAX_APDU_RESP_SIZE;
  ------------------
  |  |   36|     40|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
 1147|       |
 1148|     40|		rv = sc_transmit_apdu(card, &apdu);
 1149|     40|		sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   71|     40|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1150|     40|		LOG_TEST_RET(card->ctx, rv, "APDU 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: 12, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  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|     40|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|     28|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1152|     28|		LOG_TEST_RET(card->ctx, rv, "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: 12, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1153|       |
 1154|     16|		_inlen -= 8;
 1155|     16|		in += 8;
 1156|       |
 1157|     16|		apdu.cla &= ~0x10;
 1158|     16|	}
 1159|       |
 1160|     49|	apdu.data = in;
 1161|     49|	apdu.datalen = _inlen;
 1162|     49|	apdu.resp = resp;
 1163|     49|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     49|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1164|     49|	apdu.lc = _inlen;
 1165|     49|	apdu.le = _inlen;
 1166|       |
 1167|     49|	rv = sc_transmit_apdu(card, &apdu);
 1168|     49|	sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1169|     49|	LOG_TEST_RET(card->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: 21, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  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|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1170|     28|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1171|     28|	sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1172|     28|	LOG_TEST_RET(card->ctx, rv, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1173|       |
 1174|     17|	if (outlen > apdu.resplen)
  ------------------
  |  Branch (1174:6): [True: 17, False: 0]
  ------------------
 1175|     17|		outlen = apdu.resplen;
 1176|       |
 1177|     17|	memcpy(out, apdu.resp, outlen);
 1178|     17|	rv = (int)outlen;
 1179|       |
 1180|     81|done:
 1181|     81|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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: 68, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     64|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 64, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     68|	} 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|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1182|     81|}
card-oberthur.c:auth_process_fci:
  297|  6.20k|{
  298|  6.20k|	unsigned char type;
  299|  6.20k|	const unsigned char *attr;
  300|  6.20k|	size_t attr_len = 0;
  301|       |
  302|  6.20k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.20k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.20k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.20k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.20k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|  6.20k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  304|  6.20k|	if (!attr || attr_len < 1)
  ------------------
  |  Branch (304:6): [True: 3.29k, False: 2.91k]
  |  Branch (304:15): [True: 14, False: 2.89k]
  ------------------
  305|  6.20k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  3.30k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.30k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.30k|	int _ret = r; \
  |  |  |  |  155|  3.30k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.30k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.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|  3.30k|	return _ret; \
  |  |  |  |  163|  3.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|  2.89k|	type = attr[0];
  307|       |
  308|  2.89k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x83, &attr_len);
  309|  2.89k|	if (!attr || attr_len < 2)
  ------------------
  |  Branch (309:6): [True: 135, False: 2.76k]
  |  Branch (309:15): [True: 10, False: 2.75k]
  ------------------
  310|  2.89k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  311|  2.75k|	file->id = attr[0]*0x100 + attr[1];
  312|       |
  313|  2.75k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, type==0x01 ? 0x80 : 0x85, &attr_len);
  ------------------
  |  Branch (313:50): [True: 222, False: 2.53k]
  ------------------
  314|  2.75k|	switch (type) {
  315|    222|	case 0x01:
  ------------------
  |  Branch (315:2): [True: 222, False: 2.53k]
  ------------------
  316|    222|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (316:7): [True: 31, False: 191]
  |  Branch (316:16): [True: 19, False: 172]
  ------------------
  317|    222|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     50|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     50|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     50|	int _ret = r; \
  |  |  |  |  155|     50|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 50, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     50|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     50|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 50, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     50|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     50|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     50|	return _ret; \
  |  |  |  |  163|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|    172|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    172|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  319|    172|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    172|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    172|		file->size = attr[0]*0x100 + attr[1];
  321|    172|		break;
  322|  1.83k|	case 0x04:
  ------------------
  |  Branch (322:2): [True: 1.83k, False: 917]
  ------------------
  323|  1.83k|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (323:7): [True: 285, False: 1.55k]
  |  Branch (323:16): [True: 10, False: 1.54k]
  ------------------
  324|  1.83k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    295|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    295|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    295|	int _ret = r; \
  |  |  |  |  155|    295|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 295, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    295|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    295|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    295|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    295|	return _ret; \
  |  |  |  |  163|    295|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|  1.54k|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.54k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  326|  1.54k|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|  1.54k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  327|  1.54k|		file->size = attr[0];
  328|  1.54k|		attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  329|  1.54k|		if (!attr || attr_len < 5)
  ------------------
  |  Branch (329:7): [True: 0, False: 1.54k]
  |  Branch (329:16): [True: 11, False: 1.53k]
  ------------------
  330|  1.54k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|  1.53k|		file->record_length = attr[2]*0x100+attr[3];
  332|  1.53k|		file->record_count = attr[4];
  333|  1.53k|		break;
  334|     56|	case 0x11:
  ------------------
  |  Branch (334:2): [True: 56, False: 2.69k]
  ------------------
  335|     56|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (335:7): [True: 18, False: 38]
  |  Branch (335:16): [True: 10, False: 28]
  ------------------
  336|     56|			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|     28|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     28|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  338|     28|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_DES;
  339|     28|		file->size = attr[0]*0x100 + attr[1];
  340|     28|		file->size /= 8;
  341|     28|		break;
  342|    155|	case 0x12:
  ------------------
  |  Branch (342:2): [True: 155, False: 2.59k]
  ------------------
  343|    155|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (343:7): [True: 10, False: 145]
  |  Branch (343:16): [True: 18, False: 127]
  ------------------
  344|    155|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|    127|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    127|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  346|    127|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC;
  347|       |
  348|    127|		file->size = attr[0]*0x100 + attr[1];
  349|    127|		if (file->size==512)
  ------------------
  |  Branch (349:7): [True: 17, False: 110]
  ------------------
  350|     17|			file->size = PUBKEY_512_ASN1_SIZE;
  ------------------
  |  |  100|     17|#define PUBKEY_512_ASN1_SIZE	0x4A
  ------------------
  351|    110|		else if (file->size==1024)
  ------------------
  |  Branch (351:12): [True: 25, False: 85]
  ------------------
  352|     25|			file->size = PUBKEY_1024_ASN1_SIZE;
  ------------------
  |  |  101|     25|#define PUBKEY_1024_ASN1_SIZE	0x8C
  ------------------
  353|     85|		else if (file->size==2048)
  ------------------
  |  Branch (353:12): [True: 0, False: 85]
  ------------------
  354|      0|			file->size = PUBKEY_2048_ASN1_SIZE;
  ------------------
  |  |  102|      0|#define PUBKEY_2048_ASN1_SIZE	0x10E
  ------------------
  355|     85|		else {
  356|     85|			sc_log(card->ctx, "Not supported public key size: %zu", file->size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  357|     85|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     85|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|     85|		}
  359|     42|		break;
  360|     51|	case 0x14:
  ------------------
  |  Branch (360:2): [True: 51, False: 2.70k]
  ------------------
  361|     51|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (361:7): [True: 23, False: 28]
  |  Branch (361:16): [True: 15, False: 13]
  ------------------
  362|     51|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  363|     13|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     13|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  364|     13|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_CRT;
  365|     13|		file->size = attr[0]*0x100 + attr[1];
  366|     13|		break;
  367|    374|	case 0x38:
  ------------------
  |  Branch (367:2): [True: 374, False: 2.38k]
  ------------------
  368|    374|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (368:7): [True: 13, False: 361]
  |  Branch (368:16): [True: 10, False: 351]
  ------------------
  369|    374|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  370|    351|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    351|#define SC_FILE_TYPE_DF			0x04
  ------------------
  371|    351|		file->size = attr[0];
  372|    351|		if (SC_SUCCESS != sc_file_set_type_attr(file,attr,attr_len))
  ------------------
  |  |   28|    351|#define SC_SUCCESS				0
  ------------------
  |  Branch (372:7): [True: 0, False: 351]
  ------------------
  373|    351|			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|    351|		break;
  375|    351|	default:
  ------------------
  |  Branch (375:2): [True: 59, False: 2.69k]
  ------------------
  376|     59|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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: 59, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     59|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     59|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 59, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     59|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     59|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     59|	return _ret; \
  |  |  |  |  163|     59|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|  2.75k|	}
  378|       |
  379|  2.13k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x86, &attr_len);
  380|  2.13k|	if (!attr || attr_len < 8)
  ------------------
  |  Branch (380:6): [True: 1.68k, False: 454]
  |  Branch (380:15): [True: 24, False: 430]
  ------------------
  381|  2.13k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.70k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.70k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.70k|	int _ret = r; \
  |  |  |  |  155|  1.70k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.70k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.70k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.70k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.70k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.70k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.70k|	return _ret; \
  |  |  |  |  163|  1.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    430|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    430|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (383:6): [True: 305, False: 125]
  ------------------
  384|    305|		add_acl_entry(card, file, SC_AC_OP_CREATE, attr[0]);
  ------------------
  |  |  169|    305|#define SC_AC_OP_CREATE			3
  ------------------
  385|    305|		add_acl_entry(card, file, SC_AC_OP_CRYPTO, attr[1]);
  ------------------
  |  |  173|    305|#define SC_AC_OP_CRYPTO			7
  ------------------
  386|    305|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, attr[2]);
  ------------------
  |  |  172|    305|#define SC_AC_OP_LIST_FILES		6
  ------------------
  387|    305|		add_acl_entry(card, file, SC_AC_OP_DELETE, attr[3]);
  ------------------
  |  |  168|    305|#define SC_AC_OP_DELETE			2
  ------------------
  388|    305|		add_acl_entry(card, file, SC_AC_OP_PIN_DEFINE, attr[4]);
  ------------------
  |  |  183|    305|#define SC_AC_OP_PIN_DEFINE		17
  ------------------
  389|    305|		add_acl_entry(card, file, SC_AC_OP_PIN_CHANGE, attr[5]);
  ------------------
  |  |  184|    305|#define SC_AC_OP_PIN_CHANGE		18
  ------------------
  390|    305|		add_acl_entry(card, file, SC_AC_OP_PIN_RESET, attr[6]);
  ------------------
  |  |  185|    305|#define SC_AC_OP_PIN_RESET		19
  ------------------
  391|    305|		sc_log(card->ctx, "SC_FILE_TYPE_DF:CRYPTO %X", attr[1]);
  ------------------
  |  |   71|    305|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  392|    305|	} else if (file->type == SC_FILE_TYPE_INTERNAL_EF) { /* EF */
  ------------------
  |  |  215|    125|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (392:13): [True: 65, False: 60]
  ------------------
  393|     65|		switch (file->ef_structure) {
  ------------------
  |  Branch (393:11): [True: 65, False: 0]
  ------------------
  394|     28|		case SC_CARDCTL_OBERTHUR_KEY_DES:
  ------------------
  |  Branch (394:3): [True: 28, False: 37]
  ------------------
  395|     28|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     28|#define SC_AC_OP_UPDATE			23
  ------------------
  396|     28|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     28|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  397|     28|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     28|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  398|     28|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_CHECKSUM, attr[3]);
  ------------------
  |  |  179|     28|#define SC_AC_OP_PSO_COMPUTE_CHECKSUM	13
  ------------------
  399|     28|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_CHECKSUM, attr[4]);
  ------------------
  |  |  180|     28|#define SC_AC_OP_PSO_VERIFY_CHECKSUM	14
  ------------------
  400|     28|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     28|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  401|     28|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     28|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  402|     28|			break;
  403|     27|		case SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC:
  ------------------
  |  Branch (403:3): [True: 27, False: 38]
  ------------------
  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: 55]
  ------------------
  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|     65|		}
  416|     65|	} else {
  417|     60|		switch (file->ef_structure) {
  ------------------
  |  Branch (417:11): [True: 60, False: 0]
  ------------------
  418|     42|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     42|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (418:3): [True: 42, False: 18]
  ------------------
  419|     42|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     42|#define SC_AC_OP_WRITE			24
  ------------------
  420|     42|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     42|#define SC_AC_OP_UPDATE			23
  ------------------
  421|     42|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     42|#define SC_AC_OP_READ			22
  ------------------
  422|     42|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     42|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     42|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  423|     42|			break;
  424|     18|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     18|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (424:3): [True: 18, False: 42]
  ------------------
  425|     18|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     18|#define SC_AC_OP_WRITE			24
  ------------------
  426|     18|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     18|#define SC_AC_OP_UPDATE			23
  ------------------
  427|     18|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     18|#define SC_AC_OP_READ			22
  ------------------
  428|     18|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     18|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     18|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  429|     18|			break;
  430|     60|		}
  431|     60|	}
  432|       |
  433|    430|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    430|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  434|    430|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|    430|#define SC_FILE_MAGIC			0x14426950
  ------------------
  435|       |
  436|    430|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    430|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    430|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    430|	int _ret = r; \
  |  |  |  |  155|    430|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 430, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    430|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 430]
  |  |  |  |  ------------------
  |  |  |  |  157|    430|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    430|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    430|	return _ret; \
  |  |  |  |  163|    430|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    430|}
card-oberthur.c:add_acl_entry:
  260|  2.71k|{
  261|  2.71k|	if ((acl_byte & 0xE0) == 0x60) {
  ------------------
  |  Branch (261:6): [True: 723, False: 1.99k]
  ------------------
  262|    723|		sc_log(card->ctx, "called; op 0x%X; SC_AC_PRO; ref 0x%X", op, acl_byte);
  ------------------
  |  |   71|    723|#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|    723|		sc_file_add_acl_entry(file, op, SC_AC_PRO, acl_byte);
  ------------------
  |  |  153|    723|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  264|    723|		return;
  265|    723|	}
  266|       |
  267|  1.99k|	switch (acl_byte) {
  268|    466|	case 0x00:
  ------------------
  |  Branch (268:2): [True: 466, False: 1.53k]
  ------------------
  269|    466|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    466|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    466|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  270|    466|		break;
  271|       |	/* User and OneTime PINs are locals */
  272|     61|	case 0x21:
  ------------------
  |  Branch (272:2): [True: 61, False: 1.93k]
  ------------------
  273|    135|	case 0x22:
  ------------------
  |  Branch (273:2): [True: 74, False: 1.92k]
  ------------------
  274|    135|		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |  151|    135|#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|    135|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
  275|    135|		break;
  276|       |	/* Local SOPIN is only for the unblocking. */
  277|    144|	case 0x24:
  ------------------
  |  Branch (277:2): [True: 144, False: 1.85k]
  ------------------
  278|    294|	case 0x25:
  ------------------
  |  Branch (278:2): [True: 150, False: 1.84k]
  ------------------
  279|    294|		if (op == SC_AC_OP_PIN_RESET)
  ------------------
  |  |  185|    294|#define SC_AC_OP_PIN_RESET		19
  ------------------
  |  Branch (279:7): [True: 55, False: 239]
  ------------------
  280|     55|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x84);
  ------------------
  |  |  151|     55|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  281|    239|		else
  282|    239|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x04);
  ------------------
  |  |  151|    239|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  283|    294|		break;
  284|    280|	case 0xFF:
  ------------------
  |  Branch (284:2): [True: 280, False: 1.71k]
  ------------------
  285|    280|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    280|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    280|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  286|    280|		break;
  287|    821|	default:
  ------------------
  |  Branch (287:2): [True: 821, False: 1.17k]
  ------------------
  288|    821|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    821|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    821|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  289|    821|		break;
  290|  1.99k|	}
  291|  1.99k|}
card-oberthur.c:auth_pin_cmd:
 1888|  1.45k|{
 1889|  1.45k|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.45k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1890|       |
 1891|  1.45k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.45k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.45k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1892|  1.45k|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|  1.45k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1892:6): [True: 0, False: 1.45k]
  ------------------
 1893|  1.45k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1894|       |
 1895|  1.45k|	sc_log(card->ctx, "PIN CMD:%i; reference:%i; pin1:%p/%zu, pin2:%p/%zu", data->cmd,
  ------------------
  |  |   71|  1.45k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1896|  1.45k|			data->pin_reference, data->pin1.data, data->pin1.len,
 1897|  1.45k|			data->pin2.data, data->pin2.len);
 1898|  1.45k|	switch (data->cmd) {
 1899|  1.20k|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|  1.20k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1899:2): [True: 1.20k, False: 256]
  ------------------
 1900|  1.20k|		rv = auth_pin_verify(card, SC_AC_CHV, data);
  ------------------
  |  |  151|  1.20k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1901|  1.20k|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|  1.20k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.20k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.20k|	int _ret = (r); \
  |  |  |  |  168|  1.20k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 183, False: 1.01k]
  |  |  |  |  ------------------
  |  |  |  |  169|    183|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    183|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    183|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    183|		return _ret; \
  |  |  |  |  172|    183|	} \
  |  |  |  |  173|  1.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.01k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1902|  1.01k|		break;
 1903|  1.01k|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|     44|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1903:2): [True: 44, False: 1.41k]
  ------------------
 1904|     44|		rv = auth_pin_change(card, SC_AC_CHV, data);
  ------------------
  |  |  151|     44|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1905|     44|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' 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: 31, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1906|     13|		break;
 1907|     49|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|     49|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1907:2): [True: 49, False: 1.40k]
  ------------------
 1908|     49|		rv = auth_pin_reset(card, SC_AC_CHV, data);
  ------------------
  |  |  151|     49|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1909|     49|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' 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: 49, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     49|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1910|      0|		break;
 1911|    163|	default:
  ------------------
  |  Branch (1911:2): [True: 163, False: 1.29k]
  ------------------
 1912|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1913|  1.45k|	}
 1914|       |
 1915|  1.03k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1916|  1.03k|}
card-oberthur.c:auth_pin_verify:
 1608|  1.21k|{
 1609|  1.21k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1610|  1.21k|	int rv;
 1611|       |
 1612|  1.21k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.21k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.21k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.21k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.21k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1613|       |
 1614|  1.21k|	if (type != SC_AC_CHV)
  ------------------
  |  |  151|  1.21k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1614:6): [True: 0, False: 1.21k]
  ------------------
 1615|  1.21k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1616|       |
 1617|  1.21k|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|  1.21k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1618|       |
 1619|  1.21k|	auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|  1.21k|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1620|       |
 1621|       |	/* User PIN is always local. */
 1622|  1.21k|	if (data->pin_reference == OBERTHUR_PIN_REFERENCE_USER
  ------------------
  |  |   42|  2.43k|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1622:6): [True: 524, False: 691]
  ------------------
 1623|    691|			|| data->pin_reference == OBERTHUR_PIN_REFERENCE_ONETIME)
  ------------------
  |  |   43|    691|#define OBERTHUR_PIN_REFERENCE_ONETIME	0x82
  ------------------
  |  Branch (1623:7): [True: 0, False: 691]
  ------------------
 1624|    524|		data->pin_reference  |= OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|    524|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1625|       |
 1626|  1.21k|        rv = auth_pin_is_verified(card, data->pin_reference, &data->pin1.tries_left);
 1627|  1.21k|    	sc_log(card->ctx, "auth_pin_is_verified returned rv %i", rv);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 1628|       |
 1629|       |	/* Return if only PIN status has been asked. */
 1630|  1.21k|	if (data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1630:6): [True: 1.21k, False: 0]
  |  Branch (1630:25): [True: 1.10k, False: 114]
  ------------------
 1631|  1.21k|		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: 1.10k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.10k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    135|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 135, False: 966]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.10k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.10k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.10k|	return _ret; \
  |  |  |  |  163|  1.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1632|       |
 1633|       |	/* Return SUCCESS without verifying if
 1634|       |	 * PIN has been already verified and PIN pad has to be used. */
 1635|    114|	if (!rv && !data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1635:6): [True: 44, False: 70]
  |  Branch (1635:13): [True: 0, False: 44]
  |  Branch (1635:33): [True: 0, False: 0]
  ------------------
 1636|    114|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1637|       |
 1638|    114|	if (!data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1638:6): [True: 0, False: 114]
  |  Branch (1638:26): [True: 0, False: 0]
  ------------------
 1639|      0|		rv = auth_pin_verify_pinpad(card, data->pin_reference, &data->pin1.tries_left);
 1640|    114|	else
 1641|    114|		rv = iso_drv->ops->pin_cmd(card, data);
 1642|       |
 1643|    114|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    114|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    114|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    114|	int _ret = r; \
  |  |  |  |  155|    114|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 114, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    114|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 55, False: 59]
  |  |  |  |  ------------------
  |  |  |  |  157|    114|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    114|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    114|	return _ret; \
  |  |  |  |  163|    114|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1644|    114|}
card-oberthur.c:auth_pin_is_verified:
 1649|  1.21k|{
 1650|  1.21k|	struct sc_apdu apdu;
 1651|  1.21k|	int rv;
 1652|       |
 1653|  1.21k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_reference);
  ------------------
  |  |  291|  1.21k|#define SC_APDU_CASE_1			0x01
  ------------------
 1654|       |
 1655|  1.21k|	rv = sc_transmit_apdu(card, &apdu);
 1656|  1.21k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.21k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.21k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.21k|	int _ret = (r); \
  |  |  |  |  168|  1.21k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 1.21k]
  |  |  |  |  ------------------
  |  |  |  |  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.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1657|       |
 1658|  1.21k|	if (tries_left && apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1658:6): [True: 1.21k, False: 0]
  |  Branch (1658:20): [True: 76, False: 1.13k]
  |  Branch (1658:40): [True: 67, False: 9]
  ------------------
 1659|     67|		*tries_left = apdu.sw2 & 0x0F;
 1660|       |
 1661|       |	/* Replace 'no tries left' with 'auth method blocked' */
 1662|  1.21k|	if (apdu.sw1 == 0x63 && apdu.sw2 == 0xC0) {
  ------------------
  |  Branch (1662:6): [True: 76, False: 1.13k]
  |  Branch (1662:26): [True: 1, False: 75]
  ------------------
 1663|      1|		apdu.sw1 = 0x69;
 1664|      1|		apdu.sw2 = 0x83;
 1665|      1|	}
 1666|       |
 1667|  1.21k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1668|       |
 1669|  1.21k|	return rv;
 1670|  1.21k|}
card-oberthur.c:auth_pin_change:
 1732|     44|{
 1733|     44|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1734|     44|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     44|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1735|       |
 1736|     44|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     44|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     44|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     44|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     44|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 44]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1737|       |
 1738|     44|	if (data->pin1.len && data->pin2.len) {
  ------------------
  |  Branch (1738:6): [True: 44, False: 0]
  |  Branch (1738:24): [True: 44, False: 0]
  ------------------
 1739|       |		/* Direct unblock style */
 1740|     44|		data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|     44|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1741|     44|		data->flags &= ~SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|     44|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
 1742|     44|		data->apdu = NULL;
 1743|       |
 1744|     44|		data->pin_reference &= ~OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|     44|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1745|       |
 1746|     44|		auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|     44|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1747|     44|		auth_init_pin_info(card, &data->pin2, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|     44|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1748|       |
 1749|     44|		rv = iso_drv->ops->pin_cmd(card, data);
 1750|     44|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN CHANGE' 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: 31, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1751|     44|	} else if (!data->pin1.len && !data->pin2.len) {
  ------------------
  |  Branch (1751:13): [True: 0, False: 0]
  |  Branch (1751:32): [True: 0, False: 0]
  ------------------
 1752|       |		/* Oberthur unblock style with PIN pad. */
 1753|      0|		rv = auth_pin_change_pinpad(card, data);
 1754|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1755|      0|	} else {
 1756|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1757|      0|	}
 1758|       |
 1759|     13|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1760|     13|}
card-oberthur.c:auth_pin_reset:
 1873|     51|{
 1874|     51|	int rv;
 1875|       |
 1876|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1877|       |
 1878|       |	/* Oberthur unblock style: PUK value is a SOPIN */
 1879|     51|	rv = auth_pin_reset_oberthur_style(card, SC_AC_CHV, data);
  ------------------
  |  |  151|     51|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1880|     51|	LOG_TEST_RET(card->ctx, rv, "Oberthur style 'PIN RESET' 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: 51, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1881|       |
 1882|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1883|      0|}
card-oberthur.c:auth_pin_reset_oberthur_style:
 1766|     51|{
 1767|     51|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1768|     51|	struct sc_pin_cmd_data pin_cmd;
 1769|     51|	struct sc_path tmp_path;
 1770|     51|	struct sc_file *tmp_file = NULL;
 1771|     51|	struct sc_apdu apdu;
 1772|     51|	unsigned char puk[OBERTHUR_AUTH_MAX_LENGTH_PUK];
 1773|     51|	unsigned char ffs1[0x100];
 1774|     51|	int rv, rvv, local_pin_reference;
 1775|       |
 1776|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1777|       |
 1778|     51|	local_pin_reference = data->pin_reference & ~OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|     51|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1779|       |
 1780|     51|	if (data->pin_reference !=  OBERTHUR_PIN_REFERENCE_USER)
  ------------------
  |  |   42|     51|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1780:6): [True: 37, False: 14]
  ------------------
 1781|     51|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Oberthur style 'PIN RESET' failed: invalid PIN reference");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1782|       |
 1783|     14|	memset(&pin_cmd, 0, sizeof(pin_cmd));
 1784|     14|	memset(&tmp_path, 0, sizeof(struct sc_path));
 1785|       |
 1786|     14|	pin_cmd.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|     14|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1787|     14|	pin_cmd.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|     14|#define SC_PIN_CMD_VERIFY	0
  ------------------
 1788|     14|	pin_cmd.pin_reference = OBERTHUR_PIN_REFERENCE_PUK;
  ------------------
  |  |   45|     14|#define OBERTHUR_PIN_REFERENCE_PUK	0x84
  ------------------
 1789|     14|	memcpy(&pin_cmd.pin1, &data->pin1, sizeof(pin_cmd.pin1));
 1790|       |
 1791|     14|	rv = auth_pin_verify(card, SC_AC_CHV, &pin_cmd);
  ------------------
  |  |  151|     14|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1792|     14|	LOG_TEST_RET(card->ctx, rv, "Oberthur style 'PIN RESET' failed: SOPIN verify 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: 7, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1793|       |
 1794|      7|	sc_format_path("2000", &tmp_path);
 1795|      7|	tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      7|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1796|      7|	rv = iso_ops->select_file(card, &tmp_path, &tmp_file);
 1797|      7|	LOG_TEST_RET(card->ctx, rv, "select PUK file");
  ------------------
  |  |  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: 1, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1798|       |
 1799|      6|	if (!tmp_file || tmp_file->size < OBERTHUR_AUTH_MAX_LENGTH_PUK) {
  ------------------
  |  |   96|      6|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
  |  Branch (1799:6): [True: 0, False: 6]
  |  Branch (1799:19): [True: 1, False: 5]
  ------------------
 1800|      1|		sc_file_free(tmp_file);
 1801|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1802|      1|	}
 1803|      5|	sc_file_free(tmp_file);
 1804|       |
 1805|      5|	rv = iso_ops->read_binary(card, 0, puk, OBERTHUR_AUTH_MAX_LENGTH_PUK, 0);
  ------------------
  |  |   96|      5|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1806|      5|	LOG_TEST_RET(card->ctx, rv, "read PUK file error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1807|      4|	if (rv != OBERTHUR_AUTH_MAX_LENGTH_PUK)
  ------------------
  |  |   96|      4|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
  |  Branch (1807:6): [True: 2, False: 2]
  ------------------
 1808|      4|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_DATA, "Oberthur style 'PIN RESET' failed");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1809|       |
 1810|      2|	memset(ffs1, 0xFF, sizeof(ffs1));
 1811|      2|	memcpy(ffs1, puk, rv);
 1812|       |
 1813|      2|	memset(&pin_cmd, 0, sizeof(pin_cmd));
 1814|      2|	pin_cmd.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      2|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1815|      2|        pin_cmd.cmd = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  417|      2|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
 1816|      2|	pin_cmd.pin_reference = local_pin_reference;
 1817|      2|	auth_init_pin_info(card, &pin_cmd.pin1, OBERTHUR_AUTH_TYPE_PUK);
  ------------------
  |  |   93|      2|#define OBERTHUR_AUTH_TYPE_PUK		2
  ------------------
 1818|      2|	pin_cmd.pin1.data = ffs1;
 1819|      2|	pin_cmd.pin1.len = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      2|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1820|       |
 1821|      2|	if (data->pin2.data) {
  ------------------
  |  Branch (1821:6): [True: 2, False: 0]
  ------------------
 1822|      2|		memcpy(&pin_cmd.pin2, &data->pin2, sizeof(pin_cmd.pin2));
 1823|      2|		rv = auth_pin_reset(card, SC_AC_CHV, &pin_cmd);
  ------------------
  |  |  151|      2|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1824|      2|		LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1825|      2|	}
 1826|       |
 1827|      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
  ------------------
 1828|      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
  ------------------
 1829|      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
  ------------------
 1830|      0|	apdu.data = ffs1;
 1831|       |
 1832|      0|	pin_cmd.apdu = &apdu;
 1833|      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
  ------------------
 1834|       |
 1835|      0|	pin_cmd.pin1.min_length = 4;
 1836|      0|	pin_cmd.pin1.max_length = 8;
 1837|      0|	pin_cmd.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1838|      0|	pin_cmd.pin1.offset = 5;
 1839|       |
 1840|      0|	pin_cmd.pin2.data = &ffs1[OBERTHUR_AUTH_MAX_LENGTH_PUK];
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1841|      0|	pin_cmd.pin2.len = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1842|      0|	pin_cmd.pin2.offset = 5 + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1843|      0|	pin_cmd.pin2.min_length = 4;
 1844|      0|	pin_cmd.pin2.max_length = 8;
 1845|      0|	pin_cmd.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1846|       |
 1847|      0|	rvv = iso_drv->ops->pin_cmd(card, &pin_cmd);
 1848|      0|	if (rvv)
  ------------------
  |  Branch (1848:6): [True: 0, False: 0]
  ------------------
 1849|      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__
  |  |  ------------------
  ------------------
 1850|      0|				"%s: PIN CMD 'VERIFY' with pinpad failed",
 1851|      0|				sc_strerror(rvv));
 1852|       |
 1853|      0|	if (auth_current_ef) {
  ------------------
  |  Branch (1853:6): [True: 0, False: 0]
  ------------------
 1854|      0|		struct sc_file *ef = NULL;
 1855|      0|		rv = iso_ops->select_file(card, &auth_current_ef->path, &ef);
 1856|      0|		if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1856:7): [True: 0, False: 0]
  ------------------
 1857|      0|			sc_file_free(auth_current_ef);
 1858|      0|			auth_current_ef = ef;
 1859|      0|		} else
 1860|      0|			sc_file_free(ef);
 1861|      0|	}
 1862|       |
 1863|      0|	if (rv > 0)
  ------------------
  |  Branch (1863:6): [True: 0, False: 0]
  ------------------
 1864|      0|		rv = 0;
 1865|       |
 1866|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1867|      0|}
card-oberthur.c:auth_check_sw:
 2285|  20.8k|{
 2286|  20.8k|	int ii;
 2287|       |
 2288|  41.6k|	for (ii = 0; auth_warnings[ii].SWs; ii++) {
  ------------------
  |  Branch (2288:15): [True: 20.8k, False: 20.8k]
  ------------------
 2289|  20.8k|		if (auth_warnings[ii].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (2289:7): [True: 90, False: 20.8k]
  ------------------
 2290|     90|			sc_log(card->ctx, "%s", auth_warnings[ii].errorstr);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2291|     90|			return auth_warnings[ii].errorno;
 2292|     90|		}
 2293|  20.8k|	}
 2294|       |
 2295|  20.8k|	return iso_ops->check_sw(card, sw1, sw2);
 2296|  20.8k|}

populate_blobs_to_mf:
  381|    680|{
  382|    680|	pgp_do_info_t	*info;
  383|       |
  384|    680|	if (priv->mf == NULL)
  ------------------
  |  Branch (384:6): [True: 0, False: 680]
  ------------------
  385|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  386|       |
  387|  40.3k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (387:33): [True: 40.3k, False: 0]
  |  Branch (387:51): [True: 39.6k, False: 680]
  ------------------
  388|  39.6k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (388:7): [True: 28.8k, False: 10.8k]
  |  Branch (388:53): [True: 13.1k, False: 15.6k]
  ------------------
  389|  13.1k|			pgp_blob_t *child = NULL;
  390|  13.1k|			sc_file_t *file = sc_file_new();
  391|       |
  392|  13.1k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  393|       |
  394|       |			/* catch out of memory condition */
  395|  13.1k|			if (child == NULL) {
  ------------------
  |  Branch (395:8): [True: 0, False: 13.1k]
  ------------------
  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|  13.1k|		}
  400|  39.6k|	}
  401|    680|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 680, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    680|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 680]
  |  |  |  |  ------------------
  |  |  |  |  157|    680|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    680|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|    680|}
_pgp_add_algo:
  740|  1.29k|{
  741|  1.29k|	unsigned long flags = 0, ext_flags = 0;
  742|       |
  743|  1.29k|	if (!card || !key_info)
  ------------------
  |  Branch (743:6): [True: 0, False: 1.29k]
  |  Branch (743:15): [True: 0, False: 1.29k]
  ------------------
  744|      0|		return 0;
  745|       |
  746|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  747|  1.29k|	switch (key_info->algorithm) {
  748|  1.29k|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|  1.29k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (748:2): [True: 1.29k, 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|  1.29k|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  111|  1.29k|#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.29k|#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.29k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  752|  1.29k|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  133|  1.29k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  753|  1.29k|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |   93|  1.29k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  754|       |
  755|  1.29k|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  756|  1.29k|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_len = %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__
  |  |  ------------------
  ------------------
  757|  1.29k|				do_num, key_info->u.rsa.modulus_len);
  758|  1.29k|		break;
  759|      0|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (759:2): [True: 0, False: 1.29k]
  ------------------
  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: 1.29k]
  ------------------
  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: 1.29k]
  ------------------
  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: 1.29k]
  ------------------
  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|  1.29k|	}
  798|       |	/* return true */
  799|  1.29k|	return 1;
  800|  1.29k|}
sc_get_openpgp_driver:
 4234|  16.1k|{
 4235|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4236|       |
 4237|  16.1k|	iso_ops = iso_drv->ops;
 4238|       |
 4239|  16.1k|	pgp_ops = *iso_ops;
 4240|  16.1k|	pgp_ops.match_card	= pgp_match_card;
 4241|  16.1k|	pgp_ops.init		= pgp_init;
 4242|  16.1k|	pgp_ops.finish		= pgp_finish;
 4243|  16.1k|	pgp_ops.select_file	= pgp_select_file;
 4244|  16.1k|	pgp_ops.list_files	= pgp_list_files;
 4245|  16.1k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4246|  16.1k|	pgp_ops.read_binary	= pgp_read_binary;
 4247|  16.1k|	pgp_ops.write_binary	= NULL;
 4248|  16.1k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4249|  16.1k|	pgp_ops.logout		= pgp_logout;
 4250|  16.1k|	pgp_ops.get_data	= pgp_get_data;
 4251|  16.1k|	pgp_ops.put_data	= pgp_put_data;
 4252|  16.1k|	pgp_ops.set_security_env= pgp_set_security_env;
 4253|  16.1k|	pgp_ops.compute_signature= pgp_compute_signature;
 4254|  16.1k|	pgp_ops.decipher	= pgp_decipher;
 4255|  16.1k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4256|  16.1k|	pgp_ops.delete_file	= pgp_delete_file;
 4257|  16.1k|	pgp_ops.update_binary	= pgp_update_binary;
 4258|  16.1k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4259|       |
 4260|  16.1k|	return &pgp_drv;
 4261|  16.1k|}
card-openpgp.c:pgp_new_blob:
 1240|  43.4k|{
 1241|  43.4k|	pgp_blob_t *blob = NULL;
 1242|       |
 1243|  43.4k|	if (file == NULL)
  ------------------
  |  Branch (1243:6): [True: 0, False: 43.4k]
  ------------------
 1244|      0|		return NULL;
 1245|       |
 1246|  43.4k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1246:6): [True: 43.4k, False: 0]
  ------------------
 1247|  43.4k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  43.4k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1248|  43.4k|		pgp_do_info_t *info;
 1249|       |
 1250|  43.4k|		blob->file = file;
 1251|       |
 1252|  43.4k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  43.4k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1253|  43.4k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  43.4k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1254|  43.4k|		blob->file->id           = file_id;
 1255|       |
 1256|  43.4k|		blob->id     = file_id;
 1257|  43.4k|		blob->parent = parent;
 1258|       |
 1259|  43.4k|		if (parent != NULL) {
  ------------------
  |  Branch (1259:7): [True: 42.8k, False: 680]
  ------------------
 1260|  42.8k|			pgp_blob_t **p;
 1261|       |
 1262|       |			/* set file's path = parent's path + file's id */
 1263|  42.8k|			blob->file->path = parent->file->path;
 1264|  42.8k|			sc_append_file_id(&blob->file->path, file_id);
 1265|       |
 1266|       |			/* append blob to list of parent's children */
 1267|  5.41M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1267:29): [True: 5.37M, False: 42.8k]
  ------------------
 1268|  5.37M|				;
 1269|  42.8k|			*p = blob;
 1270|  42.8k|		}
 1271|    680|		else {
 1272|    680|			char path[10] = "0000";	/* long enough */
 1273|       |
 1274|       |			/* no parent: set file's path = file's id */
 1275|    680|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1275:8): [True: 0, False: 680]
  ------------------
 1276|      0|				free(blob);
 1277|      0|				return NULL;
 1278|      0|			}
 1279|       |
 1280|    680|			sc_format_path(path, &blob->file->path);
 1281|    680|		}
 1282|       |
 1283|       |		/* find matching DO info: set file type depending on it */
 1284|  1.83M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1284:34): [True: 1.83M, False: 0]
  |  Branch (1284:52): [True: 1.82M, False: 13.4k]
  ------------------
 1285|  1.82M|			if (info->id == file_id) {
  ------------------
  |  Branch (1285:8): [True: 30.0k, False: 1.79M]
  ------------------
 1286|  30.0k|				blob->info = info;
 1287|  30.0k|				blob->file->type = blob->info->type;
 1288|  30.0k|				pgp_attach_acl(card, blob->file, info);
 1289|  30.0k|				break;
 1290|  30.0k|			}
 1291|  1.82M|		}
 1292|  43.4k|	}
 1293|       |
 1294|  43.4k|	return blob;
 1295|  43.4k|}
card-openpgp.c:pgp_attach_acl:
 1172|  30.0k|{
 1173|  30.0k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  30.0k|#define SC_AC_NONE			0x00000000
  ------------------
 1174|  30.0k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  30.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1175|       |
 1176|       |	/* Write access */
 1177|  30.0k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1177:10): [True: 30.0k, False: 0]
  ------------------
 1178|  7.65k|	case WRITE_NEVER:
  ------------------
  |  Branch (1178:2): [True: 7.65k, False: 22.3k]
  ------------------
 1179|  7.65k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  7.65k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1180|  7.65k|		break;
 1181|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1181:2): [True: 0, False: 30.0k]
  ------------------
 1182|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1183|      0|		key_ref = 0x01;
 1184|      0|		break;
 1185|  1.36k|	case WRITE_PIN2:
  ------------------
  |  Branch (1185:2): [True: 1.36k, False: 28.6k]
  ------------------
 1186|  1.36k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.36k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1187|  1.36k|		key_ref = 0x02;
 1188|  1.36k|		break;
 1189|  20.9k|	case WRITE_PIN3:
  ------------------
  |  Branch (1189:2): [True: 20.9k, False: 9.01k]
  ------------------
 1190|  20.9k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  20.9k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1191|  20.9k|		key_ref = 0x03;
 1192|  20.9k|		break;
 1193|  30.0k|	}
 1194|       |
 1195|  30.0k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  60.0k|#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: 30.0k, False: 0]
  |  Branch (1195:30): [True: 0, False: 0]
  ------------------
 1196|  30.0k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  30.0k|#define SC_AC_OP_WRITE			24
  ------------------
 1197|  30.0k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  30.0k|#define SC_AC_OP_UPDATE			23
  ------------------
 1198|  30.0k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  30.0k|#define SC_AC_OP_DELETE			2
  ------------------
 1199|  30.0k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  30.0k|#define SC_AC_OP_CREATE			3
  ------------------
 1200|  30.0k|	}
 1201|      0|	else {
 1202|       |		/* When SC_AC_OP_DELETE is absent, we need to provide
 1203|       |		 * SC_AC_OP_DELETE_SELF for sc_pkcs15init_delete_by_path() */
 1204|      0|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE_SELF, method, key_ref);
  ------------------
  |  |  174|      0|#define SC_AC_OP_DELETE_SELF		8
  ------------------
 1205|      0|	}
 1206|       |
 1207|  30.0k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  30.0k|#define SC_AC_NONE			0x00000000
  ------------------
 1208|  30.0k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  30.0k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1209|       |	/* Read access */
 1210|  30.0k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1210:10): [True: 3.26k, False: 26.7k]
  ------------------
 1211|  1.90k|	case READ_NEVER:
  ------------------
  |  Branch (1211:2): [True: 1.90k, False: 28.0k]
  ------------------
 1212|  1.90k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.90k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1213|  1.90k|		break;
 1214|      0|	case READ_PIN1:
  ------------------
  |  Branch (1214:2): [True: 0, False: 30.0k]
  ------------------
 1215|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1216|      0|		key_ref = 0x01;
 1217|      0|		break;
 1218|    680|	case READ_PIN2:
  ------------------
  |  Branch (1218:2): [True: 680, False: 29.3k]
  ------------------
 1219|    680|		method = SC_AC_CHV;
  ------------------
  |  |  151|    680|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1220|    680|		key_ref = 0x02;
 1221|    680|		break;
 1222|    680|	case READ_PIN3:
  ------------------
  |  Branch (1222:2): [True: 680, False: 29.3k]
  ------------------
 1223|    680|		method = SC_AC_CHV;
  ------------------
  |  |  151|    680|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1224|    680|		key_ref = 0x03;
 1225|    680|		break;
 1226|  30.0k|	}
 1227|       |
 1228|  30.0k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  60.0k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  26.7k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1228:6): [True: 3.26k, False: 26.7k]
  |  Branch (1228:30): [True: 0, False: 26.7k]
  ------------------
 1229|  3.26k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  3.26k|#define SC_AC_OP_READ			22
  ------------------
 1230|  3.26k|	}
 1231|  30.0k|}
card-openpgp.c:pgp_match_card:
  326|  3.56k|{
  327|  3.56k|	int i;
  328|       |
  329|  3.56k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.56k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.56k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.56k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.56k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.56k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.56k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.56k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 232, False: 3.33k]
  ------------------
  333|    232|		card->name = pgp_atrs[i].name;
  334|    232|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  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: 0, False: 232]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    232|	} else { \
  |  |  |  |  159|    232|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    232|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    232|	} \
  |  |  |  |  162|    232|	return _ret; \
  |  |  |  |  163|    232|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|    232|	}
  336|  3.33k|	else {
  337|  3.33k|		sc_path_t	partial_aid;
  338|  3.33k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.33k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.33k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.33k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.33k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.33k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.33k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 478, False: 2.85k]
  ------------------
  346|    478|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    478|			card->name = default_cardname;
  348|       |
  349|    478|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 477, False: 1]
  ------------------
  350|    477|				(void) get_full_pgp_aid(card, file);
  351|    478|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 36, False: 442]
  ------------------
  352|     36|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     36|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     36|				switch (major) {
  355|      4|					case 1:
  ------------------
  |  Branch (355:6): [True: 4, False: 32]
  ------------------
  356|      4|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      4|						card->name = default_cardname_v1;
  358|      4|						break;
  359|      4|					case 2:
  ------------------
  |  Branch (359:6): [True: 4, False: 32]
  ------------------
  360|      4|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|      4|						card->name = default_cardname_v2;
  362|      4|						break;
  363|     18|					case 3:
  ------------------
  |  Branch (363:6): [True: 18, False: 18]
  ------------------
  364|     18|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|     18|						card->name = default_cardname_v3;
  366|     18|						break;
  367|     10|					default:
  ------------------
  |  Branch (367:6): [True: 10, False: 26]
  ------------------
  368|     10|						break;
  369|     36|				}
  370|     36|			}
  371|    478|			sc_file_free(file);
  372|    478|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    478|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    478|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    478|	int _ret = r; \
  |  |  |  |  155|    478|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 478]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    478|	} else { \
  |  |  |  |  159|    478|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    478|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    478|	} \
  |  |  |  |  162|    478|	return _ret; \
  |  |  |  |  163|    478|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    478|		}
  374|  3.33k|	}
  375|  2.85k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.85k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.85k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.85k|	int _ret = r; \
  |  |  |  |  155|  2.85k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.85k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.85k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.85k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.85k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.85k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.85k|	return _ret; \
  |  |  |  |  163|  2.85k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.85k|}
card-openpgp.c:get_full_pgp_aid:
  307|  1.16k|{
  308|  1.16k|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.16k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|  1.16k|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 1.16k, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|  1.16k|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|  1.16k|		file->namelen = MAX(r, 0);
  ------------------
  |  |   66|  1.16k|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (66:20): [True: 689, False: 473]
  |  |  ------------------
  ------------------
  314|  1.16k|	}
  315|       |
  316|  1.16k|	return r;
  317|  1.16k|}
card-openpgp.c:pgp_init:
  409|    710|{
  410|    710|	struct pgp_priv_data *priv;
  411|    710|	sc_path_t	path;
  412|    710|	sc_file_t	*file = NULL;
  413|    710|	int		r, i;
  414|       |
  415|    710|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    710|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    710|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    710|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    710|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 710]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|       |
  417|    710|	priv = calloc (1, sizeof *priv);
  418|    710|	if (!priv)
  ------------------
  |  Branch (418:6): [True: 0, False: 710]
  ------------------
  419|    710|		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|    710|	card->drv_data = priv;
  421|       |
  422|    710|	card->cla = 0x00;
  423|       |
  424|       |	/* select application "OpenPGP" */
  425|    710|	sc_format_path("D276:0001:2401", &path);
  426|    710|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    710|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  427|    710|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (427:6): [True: 23, False: 687]
  ------------------
  428|     23|		sc_file_free(file);
  429|     23|		pgp_finish(card);
  430|     23|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|     23|	}
  432|       |
  433|       |	/* defensive programming check */
  434|    687|	if (!file)   {
  ------------------
  |  Branch (434:6): [True: 0, False: 687]
  ------------------
  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|    687|	if (file->namelen != 16) {
  ------------------
  |  Branch (439:6): [True: 685, False: 2]
  ------------------
  440|       |		/* explicitly get the full aid */
  441|    685|		r = get_full_pgp_aid(card, file);
  442|    685|		if (r < 0) {
  ------------------
  |  Branch (442:7): [True: 7, False: 678]
  ------------------
  443|      7|			sc_file_free(file);
  444|      7|			pgp_finish(card);
  445|      7|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  446|      7|		}
  447|    685|	}
  448|       |
  449|       |	/* read information from AID */
  450|    680|	if (file->namelen == 16) {
  ------------------
  |  Branch (450:6): [True: 382, False: 298]
  ------------------
  451|    382|		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|    382|		priv->bcd_version = bebytes2ushort(file->name + 6);
  455|    382|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    382|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  456|    382|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    382|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  457|       |
  458|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  459|    382|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (459:7): [True: 1, False: 381]
  ------------------
  460|    381|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (460:7): [True: 1, False: 380]
  ------------------
  461|    380|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (461:7): [True: 1, False: 379]
  ------------------
  462|      3|			snprintf(card_name, sizeof(card_name),
  463|      3|				 "OpenPGP card v%u.%u (%04X %08lX)",
  464|      3|				 card->version.hw_major, card->version.hw_minor,
  465|      3|				 bebytes2ushort(file->name + 8),
  466|      3|				 bebytes2ulong(file->name + 10));
  467|      3|		}
  468|    379|		else if (card->name != NULL) {
  ------------------
  |  Branch (468:12): [True: 379, False: 0]
  ------------------
  469|       |			/* for other cards, append serial number to the card name */
  470|    379|			snprintf(card_name, sizeof(card_name),
  471|    379|				 "%s (%04X %08lX)",
  472|    379|				 card->name,
  473|    379|				 bebytes2ushort(file->name + 8),
  474|    379|				 bebytes2ulong(file->name + 10));
  475|    379|		}
  476|    382|		card->name = card_name;
  477|       |
  478|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  479|    382|		memcpy(card->serialnr.value, file->name + 8, 6);
  480|    382|		card->serialnr.len = 6;
  481|    382|	} else {
  482|       |		/* set detailed card version */
  483|    298|		switch (card->type) {
  484|     16|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (484:4): [True: 16, False: 282]
  ------------------
  485|     16|				priv->bcd_version = OPENPGP_CARD_3_0;
  486|     16|				break;
  487|    193|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (487:4): [True: 193, False: 105]
  ------------------
  488|    195|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (488:4): [True: 2, False: 296]
  ------------------
  489|    195|				priv->bcd_version = OPENPGP_CARD_2_0;
  490|    195|				break;
  491|     87|			default:
  ------------------
  |  Branch (491:4): [True: 87, False: 211]
  ------------------
  492|     87|				priv->bcd_version = OPENPGP_CARD_1_1;
  493|     87|				break;
  494|    298|		}
  495|    298|	}
  496|       |
  497|       |	/* set pointer to correct list of card objects */
  498|    680|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (498:22): [True: 111, False: 569]
  ------------------
  499|    680|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (499:8): [True: 197, False: 372]
  ------------------
  500|    569|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (500:8): [True: 9, False: 363]
  ------------------
  501|    372|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (501:8): [True: 20, False: 343]
  ------------------
  502|    363|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (502:8): [True: 1, False: 342]
  ------------------
  503|    343|			  :					     pgp34_objects;
  504|       |
  505|       |	/* With gnuk, we use different curves */
  506|    680|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (506:6): [True: 224, False: 456]
  ------------------
  507|    224|		priv->ec_curves = ec_curves_gnuk;
  508|    456|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (508:13): [True: 319, False: 137]
  ------------------
  509|    319|		priv->ec_curves = ec_curves_openpgp34;
  510|    319|	} else {
  511|    137|		priv->ec_curves = ec_curves_openpgp;
  512|    137|	}
  513|       |
  514|       |	/* change file path to MF for reuse in MF */
  515|    680|	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|    680|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  520|    680|	if (!priv->mf) {
  ------------------
  |  Branch (520:6): [True: 0, False: 680]
  ------------------
  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|    680|	priv->current = priv->mf;
  528|       |
  529|    680|	r = populate_blobs_to_mf(card, priv);
  530|    680|	if (r < 0) {
  ------------------
  |  Branch (530:6): [True: 0, False: 680]
  ------------------
  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|    680|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (536:6): [True: 39, False: 641]
  ------------------
  537|     39|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     39|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     39|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     39|	int _ret = r; \
  |  |  |  |  155|     39|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     39|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     39|	return _ret; \
  |  |  |  |  163|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  538|     39|	}
  539|       |
  540|       |	/* if algorithm attributes can be changed,
  541|       |	 * add supported algorithms based on specification for pkcs15-init */
  542|    641|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (542:6): [True: 82, False: 559]
  ------------------
  543|     82|		unsigned long flags_rsa, flags_ecc, ext_flags;
  544|     82|		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|     82|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  111|     82|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|     82|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|     82|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  548|     82|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  133|     82|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  549|     82|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     82|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     82|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|     82|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  551|     82|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|     82|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  552|     82|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|     82|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|     82|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  553|     82|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     82|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|     82|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  201|     82|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  555|       |
  556|     82|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  188|     82|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  557|     82|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     82|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  558|       |		/* xeddsa may allow signing at some time */
  559|     82|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  173|     82|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  560|     82|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|     82|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  561|       |
  562|     82|		switch (card->type) {
  563|      0|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (563:4): [True: 0, False: 82]
  ------------------
  564|       |				/* RSA 1024 was removed for v3+ */
  565|      0|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  566|      0|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  567|       |				/* fallthrough */
  568|     47|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (568:4): [True: 47, False: 35]
  ------------------
  569|     47|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  570|    329|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (570:15): [True: 282, False: 47]
  ------------------
  571|    282|				{
  572|    282|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   70|    282|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (572:10): [True: 94, False: 188]
  ------------------
  573|     94|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  574|     94|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  575|    188|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    188|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (575:15): [True: 94, False: 94]
  ------------------
  576|     94|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  577|     94|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  578|     94|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|     94|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (578:15): [True: 94, False: 0]
  ------------------
  579|     94|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  580|     94|								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|    282|				}
  584|     47|				break;
  585|     47|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (585:4): [True: 0, False: 82]
  ------------------
  586|     35|			default:
  ------------------
  |  Branch (586:4): [True: 35, False: 47]
  ------------------
  587|     35|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  588|     35|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  589|     35|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  590|     35|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  591|     35|				break;
  592|     82|		}
  593|     82|	}
  594|       |
  595|    641|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    641|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    641|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    641|	int _ret = r; \
  |  |  |  |  155|    641|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 641, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    641|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 641]
  |  |  |  |  ------------------
  |  |  |  |  157|    641|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    641|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    641|	return _ret; \
  |  |  |  |  163|    641|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|    641|}
card-openpgp.c:pgp_get_blob:
 1480|  10.5k|{
 1481|  10.5k|	pgp_blob_t		*child;
 1482|  10.5k|	int			r;
 1483|       |
 1484|  10.5k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1484:6): [True: 1.00k, False: 9.56k]
  ------------------
 1485|  1.00k|		return r;
 1486|       |
 1487|  68.7k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1487:28): [True: 67.0k, False: 1.70k]
  ------------------
 1488|  67.0k|		if (child->id == id) {
  ------------------
  |  Branch (1488:7): [True: 7.86k, False: 59.2k]
  ------------------
 1489|  7.86k|			(void) pgp_read_blob(card, child);
 1490|  7.86k|			*ret = child;
 1491|  7.86k|			return SC_SUCCESS;
  ------------------
  |  |   28|  7.86k|#define SC_SUCCESS				0
  ------------------
 1492|  7.86k|		}
 1493|  67.0k|	}
 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|  1.70k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  3.41k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|    466|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|    466|#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: 233, False: 1.47k]
  |  Branch (1500:36): [True: 0, False: 233]
  |  Branch (1500:53): [True: 233, False: 0]
  |  Branch (1500:75): [True: 0, False: 0]
  ------------------
 1501|    233|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   71|    233|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1502|    233|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1503|    233|		if (child) {
  ------------------
  |  Branch (1503:7): [True: 233, False: 0]
  ------------------
 1504|    233|			pgp_set_blob(child, NULL, 0);
 1505|    233|			*ret = child;
 1506|    233|			return SC_SUCCESS;
  ------------------
  |  |   28|    233|#define SC_SUCCESS				0
  ------------------
 1507|    233|		}
 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|    233|			       "Not enough memory to create blob for DO %X",
 1511|    233|			       id);
 1512|    233|	}
 1513|       |
 1514|  1.47k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.47k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1515|  1.70k|}
card-openpgp.c:pgp_enumerate_blob:
 1398|  10.9k|{
 1399|  10.9k|	const u8	*in;
 1400|  10.9k|	int		r;
 1401|  10.9k|	sc_file_t	*file = NULL;
 1402|       |
 1403|  10.9k|	if (blob->files != NULL)
  ------------------
  |  Branch (1403:6): [True: 8.90k, False: 2.00k]
  ------------------
 1404|  8.90k|		return SC_SUCCESS;
  ------------------
  |  |   28|  8.90k|#define SC_SUCCESS				0
  ------------------
 1405|       |
 1406|  2.00k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1406:6): [True: 835, False: 1.16k]
  ------------------
 1407|    835|		return r;
 1408|       |
 1409|  1.16k|	in = blob->data;
 1410|       |
 1411|  30.8k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1411:9): [True: 30.1k, False: 689]
  ------------------
 1412|  30.1k|		unsigned int	cla, tag, tmptag;
 1413|  30.1k|		size_t		len;
 1414|  30.1k|		const u8	*data = in;
 1415|  30.1k|		pgp_blob_t	*new;
 1416|       |
 1417|  30.1k|		if (!in)
  ------------------
  |  Branch (1417:7): [True: 0, False: 30.1k]
  ------------------
 1418|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1419|       |
 1420|  30.1k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1421|  30.1k|					&cla, &tag, &len);
 1422|  30.1k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  30.1k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1422:7): [True: 184, False: 29.9k]
  ------------------
 1423|    184|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1424|    184|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    184|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1425|    184|		}
 1426|       |		/* Check for unknown error, or empty data */
 1427|  29.9k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    169|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1427:8): [True: 169, False: 29.8k]
  |  Branch (1427:19): [True: 0, False: 169]
  ------------------
 1428|  29.9k|		    (data == NULL)) {
  ------------------
  |  Branch (1428:7): [True: 136, False: 29.8k]
  ------------------
 1429|    136|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    136|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1430|    136|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    136|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1431|    136|		}
 1432|       |
 1433|       |		/* undo ASN1's split of tag & class */
 1434|  30.9k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1434:22): [True: 1.05k, False: 29.8k]
  ------------------
 1435|  1.05k|			cla <<= 8;
 1436|  1.05k|		}
 1437|  29.8k|		tag |= cla;
 1438|       |		/* Check for length mismatch */
 1439|  29.8k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  29.8k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1439:7): [True: 169, False: 29.6k]
  ------------------
 1440|  29.6k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1440:7): [True: 0, False: 29.6k]
  ------------------
 1441|       |			// Check if it is not known Yubikey 5 issue
 1442|    169|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1442:8): [True: 146, False: 23]
  |  Branch (1442:29): [True: 13, False: 10]
  ------------------
 1443|    159|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   71|    159|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1444|    159|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    159|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1445|    159|			}
 1446|    169|		}
 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.7k|		if (tag == blob->id) {
  ------------------
  |  Branch (1451:7): [True: 294, False: 29.4k]
  ------------------
 1452|    294|			in = data;
 1453|    294|			continue;
 1454|    294|		}
 1455|       |
 1456|       |		/* create fake file system hierarchy by
 1457|       |		 * using constructed DOs as DF */
 1458|  29.4k|		file = sc_file_new();
 1459|  29.4k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1459:7): [True: 0, False: 29.4k]
  ------------------
 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.4k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  29.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1463:7): [True: 0, False: 29.4k]
  ------------------
 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.4k|		in = data + len;
 1468|  29.4k|	}
 1469|       |
 1470|    689|	return SC_SUCCESS;
  ------------------
  |  |   28|    689|#define SC_SUCCESS				0
  ------------------
 1471|  1.16k|}
card-openpgp.c:pgp_set_blob:
 1140|  30.8k|{
 1141|  30.8k|	if (blob->data)
  ------------------
  |  Branch (1141:6): [True: 0, False: 30.8k]
  ------------------
 1142|      0|		free(blob->data);
 1143|  30.8k|	blob->data = NULL;
 1144|  30.8k|	blob->len    = 0;
 1145|  30.8k|	blob->status = 0;
 1146|       |
 1147|  30.8k|	if (len > 0) {
  ------------------
  |  Branch (1147:6): [True: 18.0k, False: 12.7k]
  ------------------
 1148|  18.0k|		void *tmp = calloc(1, len);
 1149|       |
 1150|  18.0k|		if (tmp == NULL)
  ------------------
  |  Branch (1150:7): [True: 0, False: 18.0k]
  ------------------
 1151|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1152|       |
 1153|  18.0k|		blob->data = tmp;
 1154|  18.0k|		blob->len  = (unsigned int)len;
 1155|  18.0k|		if (data != NULL)
  ------------------
  |  Branch (1155:7): [True: 18.0k, False: 0]
  ------------------
 1156|  18.0k|			memcpy(blob->data, data, len);
 1157|  18.0k|	}
 1158|       |
 1159|  30.8k|	if (blob->file)
  ------------------
  |  Branch (1159:6): [True: 30.8k, False: 0]
  ------------------
 1160|  30.8k|		blob->file->size = len;
 1161|       |
 1162|  30.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  30.8k|#define SC_SUCCESS				0
  ------------------
 1163|  30.8k|}
card-openpgp.c:pgp_read_blob:
 1348|  14.6k|{
 1349|  14.6k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  14.6k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1350|       |
 1351|  14.6k|	if (blob->data != NULL)
  ------------------
  |  Branch (1351:6): [True: 10.8k, False: 3.79k]
  ------------------
 1352|  10.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  10.8k|#define SC_SUCCESS				0
  ------------------
 1353|  3.79k|	if (blob->info == NULL)
  ------------------
  |  Branch (1353:6): [True: 0, False: 3.79k]
  ------------------
 1354|      0|		return blob->status;
 1355|       |
 1356|  3.79k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1356:6): [True: 3.77k, False: 27]
  ------------------
 1357|  3.77k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1358|  3.77k|		size_t	buf_len = sizeof(buffer);
 1359|  3.77k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.77k|#define SC_SUCCESS				0
  ------------------
 1360|       |
 1361|       |		/* buffer length for certificate */
 1362|  3.77k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  7.54k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1362:7): [True: 140, False: 3.63k]
  |  Branch (1362:30): [True: 51, False: 89]
  ------------------
 1363|     51|			buf_len = MIN(priv->max_cert_size, sizeof(buffer));
  ------------------
  |  |   69|     51|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 38, False: 13]
  |  |  ------------------
  ------------------
 1364|     51|		}
 1365|       |
 1366|       |		/* buffer length for Gnuk pubkey */
 1367|  3.77k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1367:7): [True: 1.15k, False: 2.62k]
  ------------------
 1368|  1.15k|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|  2.30k|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1368:8): [True: 0, False: 1.15k]
  ------------------
 1369|  1.15k|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|  2.30k|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1369:8): [True: 0, False: 1.15k]
  ------------------
 1370|  1.15k|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|  2.30k|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1370:8): [True: 0, False: 1.15k]
  ------------------
 1371|  1.15k|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|  2.30k|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1371:8): [True: 0, False: 1.15k]
  ------------------
 1372|  1.15k|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|  2.30k|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1372:8): [True: 0, False: 1.15k]
  ------------------
 1373|  1.15k|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|  1.15k|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1373:8): [True: 0, False: 1.15k]
  ------------------
 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|  3.77k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1378|       |
 1379|  3.77k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1379:7): [True: 2.55k, False: 1.21k]
  ------------------
 1380|  2.55k|			blob->status = r;
 1381|  2.55k|			return r;
 1382|  2.55k|		}
 1383|       |
 1384|  1.21k|		return pgp_set_blob(blob, buffer, r);
 1385|  3.77k|	}
 1386|     27|	else {		/* un-readable DO or part of a constructed DO */
 1387|     27|		return SC_SUCCESS;
  ------------------
  |  |   28|     27|#define SC_SUCCESS				0
  ------------------
 1388|     27|	}
 1389|  3.79k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  634|  11.5k|{
  635|  11.5k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  11.5k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  636|  11.5k|	struct sc_object_id oid;
  637|  11.5k|	unsigned int j, r;
  638|       |
  639|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |
  641|  11.5k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (641:6): [True: 0, False: 11.5k]
  |  Branch (641:22): [True: 1.23k, False: 10.3k]
  |  Branch (641:44): [True: 0, False: 10.3k]
  ------------------
  642|  10.3k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (642:6): [True: 0, False: 10.3k]
  |  Branch (642:27): [True: 0, False: 10.3k]
  |  Branch (642:48): [True: 0, False: 10.3k]
  ------------------
  643|  1.23k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  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|  1.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.23k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  644|  1.23k|	}
  645|       |
  646|  10.3k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  647|       |
  648|  10.3k|	switch (blob->data[0]) {
  649|  2.59k|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|  2.59k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (649:3): [True: 2.59k, False: 7.76k]
  ------------------
  650|  2.59k|			if (blob->len < 5) {
  ------------------
  |  Branch (650:8): [True: 1.29k, False: 1.29k]
  ------------------
  651|  1.29k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  1.29k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.29k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.29k|	int _ret = r; \
  |  |  |  |  155|  1.29k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.29k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.29k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.29k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.29k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  652|  1.29k|			}
  653|       |
  654|  1.29k|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  877|  1.29k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  655|  1.29k|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  656|  1.29k|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  657|       |
  658|  1.29k|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (658:32): [True: 269, False: 1.02k]
  ------------------
  659|  1.29k|						  ? blob->data[5]
  660|  1.29k|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  882|  2.31k|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  661|  1.29k|			break;
  662|  2.58k|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|  2.58k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (662:3): [True: 2.58k, False: 7.76k]
  ------------------
  663|  4.91k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|  4.91k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (663:3): [True: 2.32k, False: 8.02k]
  ------------------
  664|  5.76k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|  5.76k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (664:3): [True: 848, False: 9.50k]
  ------------------
  665|       |
  666|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  667|  5.76k|			key_info->algorithm = blob->data[0];
  668|       |
  669|       |			/* last byte is set to 0xFF if pubkey import is supported */
  670|  5.76k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  888|  5.76k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (670:8): [True: 1.27k, False: 4.48k]
  ------------------
  671|  1.27k|				if (blob->len < 3)
  ------------------
  |  Branch (671:9): [True: 532, False: 739]
  ------------------
  672|    532|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    532|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  673|    739|				key_info->u.ec.oidv_len = blob->len - 2;
  674|    739|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  888|    739|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  675|    739|			}
  676|  4.48k|			else {
  677|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  678|       |				 * it is not part of OID */
  679|  4.48k|				if (blob->len < 2)
  ------------------
  |  Branch (679:9): [True: 1.44k, False: 3.04k]
  ------------------
  680|  1.44k|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|  1.44k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  681|  3.04k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  887|  3.04k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (681:9): [True: 699, False: 2.34k]
  ------------------
  682|    699|					key_info->u.ec.oidv_len = blob->len - 2;
  683|  2.34k|				else
  684|  2.34k|					key_info->u.ec.oidv_len = blob->len - 1;
  685|  3.04k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  887|  3.04k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  686|  3.04k|			}
  687|       |
  688|       |			/* Create copy of oid from blob */
  689|  3.78k|			sc_init_oid(&oid);
  690|  3.78k|			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.78k|			if (r > 0){
  ------------------
  |  Branch (693:8): [True: 2.72k, False: 1.05k]
  ------------------
  694|  2.72k|				return r;
  695|  2.72k|			}
  696|       |			/* compare with list of supported ec_curves */
  697|  14.5k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (697:16): [True: 13.4k, False: 1.05k]
  ------------------
  698|  13.4k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (698:9): [True: 0, False: 13.4k]
  ------------------
  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.4k|			}
  706|       |			/* We did not match the OID */
  707|  1.05k|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (707:8): [True: 1.05k, False: 0]
  ------------------
  708|  1.05k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  1.05k|			}
  710|      0|			break;
  711|  2.00k|		default:
  ------------------
  |  Branch (711:3): [True: 2.00k, False: 8.35k]
  ------------------
  712|  2.00k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  713|  10.3k|	}
  714|       |
  715|  1.29k|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|  1.29k|}
card-openpgp.c:pgp_get_card_features:
  909|    680|{
  910|    680|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    680|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  911|    680|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  912|    680|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  913|    680|	unsigned int i;
  914|    680|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  915|    680|	int handled_algos = 0;
  916|       |
  917|    680|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    680|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    680|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    680|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    680|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 680]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  918|       |
  919|       |	/* parse card capabilities from historical bytes in ATR */
  920|    680|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (920:6): [True: 372, False: 308]
  ------------------
  921|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  922|    372|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (922:11): [True: 330, False: 42]
  ------------------
  923|    306|			case 0x00:
  ------------------
  |  Branch (923:4): [True: 306, False: 66]
  ------------------
  924|    306|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (924:9): [True: 264, False: 42]
  ------------------
  925|    264|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  926|    264|				}
  927|    306|				break;
  928|      6|			case 0x80:
  ------------------
  |  Branch (928:4): [True: 6, False: 366]
  ------------------
  929|      6|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (929:9): [True: 5, False: 1]
  ------------------
  930|      5|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  931|      5|				}
  932|      6|				break;
  933|     18|			case 0x10:
  ------------------
  |  Branch (933:4): [True: 18, False: 354]
  ------------------
  934|     18|				if (hist_bytes_len > 2) {
  ------------------
  |  Branch (934:9): [True: 16, False: 2]
  ------------------
  935|     16|					pgp_parse_hist_bytes(card, hist_bytes+2, hist_bytes_len-2);
  936|     16|				}
  937|     18|				break;
  938|    372|		}
  939|    372|	}
  940|       |
  941|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  942|    680|	priv->ext_caps &= ~EXT_CAP_LCS;
  943|       |
  944|    680|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (944:6): [True: 569, False: 111]
  ------------------
  945|       |		/* get card capabilities from "historical bytes" DO */
  946|    569|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (946:7): [True: 569, False: 0]
  ------------------
  947|    569|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (947:7): [True: 81, False: 488]
  |  Branch (947:31): [True: 28, False: 53]
  ------------------
  948|       |
  949|     28|			if (blob->len > 4) {
  ------------------
  |  Branch (949:8): [True: 26, False: 2]
  ------------------
  950|     26|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  951|     26|			}
  952|       |
  953|       |			/* get card status from historical bytes status indicator */
  954|     28|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (954:8): [True: 28, False: 0]
  |  Branch (954:35): [True: 26, False: 2]
  ------------------
  955|     26|				priv->state = blob->data[blob->len-3];
  956|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  957|     26|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (957:9): [True: 20, False: 6]
  ------------------
  958|     20|					priv->ext_caps |= EXT_CAP_LCS;
  959|     26|			}
  960|     28|		}
  961|    569|	}
  962|       |
  963|    680|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (963:6): [True: 343, False: 337]
  ------------------
  964|    343|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    343|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  965|    343|	}
  966|       |
  967|    680|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (967:6): [True: 342, False: 338]
  ------------------
  968|       |		/* Parse supported algorithms from Algorithm Information DO
  969|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  970|    342|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (970:7): [True: 342, False: 0]
  ------------------
  971|    342|			pgp_blob_t *child;
  972|    342|			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|  19.6k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (975:32): [True: 19.3k, False: 342]
  ------------------
  976|  19.3k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (976:9): [True: 5.75k, False: 13.5k]
  |  Branch (976:33): [True: 2.53k, False: 11.0k]
  ------------------
  977|  8.29k|					continue;
  978|  11.0k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  979|  11.0k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (979:9): [True: 1.11k, False: 9.91k]
  ------------------
  980|  1.11k|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  981|  11.0k|			}
  982|    342|		}
  983|    342|	}
  984|       |
  985|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  986|    680|	priv->max_specialDO_size = 254;
  987|       |
  988|    680|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (988:6): [True: 680, False: 0]
  ------------------
  989|    680|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (989:6): [True: 226, False: 454]
  ------------------
  990|       |
  991|       |		/* get "extended capabilities" DO */
  992|    226|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (992:7): [True: 99, False: 127]
  ------------------
  993|     99|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (993:7): [True: 98, False: 1]
  |  Branch (993:31): [True: 98, False: 0]
  ------------------
  994|     98|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (994:8): [True: 63, False: 35]
  |  Branch (994:34): [True: 12, False: 51]
  ------------------
  995|     12|				priv->ext_caps |= EXT_CAP_KDF_DO;
  996|     12|			}
  997|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  998|     98|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (998:8): [True: 86, False: 12]
  ------------------
  999|     86|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (999:6): [True: 82, False: 4]
  ------------------
 1000|     82|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
 1001|       |			/* bit 0x08 in first byte means "support for private use DOs" */
 1002|     98|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (1002:8): [True: 35, False: 63]
  ------------------
 1003|     35|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1004|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1005|     98|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1005:8): [True: 4, False: 94]
  ------------------
 1006|      4|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1007|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1008|     98|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1008:8): [True: 90, False: 8]
  ------------------
 1009|     90|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1010|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1011|     98|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1011:8): [True: 87, False: 11]
  ------------------
 1012|     87|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|     87|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1013|     87|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1014|     87|			}
 1015|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1016|     98|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1016:8): [True: 75, False: 23]
  ------------------
 1017|     75|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1017:6): [True: 71, False: 4]
  ------------------
 1018|     71|				priv->ext_caps |= EXT_CAP_SM;
 1019|       |
 1020|     98|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1020:8): [True: 94, False: 4]
  |  Branch (1020:51): [True: 92, False: 2]
  ------------------
 1021|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1022|     92|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1023|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1024|     92|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1025|       |
 1026|     92|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1026:9): [True: 52, False: 40]
  ------------------
 1027|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1028|     52|					priv->sm_algo = blob->data[1];
 1029|     52|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1029:10): [True: 2, False: 50]
  |  Branch (1029:45): [True: 1, False: 1]
  ------------------
 1030|      1|						priv->sm_algo = SM_ALGO_3DES;
 1031|       |
 1032|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1033|     52|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1034|     52|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1035|     52|				}
 1036|     40|				else {
 1037|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1038|     40|					priv->sm_algo = blob->data[1];
 1039|     40|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1039:10): [True: 8, False: 32]
  |  Branch (1039:45): [True: 5, False: 3]
  ------------------
 1040|      5|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1041|       |
 1042|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1043|     40|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1044|     40|				}
 1045|     92|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1045:9): [True: 38, False: 54]
  |  Branch (1045:50): [True: 38, False: 0]
  ------------------
 1046|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1047|     38|					if (blob->data[9])
  ------------------
  |  Branch (1047:10): [True: 32, False: 6]
  ------------------
 1048|     32|						priv->ext_caps |= EXT_CAP_MSE;
 1049|     38|				}
 1050|     92|			}
 1051|     98|		}
 1052|       |
 1053|       |		/* get max. PIN length from "CHV status bytes" DO */
 1054|    226|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1054:7): [True: 205, False: 21]
  ------------------
 1055|    205|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1055:4): [True: 204, False: 1]
  |  Branch (1055:28): [True: 203, False: 1]
  ------------------
 1056|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1057|    203|			card->max_pin_len = blob->data[1];
 1058|    203|		}
 1059|       |
 1060|    226|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1060:7): [True: 83, False: 143]
  ------------------
 1061|       |			/* v3.0+: get length info from "extended length information" DO */
 1062|     83|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1062:8): [True: 0, False: 83]
  ------------------
 1063|      0|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1063:5): [True: 0, False: 0]
  |  Branch (1063:29): [True: 0, False: 0]
  ------------------
 1064|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1065|      0|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1066|      0|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1067|      0|			}
 1068|     83|		}
 1069|       |
 1070|    226|#ifdef ENABLE_OPENSSL
 1071|    226|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1071:7): [True: 12, False: 214]
  ------------------
 1072|     12|			int r = pgp_decode_kdf_do(card, priv);
 1073|     12|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  |  Branch (1073:8): [True: 11, False: 1]
  ------------------
 1074|     11|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   71|     11|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1075|     11|			}
 1076|     12|		}
 1077|    226|#endif /* ENABLE_OPENSSL */
 1078|       |
 1079|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1080|    226|		if (handled_algos) {
  ------------------
  |  Branch (1080:7): [True: 1, False: 225]
  ------------------
 1081|      1|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1082|      1|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  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: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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|	} 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|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1083|      1|		}
 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|    900|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1091:20): [True: 675, False: 225]
  ------------------
 1092|    675|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1093|       |
 1094|    675|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1095|       |
 1096|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1097|    675|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1097:8): [True: 560, False: 115]
  ------------------
 1098|    560|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1098:8): [True: 178, False: 382]
  ------------------
 1099|    178|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1099:9): [True: 0, False: 178]
  ------------------
 1100|    178|					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|    178|			}
 1102|    675|		}
 1103|       |
 1104|    225|	}
 1105|       |
 1106|    679|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    679|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    679|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    679|	int _ret = r; \
  |  |  |  |  155|    679|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 641, False: 38]
  |  |  |  |  ------------------
  |  |  |  |  156|    641|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 641]
  |  |  |  |  ------------------
  |  |  |  |  157|    641|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    641|	} else { \
  |  |  |  |  159|     38|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     38|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     38|	} \
  |  |  |  |  162|    679|	return _ret; \
  |  |  |  |  163|    679|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|    679|}
card-openpgp.c:pgp_parse_hist_bytes:
  604|    311|{
  605|    311|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    311|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  606|    311|	const u8 *ptr;
  607|       |
  608|       |	/* IS07816-4 hist bytes: 3rd function table */
  609|    311|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (609:6): [True: 258, False: 53]
  ------------------
  610|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  611|    258|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (611:7): [True: 17, False: 241]
  ------------------
  612|     17|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  547|     17|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  613|     17|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  614|     17|		}
  615|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  616|    258|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (616:7): [True: 240, False: 18]
  ------------------
  617|    240|			priv->ext_caps |= EXT_CAP_CHAINING;
  618|    240|		}
  619|    258|	}
  620|       |
  621|    311|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (621:6): [True: 83, False: 228]
  ------------------
  622|     83|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (622:6): [True: 39, False: 44]
  ------------------
  623|       |		// ToDo ...
  624|     39|	}
  625|    311|}
card-openpgp.c:pgp_decode_kdf_do:
  805|     12|{
  806|     12|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  807|     12|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     12|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  808|     12|	pgp_blob_t *kdf_blob;
  809|     12|	const uint8_t *data;
  810|     12|	size_t data_len;
  811|     12|	size_t tag_len;
  812|     12|	const uint8_t *p;
  813|     12|	pgp_blob_t *blob;
  814|       |
  815|     12|	if (!pin_kdf_info) {
  ------------------
  |  Branch (815:6): [True: 0, False: 12]
  ------------------
  816|      0|		return r;
  817|      0|	}
  818|       |
  819|     12|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     12|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  820|     12|	priv->pin_kdf_info = NULL;
  821|     12|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     12|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     12|#define SC_SUCCESS				0
  ------------------
  |  Branch (821:6): [True: 0, False: 12]
  |  Branch (821:73): [True: 2, False: 10]
  ------------------
  822|      2|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  823|      2|		goto out;
  824|      2|	}
  825|       |
  826|     10|	data = kdf_blob->data;
  827|     10|	data_len = kdf_blob->len;
  828|     10|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  829|     10|	if (!p) {
  ------------------
  |  Branch (829:6): [True: 1, False: 9]
  ------------------
  830|      1|		sc_log(card->ctx, "KDF 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__
  |  |  ------------------
  ------------------
  831|      1|		goto out;
  832|      1|	}
  833|      9|	if (tag_len != 1) {
  ------------------
  |  Branch (833:6): [True: 1, False: 8]
  ------------------
  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|      8|	if (*p != 0x3) {
  ------------------
  |  Branch (838:6): [True: 2, False: 6]
  ------------------
  839|      2|		if (*p == 0x0) {
  ------------------
  |  Branch (839:7): [True: 1, False: 1]
  ------------------
  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|      1|		} else {
  843|      1|			sc_log(card->ctx, "Unknown KDF 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__
  |  |  ------------------
  ------------------
  844|      1|		}
  845|      2|		goto out;
  846|      2|	}
  847|       |
  848|      6|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  849|      6|	if (!p) {
  ------------------
  |  Branch (849:6): [True: 1, False: 5]
  ------------------
  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|      5|	if (tag_len != 1) {
  ------------------
  |  Branch (853:6): [True: 1, False: 4]
  ------------------
  854|      1|		sc_log(card->ctx, "Unexpected KDF hash algorithm byte length, expects 1, got %zu", tag_len);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  855|      1|		goto out;
  856|      1|	}
  857|       |
  858|      4|	switch (*p) {
  859|      1|	case 0x08:
  ------------------
  |  Branch (859:2): [True: 1, False: 3]
  ------------------
  860|      1|		pin_kdf_info->hash_algo = "SHA256";
  861|      1|		break;
  862|      2|	case 0x0A:
  ------------------
  |  Branch (862:2): [True: 2, False: 2]
  ------------------
  863|      2|		pin_kdf_info->hash_algo = "SHA512";
  864|      2|		break;
  865|      1|	default:
  ------------------
  |  Branch (865:2): [True: 1, False: 3]
  ------------------
  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|      4|	}
  869|       |
  870|      3|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  871|      3|	if (!p) {
  ------------------
  |  Branch (871:6): [True: 1, False: 2]
  ------------------
  872|      1|		sc_log(card->ctx, "KDF iteration count not found");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  873|      1|		goto out;
  874|      1|	}
  875|      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|     12|out:
  899|     12|	free(pin_kdf_info);
  900|     12|	return r;
  901|      0|}
card-openpgp.c:pgp_finish:
 1115|    710|{
 1116|    710|	if (card != NULL) {
  ------------------
  |  Branch (1116:6): [True: 710, False: 0]
  ------------------
 1117|    710|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    710|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1118|       |
 1119|    710|		if (priv != NULL) {
  ------------------
  |  Branch (1119:7): [True: 710, False: 0]
  ------------------
 1120|       |			/* delete fake file hierarchy */
 1121|    710|			pgp_free_blobs(priv->mf);
 1122|       |
 1123|       |			/* delete kdf do related data if exists */
 1124|    710|			free(priv->pin_kdf_info);
 1125|       |
 1126|       |			/* delete private data */
 1127|    710|			free(priv);
 1128|    710|		}
 1129|    710|		card->drv_data = NULL;
 1130|    710|	}
 1131|    710|	return SC_SUCCESS;
  ------------------
  |  |   28|    710|#define SC_SUCCESS				0
  ------------------
 1132|    710|}
card-openpgp.c:pgp_free_blobs:
 1328|  43.5k|{
 1329|  43.5k|	if (blob) {
  ------------------
  |  Branch (1329:6): [True: 43.4k, False: 30]
  ------------------
 1330|  43.4k|		pgp_blob_t *child = blob->files;
 1331|       |
 1332|  86.2k|		while (child != NULL) {
  ------------------
  |  Branch (1332:10): [True: 42.8k, False: 43.4k]
  ------------------
 1333|  42.8k|			pgp_blob_t *next = child->next;
 1334|       |
 1335|  42.8k|			pgp_free_blobs(child);
 1336|  42.8k|			child = next;
 1337|  42.8k|		}
 1338|  43.4k|		pgp_free_blob(blob);
 1339|  43.4k|	}
 1340|  43.5k|}
card-openpgp.c:pgp_free_blob:
 1303|  43.4k|{
 1304|  43.4k|	if (blob) {
  ------------------
  |  Branch (1304:6): [True: 43.4k, False: 0]
  ------------------
 1305|  43.4k|		if (blob->parent) {
  ------------------
  |  Branch (1305:7): [True: 42.8k, False: 680]
  ------------------
 1306|  42.8k|			pgp_blob_t **p;
 1307|       |
 1308|       |			/* remove blob from list of parent's children */
 1309|  42.8k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1309:35): [True: 42.8k, False: 0]
  |  Branch (1309:49): [True: 0, False: 42.8k]
  ------------------
 1310|      0|				;
 1311|  42.8k|			if (*p == blob)
  ------------------
  |  Branch (1311:8): [True: 42.8k, False: 0]
  ------------------
 1312|  42.8k|				*p = blob->next;
 1313|  42.8k|		}
 1314|       |
 1315|  43.4k|		sc_file_free(blob->file);
 1316|  43.4k|		if (blob->data)
  ------------------
  |  Branch (1316:7): [True: 18.0k, False: 25.4k]
  ------------------
 1317|  18.0k|			free(blob->data);
 1318|  43.4k|		free(blob);
 1319|  43.4k|	}
 1320|  43.4k|}
card-openpgp.c:pgp_select_file:
 1616|  6.03k|{
 1617|  6.03k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  6.03k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1618|  6.03k|	pgp_blob_t	*blob;
 1619|  6.03k|	unsigned int	path_start = 0;
 1620|  6.03k|	unsigned int	n;
 1621|  6.03k|	sc_path_t dummy_path;
 1622|       |
 1623|  6.03k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.03k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.03k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.03k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.03k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1624|       |
 1625|  6.03k|	if (!path)
  ------------------
  |  Branch (1625:6): [True: 0, False: 6.03k]
  ------------------
 1626|  6.03k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1627|       |
 1628|  6.03k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  6.03k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1628:6): [True: 1.01k, False: 5.01k]
  ------------------
 1629|  6.03k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  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|    969|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 969, False: 50]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1630|       |
 1631|  5.01k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1631:6): [True: 0, False: 5.01k]
  |  Branch (1631:23): [True: 0, False: 5.01k]
  ------------------
 1632|  5.01k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1633|  5.01k|				"invalid path length");
 1634|       |
 1635|  5.01k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  10.0k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1635:6): [True: 0, False: 5.01k]
  |  Branch (1635:44): [True: 0, False: 0]
  ------------------
 1636|  5.01k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1637|  5.01k|				"invalid path type");
 1638|       |
 1639|       |	/* Due to pkcs15init implementation, sometimes a file at path "11001101"
 1640|       |	 * need to be written (one use case is when importing key&cert from p12 file).
 1641|       |	 * This file does not exist in OpenPGP but pkcs15 requires that
 1642|       |	 * writing this file must be successful.
 1643|       |	 * So, we pretend that selecting & writing this file is successful.
 1644|       |	 * The "11001101"is defined in sc_pkcs15emu_get_df() function, pkcs15-sync.c file. */
 1645|  5.01k|	sc_format_path("11001101", &dummy_path);
 1646|  5.01k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1646:6): [True: 0, False: 5.01k]
  ------------------
 1647|      0|		if (ret != NULL) {
  ------------------
  |  Branch (1647:7): [True: 0, False: 0]
  ------------------
 1648|      0|			*ret = sc_file_new();
 1649|      0|			if (!*ret)
  ------------------
  |  Branch (1649:8): [True: 0, False: 0]
  ------------------
 1650|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1651|       |			/* One use case of this dummy file is after writing certificate in pkcs15init.
 1652|       |			 * So we set its size to be the same as max certificate size the card supports. */
 1653|      0|			(*ret)->size = priv->max_cert_size;
 1654|      0|		}
 1655|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1656|      0|	}
 1657|       |
 1658|       |	/* ignore explicitly mentioned MF at the path's beginning */
 1659|  5.01k|	path_start = pgp_strip_path(card, path);
 1660|       |
 1661|       |	/* starting with the MF ... */
 1662|  5.01k|	blob = priv->mf;
 1663|       |	/* ... recurse through the tree following the path */
 1664|  10.4k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1664:23): [True: 7.07k, False: 3.34k]
  ------------------
 1665|  7.07k|		unsigned int	id = bebytes2ushort(path->value + n);
 1666|  7.07k|		int		r = pgp_get_blob(card, blob, id, &blob);
 1667|       |
 1668|       |		/* This file ID is referred when importing key&certificate via pkcs15init, like above.
 1669|       |		 * We pretend to successfully find this inexistent file. */
 1670|  7.07k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1670:7): [True: 0, False: 7.07k]
  |  Branch (1670:23): [True: 0, False: 7.07k]
  ------------------
 1671|      0|			if (ret == NULL)
  ------------------
  |  Branch (1671:8): [True: 0, False: 0]
  ------------------
 1672|       |				/* No need to return file */
 1673|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1674|       |
 1675|       |			/* Else, need to return file */
 1676|      0|			*ret = sc_file_new();
 1677|      0|			if (!*ret)
  ------------------
  |  Branch (1677:8): [True: 0, False: 0]
  ------------------
 1678|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|      0|			(*ret)->size = priv->max_cert_size;
 1680|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1681|      0|		}
 1682|       |
 1683|  7.07k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1683:7): [True: 1.67k, False: 5.40k]
  ------------------
 1684|  1.67k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.67k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.67k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.67k|	int _ret = r; \
  |  |  |  |  155|  1.67k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.67k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.67k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.67k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.67k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.67k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.67k|	} else { \
  |  |  |  |  159|      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.67k|	return _ret; \
  |  |  |  |  163|  1.67k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1685|  1.67k|		}
 1686|  7.07k|	}
 1687|       |
 1688|       |	/* success: select file = set "current" pointer to blob found */
 1689|  3.34k|	priv->current = blob;
 1690|       |
 1691|  3.34k|	if (ret) {
  ------------------
  |  Branch (1691:6): [True: 1.86k, False: 1.47k]
  ------------------
 1692|  1.86k|		if (!blob || !blob->file)
  ------------------
  |  Branch (1692:7): [True: 0, False: 1.86k]
  |  Branch (1692:16): [True: 0, False: 1.86k]
  ------------------
 1693|  1.86k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1694|  1.86k|		sc_file_dup(ret, blob->file);
 1695|  1.86k|		if (!*ret)
  ------------------
  |  Branch (1695:7): [True: 0, False: 1.86k]
  ------------------
 1696|  1.86k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1697|  1.86k|	}
 1698|       |
 1699|  3.34k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.34k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.34k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.34k|	int _ret = r; \
  |  |  |  |  155|  3.34k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.34k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.34k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.34k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.34k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.34k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.34k|	return _ret; \
  |  |  |  |  163|  3.34k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1700|  3.34k|}
card-openpgp.c:pgp_strip_path:
 1595|  5.01k|{
 1596|  5.01k|	unsigned int start_point = 0;
 1597|       |	/* start_point will move through the path string */
 1598|  5.01k|	if (!path || path->len < 2)
  ------------------
  |  Branch (1598:6): [True: 0, False: 5.01k]
  |  Branch (1598:15): [True: 0, False: 5.01k]
  ------------------
 1599|      0|		return 0;
 1600|       |
 1601|       |	/* ignore 3F00 (MF) at the beginning */
 1602|  5.01k|	if (memcmp(path->value, "\x3f\x00", 2) == 0)
  ------------------
  |  Branch (1602:6): [True: 2.73k, False: 2.28k]
  ------------------
 1603|  2.73k|		start_point = 2;
 1604|       |	/* strip path of PKCS15-App DF (5015) */
 1605|  5.01k|	if (path->len >= start_point + 2 && memcmp(path->value + start_point, "\x50\x15", 2) == 0)
  ------------------
  |  Branch (1605:6): [True: 4.10k, False: 914]
  |  Branch (1605:38): [True: 1.12k, False: 2.98k]
  ------------------
 1606|  1.12k|		start_point += 2;
 1607|  5.01k|	return start_point;
 1608|  5.01k|}
card-openpgp.c:pgp_read_binary:
 1772|  4.80k|{
 1773|  4.80k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  4.80k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1774|  4.80k|	pgp_blob_t	*blob;
 1775|  4.80k|	int		r;
 1776|       |
 1777|  4.80k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  4.80k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1778|       |
 1779|       |	/* jump to selected file */
 1780|  4.80k|	blob = priv->current;
 1781|       |
 1782|  4.80k|	if (blob == NULL)
  ------------------
  |  Branch (1782:6): [True: 0, False: 4.80k]
  ------------------
 1783|  4.80k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1784|       |
 1785|  4.80k|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|  4.80k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1785:6): [True: 0, False: 4.80k]
  ------------------
 1786|  4.80k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1787|       |
 1788|  4.80k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1788:6): [True: 0, False: 4.80k]
  ------------------
 1789|  4.80k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1790|       |
 1791|  4.80k|	if (idx > blob->len)
  ------------------
  |  Branch (1791:6): [True: 0, False: 4.80k]
  ------------------
 1792|  4.80k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1793|       |
 1794|  4.80k|	if (idx + count > blob->len)
  ------------------
  |  Branch (1794:6): [True: 0, False: 4.80k]
  ------------------
 1795|      0|		count = blob->len - idx;
 1796|  4.80k|	memcpy(buf, blob->data + idx, count);
 1797|       |
 1798|  4.80k|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  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: 0, False: 4.80k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.80k|	} else { \
  |  |  |  |  159|  4.80k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  4.80k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  4.80k|	} \
  |  |  |  |  162|  4.80k|	return _ret; \
  |  |  |  |  163|  4.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1799|  4.80k|}
card-openpgp.c:pgp_pin_cmd:
 2405|    966|{
 2406|    966|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    966|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2407|    966|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2408|       |
 2409|    966|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    966|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    966|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    966|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    966|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 966]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2410|       |
 2411|    966|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    966|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2411:6): [True: 0, False: 966]
  ------------------
 2412|    966|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2413|    966|				"invalid PIN type");
 2414|       |
 2415|       |	/* In general, the PIN Reference is extracted from the key-id,
 2416|       |	 * for example, CHV0 -> Ref=0, CHV1 -> Ref=1.
 2417|       |	 * However, in the case of OpenPGP, the PIN Ref to compose APDU
 2418|       |	 * must be 81, 82, 83.
 2419|       |	 * So, if we receive Ref=1, Ref=2, we must convert to 81, 82...
 2420|       |	 * In OpenPGP v1, the PINs are named CHV1, CHV2, CHV3.
 2421|       |	 * In v2, they are named PW1, PW3 (PW1 operates in 2 modes).
 2422|       |	 *
 2423|       |	 * The PIN references (P2 in APDU) for "VERIFY" are the same in both versions:
 2424|       |	 * 81 (CHV1 or PW1), 82 (CHV2 or PW1-mode 2), 83 (CHV3 or PW3),
 2425|       |	 * On the other hand from version 2.0 "CHANGE REFERENCE DATA" and
 2426|       |	 * "RESET RETRY COUNTER" don't support PW1-mode 2 (82) and need this
 2427|       |	 * value changed to PW1 (81).
 2428|       |	 * Both of these commands also differ between card versions in that
 2429|       |	 * v1 cards can use only implicit old PIN or CHV3 test for both commands
 2430|       |	 * whereas v2 can use both implicit (for PW3) and explicit
 2431|       |	 * (for special "Resetting Code") PIN test for "RESET RETRY COUNTER"
 2432|       |	 * and only explicit test for "CHANGE REFERENCE DATA".
 2433|       |	 *
 2434|       |	 * Note that if this function is called from sc_pkcs15_verify_pin() in pkcs15-pin.c,
 2435|       |	 * the Ref is already 81, 82, 83.
 2436|       |	 */
 2437|       |
 2438|       |	/* convert the PIN Reference if needed */
 2439|    966|	data->pin_reference |= 0x80;
 2440|       |
 2441|       |	/* check version-dependent constraints */
 2442|    966|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  416|  1.93k|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  417|    885|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2442:6): [True: 81, False: 885]
  |  Branch (2442:40): [True: 76, False: 809]
  ------------------
 2443|    157|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2443:7): [True: 139, False: 18]
  ------------------
 2444|    139|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2444:8): [True: 52, False: 87]
  ------------------
 2445|     52|				data->pin_reference = 0x81;
 2446|       |
 2447|    139|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|    139|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2447:8): [True: 73, False: 66]
  ------------------
 2448|     73|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2448:9): [True: 0, False: 73]
  ------------------
 2449|      0|				    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2449:9): [True: 0, False: 0]
  ------------------
 2450|     73|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2451|     73|							"v2 cards don't support implicit old PIN for PIN change");
 2452|       |
 2453|     73|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|     73|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2454|     73|			}
 2455|    139|		} else {
 2456|     18|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2456:8): [True: 18, False: 0]
  ------------------
 2457|     18|				sc_log(card->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__
  |  |  ------------------
  ------------------
 2458|     18|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2459|     18|				sc_log(card->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__
  |  |  ------------------
  ------------------
 2460|     18|				       "please make sure that you have verified the relevant PIN first.");
 2461|     18|				data->pin1.len = 0;
 2462|     18|			}
 2463|       |
 2464|     18|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|     18|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2465|     18|		}
 2466|    157|	}
 2467|       |
 2468|    966|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  417|  1.93k|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2468:6): [True: 76, False: 890]
  |  Branch (2468:41): [True: 0, False: 76]
  ------------------
 2469|      0|	    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2469:6): [True: 0, False: 0]
  ------------------
 2470|    966|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2471|    966|				"new PIN must be provided for unblock operation");
 2472|       |
 2473|       |	/* ensure pin_reference is 81, 82, 83 */
 2474|    966|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2474:6): [True: 11, False: 955]
  |  Branch (2474:36): [True: 0, False: 955]
  ------------------
 2475|    966|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2476|    955|				"Invalid key ID; must be 1, 2, or 3");
 2477|       |
 2478|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2479|    955|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  418|  1.91k|#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|    598|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2479:6): [True: 598, False: 357]
  |  Branch (2479:42): [True: 378, False: 220]
  ------------------
 2480|    378|		u8 c4data[10];
 2481|    378|		int r;
 2482|       |
 2483|    378|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2484|    378|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
  ------------------
  |  |  174|    378|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    378|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    378|	int _ret = (r); \
  |  |  |  |  168|    378|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 358, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  169|    358|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    358|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    358|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    358|		return _ret; \
  |  |  |  |  172|    358|	} \
  |  |  |  |  173|    378|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2485|       |
 2486|     20|		if (r != 7)
  ------------------
  |  Branch (2486:7): [True: 17, False: 3]
  ------------------
 2487|     20|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2488|      3|				"CHV status bytes have unexpected length");
 2489|       |
 2490|       |		/* The definition of fields of DO C4 changed between OpenPGP
 2491|       |		 * card specification v1.1 and v2.0. There is no longer a separate
 2492|       |		 * CHV2 retry counter but only one retry counter for both PW1 mode 1
 2493|       |		 * and mode 2 at byte 5 (count from 1) of the DO.
 2494|       |		 */
 2495|      3|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2495:7): [True: 2, False: 1]
  |  Branch (2495:48): [True: 1, False: 1]
  ------------------
 2496|      1|			data->pin_reference = 0x81;
 2497|       |
 2498|      3|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2499|      3|		data->pin1.max_tries = 3;
 2500|      3|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      3|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2501|       |
 2502|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2503|      3|	}
 2504|       |
 2505|    577|#ifdef ENABLE_OPENSSL
 2506|    577|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2506:6): [True: 0, False: 577]
  ------------------
 2507|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2508|      0|	}
 2509|    577|#endif /* ENABLE_OPENSSL */
 2510|       |
 2511|    577|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data));
  ------------------
  |  |  164|    577|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    577|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    577|	int _ret = r; \
  |  |  |  |  155|    577|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 577, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    577|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    451|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 451, False: 126]
  |  |  |  |  ------------------
  |  |  |  |  157|    577|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    577|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    577|	return _ret; \
  |  |  |  |  163|    577|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2512|    577|}
card-openpgp.c:pgp_get_data:
 2011|  5.51k|{
 2012|  5.51k|	sc_apdu_t	apdu;
 2013|  5.51k|	int		r;
 2014|       |
 2015|  5.51k|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2016|       |
 2017|  5.51k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  5.51k|#define SC_APDU_CASE_2			0x22
  ------------------
 2018|  5.51k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  547|  3.94k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2018:13): [True: 3.94k, False: 1.57k]
  |  Branch (2018:33): [True: 3.83k, False: 110]
  ------------------
 2019|  5.51k|	apdu.resp = buf;
 2020|  5.51k|	apdu.resplen = buf_len;
 2021|       |
 2022|  5.51k|	r = sc_transmit_apdu(card, &apdu);
 2023|  5.51k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  5.51k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.51k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.51k|	int _ret = (r); \
  |  |  |  |  168|  5.51k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 34, False: 5.48k]
  |  |  |  |  ------------------
  |  |  |  |  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|  5.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.48k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2024|       |
 2025|  5.48k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2026|       |
 2027|       |	/* Gnuk returns an error instead of empty data if there is no certificate or private DO.
 2028|       |	 * So, for this case, we ignore error and consider success */
 2029|  5.48k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2029:6): [True: 1.84k, False: 3.63k]
  ------------------
 2030|  1.84k|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|  3.69k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2030:7): [True: 207, False: 1.63k]
  ------------------
 2031|  1.63k|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|  3.48k|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2031:7): [True: 23, False: 1.61k]
  ------------------
 2032|  1.61k|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|  3.46k|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2032:7): [True: 23, False: 1.59k]
  ------------------
 2033|  1.59k|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|  3.43k|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2033:7): [True: 23, False: 1.56k]
  ------------------
 2034|  1.56k|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|  1.56k|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2034:7): [True: 23, False: 1.54k]
  ------------------
 2035|    299|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    299|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2035:7): [True: 1, False: 298]
  ------------------
 2036|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2037|      1|			apdu.resplen = 0;
 2038|      1|		}
 2039|    299|	}
 2040|  5.48k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  5.48k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.48k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.48k|	int _ret = (r); \
  |  |  |  |  168|  5.48k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.20k, False: 2.27k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.20k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.20k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.20k|		return _ret; \
  |  |  |  |  172|  3.20k|	} \
  |  |  |  |  173|  5.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2041|       |
 2042|  2.27k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.27k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.27k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.27k|	int _ret = r; \
  |  |  |  |  155|  2.27k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 741, False: 1.53k]
  |  |  |  |  ------------------
  |  |  |  |  156|    741|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 741]
  |  |  |  |  ------------------
  |  |  |  |  157|    741|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.53k|	} else { \
  |  |  |  |  159|  1.53k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.53k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.53k|	} \
  |  |  |  |  162|  2.27k|	return _ret; \
  |  |  |  |  163|  2.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2043|  2.27k|}
card-openpgp.c:pgp_set_security_env:
 2555|    265|{
 2556|    265|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    265|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2557|       |
 2558|    265|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    265|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    265|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    265|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    265|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 265]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2559|       |
 2560|       |	/* The SC_SEC_ENV_ALG_PRESENT is set always so let it pass for GNUK */
 2561|    265|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   60|    265|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (2561:6): [True: 265, False: 0]
  ------------------
 2562|    265|		&& (env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   69|    265|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2562:6): [True: 0, False: 265]
  ------------------
 2563|      0|		&& (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (2563:6): [True: 0, False: 0]
  ------------------
 2564|      0|		&& (card->type != SC_CARD_TYPE_OPENPGP_GNUK))
  ------------------
  |  Branch (2564:6): [True: 0, False: 0]
  ------------------
 2565|    265|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2566|    265|				"only RSA algorithm supported");
 2567|       |
 2568|    265|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len != 1))
  ------------------
  |  |   58|    265|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (2568:6): [True: 0, False: 265]
  |  Branch (2568:52): [True: 0, False: 265]
  ------------------
 2569|    265|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2570|    265|				"exactly one key reference required");
 2571|       |
 2572|    265|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   57|    265|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (2572:6): [True: 0, False: 265]
  ------------------
 2573|    265|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2574|    265|			"passing file references not supported");
 2575|       |
 2576|    265|	sc_log(card->ctx, "Key ref %d", env->key_ref[0]);
  ------------------
  |  |   71|    265|#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|    265|	switch (env->operation) {
 2578|    183|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    183|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2578:2): [True: 183, False: 82]
  ------------------
 2579|    183|		sc_log(card->ctx, "Operation: Sign.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2580|    183|		if (env->key_ref[0] != 0x00 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2580:7): [True: 116, False: 67]
  |  Branch (2580:34): [True: 0, False: 116]
  ------------------
 2581|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2582|      0|				"Key reference not compatible with "
 2583|      0|				"requested usage");
 2584|      0|		}
 2585|    183|		break;
 2586|    183|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|     82|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2586:2): [True: 82, False: 183]
  ------------------
 2587|     82|		sc_log(card->ctx, "Operation: Decipher.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2588|       |		/* we allow key ref 2 (auth key) to be used for deciphering */
 2589|     82|		if (env->key_ref[0] != 0x01 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2589:7): [True: 17, False: 65]
  |  Branch (2589:34): [True: 0, False: 17]
  ------------------
 2590|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2591|      0|				"Key reference not compatible with "
 2592|      0|				"requested usage");
 2593|      0|		}
 2594|     82|		break;
 2595|     82|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2595:2): [True: 0, False: 265]
  ------------------
 2596|      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__
  |  |  ------------------
  ------------------
 2597|      0|		break;
 2598|      0|	default:
  ------------------
  |  Branch (2598:2): [True: 0, False: 265]
  ------------------
 2599|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2600|    265|				"invalid operation");
 2601|    265|	}
 2602|       |
 2603|    265|	priv->sec_env = *env;
 2604|       |
 2605|    265|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    265|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    265|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    265|	int _ret = r; \
  |  |  |  |  155|    265|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 265]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2606|    265|}
card-openpgp.c:pgp_compute_signature:
 2660|    183|{
 2661|    183|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|    183|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2662|    183|	sc_security_env_t	*env = &priv->sec_env;
 2663|    183|	sc_apdu_t		apdu;
 2664|    183|	u8 apdu_case = (card->type == SC_CARD_TYPE_OPENPGP_GNUK)
  ------------------
  |  Branch (2664:17): [True: 48, False: 135]
  ------------------
 2665|    183|			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  294|     48|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  303|    318|#define SC_APDU_CASE_4			0x24
  ------------------
 2666|    183|	int			r;
 2667|       |
 2668|    183|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    183|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    183|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    183|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    183|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 183]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2669|       |
 2670|    183|	if (!data || !out)
  ------------------
  |  Branch (2670:6): [True: 0, False: 183]
  |  Branch (2670:15): [True: 0, False: 183]
  ------------------
 2671|    183|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2672|       |
 2673|    183|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   48|    183|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2673:6): [True: 0, False: 183]
  ------------------
 2674|    183|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2675|    183|				"invalid operation");
 2676|       |
 2677|    183|	switch (env->key_ref[0]) {
 2678|     67|	case 0x00: /* signature key */
  ------------------
  |  Branch (2678:2): [True: 67, False: 116]
  ------------------
 2679|       |		/* PSO SIGNATURE */
 2680|     67|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x9E, 0x9A);
 2681|     67|		break;
 2682|    116|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2682:2): [True: 116, False: 67]
  ------------------
 2683|       |		/* INTERNAL AUTHENTICATE */
 2684|    116|		sc_format_apdu(card, &apdu, apdu_case, 0x88, 0, 0);
 2685|    116|		break;
 2686|      0|	case 0x01:
  ------------------
  |  Branch (2686:2): [True: 0, False: 183]
  ------------------
 2687|      0|	default:
  ------------------
  |  Branch (2687:2): [True: 0, False: 183]
  ------------------
 2688|       |		/* From PKCS #11 point of view, we should be able to use
 2689|       |		 * curve25519 to do digital signature, but it is not how it
 2690|       |		 * is used in OpenPGP so we will not allow it here */
 2691|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2692|    183|			"invalid key reference");
 2693|    183|	}
 2694|       |
 2695|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2696|    183|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  547|    183|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2696:6): [True: 164, False: 19]
  |  Branch (2696:52): [True: 51, False: 113]
  ------------------
 2697|     51|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     51|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2698|       |
 2699|    183|	apdu.lc = data_len;
 2700|    183|	apdu.data = (u8 *)data;
 2701|    183|	apdu.datalen = data_len;
 2702|    183|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  547|    183|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2702:13): [True: 183, False: 0]
  |  Branch (2702:32): [True: 164, False: 19]
  ------------------
 2703|    183|	apdu.resp    = out;
 2704|    183|	apdu.resplen = outlen;
 2705|       |
 2706|    183|	r = sc_transmit_apdu(card, &apdu);
 2707|    183|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    183|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    183|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    183|	int _ret = (r); \
  |  |  |  |  168|    183|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 76, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  169|     76|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     76|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     76|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     76|		return _ret; \
  |  |  |  |  172|     76|	} \
  |  |  |  |  173|    183|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 107]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2708|       |
 2709|    107|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2710|    107|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 75, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  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|    107|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2711|       |
 2712|     32|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 14, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  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|     18|	} else { \
  |  |  |  |  159|     18|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     18|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     18|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2713|     32|}
card-openpgp.c:pgp_decipher:
 2722|     50|{
 2723|     50|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     50|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2724|     50|	sc_security_env_t	*env = &priv->sec_env;
 2725|     50|	sc_apdu_t	apdu;
 2726|     50|	u8 apdu_case = SC_APDU_CASE_4;
  ------------------
  |  |  303|     50|#define SC_APDU_CASE_4			0x24
  ------------------
 2727|     50|	u8		*temp = NULL, *p = NULL;
 2728|     50|	size_t templen = 0, pklen, dolen;
 2729|     50|	int		r;
 2730|       |
 2731|     50|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     50|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     50|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     50|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     50|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 50]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2732|       |
 2733|     50|	if (!in || !out)
  ------------------
  |  Branch (2733:6): [True: 0, False: 50]
  |  Branch (2733:13): [True: 0, False: 50]
  ------------------
 2734|     50|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2735|       |
 2736|       |	/* padding according to OpenPGP card spec 1.1 & 2.x section 7.2.9 / 3.x section 7.2.11
 2737|       |	 * The longest possible prefix is 10 bytes for ECDH */
 2738|     50|	templen = inlen + 10;
 2739|     50|	if (!(temp = malloc(templen))) {
  ------------------
  |  Branch (2739:6): [True: 0, False: 50]
  ------------------
 2740|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2741|      0|		goto err;
 2742|      0|	}
 2743|       |
 2744|       |	/* padding byte: 0xa6 = ECC; 0x00 = RSA; 0x02 = AES */
 2745|     50|	switch (env->algorithm) {
 2746|     50|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|     50|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2746:2): [True: 50, False: 0]
  ------------------
 2747|       |		/* This is just PKCS#1.5 start byte and it should be already
 2748|       |		 * provided by the padding routines. But it lets put it here
 2749|       |		 * to make sure it does not conflict with following indicators */
 2750|     50|		temp[0] = 0x00;
 2751|     50|		memcpy(temp + 1, in, inlen);
 2752|     50|		inlen += 1;
 2753|     50|		break;
 2754|       |
 2755|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2755:2): [True: 0, False: 50]
  ------------------
 2756|      0|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (2756:2): [True: 0, False: 50]
  ------------------
 2757|       |		/* Calculate length of External Public Key (0x86) */
 2758|      0|		r = sc_asn1_put_tag(0x86, NULL, inlen, NULL, 0, NULL);
 2759|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2760|      0|		pklen = r;
 2761|       |
 2762|       |		/* Calculate length of Public Key DO (0x7F49) */
 2763|      0|		r = sc_asn1_put_tag(0x7f49, NULL, pklen, NULL, 0, NULL);
 2764|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2765|      0|		dolen = r;
 2766|       |
 2767|      0|		p = temp;
 2768|       |		/* This is 0xA6 Cipher DO with associated length field */
 2769|      0|		r = sc_asn1_put_tag(0xA6, NULL, dolen, p, templen - (p - temp), &p);
 2770|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2771|       |
 2772|       |		/* Public Key DO (0x7F49) with associated length field */
 2773|      0|		r = sc_asn1_put_tag(0x7F49, NULL, pklen, p, templen - (p - temp), &p);
 2774|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2775|       |
 2776|       |		/* External Public Key (0x86) with associated length */
 2777|      0|		r = sc_asn1_put_tag(0x86, in, inlen, p, templen - (p - temp), &p);
 2778|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2779|      0|		inlen = (p - temp);
 2780|      0|		break;
 2781|      0|	case SC_ALGORITHM_AES:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (2781:2): [True: 0, False: 50]
  ------------------
 2782|       |		/* not supported yet */
 2783|       |		/*
 2784|       |		temp[0] = 0x02;
 2785|       |		memcpy(temp + 1, in, inlen);
 2786|       |		inlen += 1;
 2787|       |		*/
 2788|       |		/* fall through */
 2789|      0|	default:
  ------------------
  |  Branch (2789:2): [True: 0, False: 50]
  ------------------
 2790|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2791|      0|		goto err;
 2792|     50|	}
 2793|       |
 2794|     50|	in = temp;
 2795|       |
 2796|     50|	if (env->operation != SC_SEC_OPERATION_DECIPHER &&
  ------------------
  |  |   47|    100|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2796:6): [True: 0, False: 50]
  ------------------
 2797|      0|			env->operation != SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2797:4): [True: 0, False: 0]
  ------------------
 2798|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2799|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "invalid operation");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2800|      0|	}
 2801|       |
 2802|     50|	switch (env->key_ref[0]) {
 2803|     36|	case 0x01: /* Decryption key */
  ------------------
  |  Branch (2803:2): [True: 36, False: 14]
  ------------------
 2804|     50|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2804:2): [True: 14, False: 36]
  ------------------
 2805|       |		/* PSO DECIPHER */
 2806|     50|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x80, 0x86);
 2807|     50|		break;
 2808|      0|	case 0x00: /* signature key */
  ------------------
  |  Branch (2808:2): [True: 0, False: 50]
  ------------------
 2809|      0|	default:
  ------------------
  |  Branch (2809:2): [True: 0, False: 50]
  ------------------
 2810|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2811|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "invalid key reference");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2812|     50|	}
 2813|       |
 2814|       |	/* Gnuk only supports short APDU, so we need to use command chaining */
 2815|     50|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (2815:6): [True: 28, False: 22]
  ------------------
 2816|     28|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     28|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2817|     28|	}
 2818|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2819|     50|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  547|     50|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2819:6): [True: 45, False: 5]
  |  Branch (2819:52): [True: 28, False: 17]
  ------------------
 2820|     28|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     28|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2821|       |
 2822|     50|	apdu.lc = inlen;
 2823|     50|	apdu.data = (u8 *)in;
 2824|     50|	apdu.datalen = inlen;
 2825|     50|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  547|     50|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2825:13): [True: 50, False: 0]
  |  Branch (2825:32): [True: 45, False: 5]
  ------------------
 2826|     50|	apdu.resp = out;
 2827|     50|	apdu.resplen = outlen;
 2828|       |
 2829|       |	/* For OpenPGP Card >=v3.3, key slot 3 instead of 2 can be used for deciphering,
 2830|       |	 * but this has to be set via MSE beforehand on every usage (slot 2 is used by default)
 2831|       |	 * see section 7.2.18 of the specification of OpenPGP Card v3.3 */
 2832|     50|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2832:6): [True: 19, False: 31]
  |  Branch (2832:47): [True: 14, False: 5]
  ------------------
 2833|     14|		pgp_set_MSE(card, 3, 0xb8);
 2834|     14|	}
 2835|       |
 2836|     50|	r = sc_transmit_apdu(card, &apdu);
 2837|     50|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|     50|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     50|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     50|	int _ret = (r); \
  |  |  |  |  178|     50|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 8, False: 42]
  |  |  |  |  ------------------
  |  |  |  |  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|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2838|       |
 2839|     42|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2840|     42|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|     42|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     42|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     42|	int _ret = (r); \
  |  |  |  |  178|     42|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 34, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     34|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     34|		goto err; \
  |  |  |  |  182|     34|	} \
  |  |  |  |  183|     42|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2841|       |
 2842|       |	/* For OpenPGP Card >=v3.3, use key slot 2 for deciphering again (set to default) */
 2843|      8|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2843:6): [True: 5, False: 3]
  |  Branch (2843:47): [True: 4, False: 1]
  ------------------
 2844|      4|		pgp_set_MSE(card, 2, 0xb8);
 2845|      4|	}
 2846|       |
 2847|      8|	r = (int)apdu.resplen;
 2848|     50|err:
 2849|     50|	sc_mem_clear(temp, templen);
 2850|     50|	free(temp);
 2851|     50|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     50|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     50|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     50|	int _ret = r; \
  |  |  |  |  155|     50|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 43, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  156|     43|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|     43|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     43|	} 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|     50|	return _ret; \
  |  |  |  |  163|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2852|     50|}
card-openpgp.c:pgp_set_MSE:
 2621|     18|{
 2622|     18|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     18|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2623|     18|	sc_apdu_t	apdu;
 2624|     18|	u8	apdu_case = SC_APDU_CASE_3;
  ------------------
  |  |  302|     18|#define SC_APDU_CASE_3			0x23
  ------------------
 2625|     18|	u8	apdu_data[3];
 2626|     18|	int	r;
 2627|       |
 2628|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2629|       |
 2630|       |	// check if MSE is supported
 2631|     18|	if (!(priv->ext_caps & EXT_CAP_MSE))
  ------------------
  |  Branch (2631:6): [True: 0, False: 18]
  ------------------
 2632|     18|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2633|       |
 2634|       |	// create apdu
 2635|     18|	sc_format_apdu(card, &apdu, apdu_case, 0x22, 0x41, p2);
 2636|     18|	apdu.lc = 3;
 2637|     18|	apdu_data[0] = 0x83;
 2638|     18|	apdu_data[1] = 0x01;
 2639|     18|	apdu_data[2] = key;
 2640|     18|	apdu.data = apdu_data;
 2641|     18|	apdu.datalen = 3;
 2642|       |
 2643|       |	// transmit apdu
 2644|     18|	r = sc_transmit_apdu(card, &apdu);
 2645|     18|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     18|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     18|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     18|	int _ret = (r); \
  |  |  |  |  168|     18|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     18|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2646|       |
 2647|     17|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2648|     17|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  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|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2649|       |
 2650|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2651|     10|}
card-openpgp.c:pgp_card_ctl:
 4034|    231|{
 4035|    231|	int r;
 4036|       |
 4037|    231|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    231|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    231|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    231|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    231|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 231]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4038|       |
 4039|    231|	switch(cmd) {
  ------------------
  |  Branch (4039:9): [True: 231, False: 0]
  ------------------
 4040|     23|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4040:2): [True: 23, False: 208]
  ------------------
 4041|     23|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4042|     23|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     23|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     23|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     23|	int _ret = r; \
  |  |  |  |  155|     23|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 23, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     23|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  157|     23|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     23|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     23|	return _ret; \
  |  |  |  |  163|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4043|      0|		break;
 4044|    208|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4044:2): [True: 208, False: 23]
  ------------------
 4045|    208|		r = pgp_select_data(card, *((u8 *) ptr));
 4046|    208|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    208|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    208|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    208|	int _ret = r; \
  |  |  |  |  155|    208|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 208, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    208|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 17]
  |  |  |  |  ------------------
  |  |  |  |  157|    208|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    208|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    208|	return _ret; \
  |  |  |  |  163|    208|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4047|      0|		break;
 4048|      0|#ifdef ENABLE_OPENSSL
 4049|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4049:2): [True: 0, False: 231]
  ------------------
 4050|      0|		r = pgp_gen_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4051|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4052|      0|		break;
 4053|      0|	case SC_CARDCTL_OPENPGP_STORE_KEY:
  ------------------
  |  Branch (4053:2): [True: 0, False: 231]
  ------------------
 4054|      0|		r = pgp_store_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4055|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4056|      0|		break;
 4057|      0|#endif /* ENABLE_OPENSSL */
 4058|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (4058:2): [True: 0, False: 231]
  ------------------
 4059|      0|		r = pgp_erase_card(card);
 4060|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4061|      0|		break;
 4062|    231|	}
 4063|       |
 4064|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4065|      0|}
card-openpgp.c:pgp_select_data:
 1973|    208|{
 1974|    208|	sc_apdu_t	apdu;
 1975|    208|	u8	apdu_data[6];
 1976|    208|	int	r;
 1977|    208|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    208|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1978|       |
 1979|    208|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    208|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    208|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    208|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    208|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 208]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1980|       |
 1981|    208|	if (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (1981:6): [True: 133, False: 75]
  ------------------
 1982|    208|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|       |
 1984|     75|	sc_log(card->ctx, "select data with: %u", p1);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1985|       |
 1986|       |	// create apdu data (taken from spec: SELECT DATA 7.2.5.)
 1987|     75|	apdu_data[0] = 0x60;
 1988|     75|	apdu_data[1] = 0x04;
 1989|     75|	apdu_data[2] = 0x5c;
 1990|     75|	apdu_data[3] = 0x02;
 1991|     75|	apdu_data[4] = 0x7f;
 1992|     75|	apdu_data[5] = 0x21;
 1993|       |
 1994|       |	// apdu, cla, ins, p1, p2, data, datalen, resp, resplen
 1995|     75|	sc_format_apdu_ex(&apdu, 0x00, 0xA5, p1, 0x04, apdu_data, sizeof(apdu_data), NULL, 0);
 1996|       |
 1997|       |	// transmit apdu
 1998|     75|	r = sc_transmit_apdu(card, &apdu);
 1999|     75|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     75|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     75|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     75|	int _ret = (r); \
  |  |  |  |  168|     75|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  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|     75|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2000|     71|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2001|     71|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     71|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     71|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     71|	int _ret = (r); \
  |  |  |  |  168|     71|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 54, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     54|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     54|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     54|		return _ret; \
  |  |  |  |  172|     54|	} \
  |  |  |  |  173|     71|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2002|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2003|     17|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4194|  9.20k|{
 4195|  9.20k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  9.20k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4196|  9.20k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  9.20k|#define SC_SUCCESS				0
  ------------------
 4197|       |
 4198|  9.20k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.20k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.20k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.20k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.20k]
  |  |  ------------------
  ------------------
 4199|       |
 4200|  9.20k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  537|  18.4k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4200:6): [True: 0, False: 9.20k]
  ------------------
 4201|      0|			&& was_reset <= 0
  ------------------
  |  Branch (4201:7): [True: 0, False: 0]
  ------------------
 4202|      0|			&& priv != NULL && priv->mf && priv->mf->file) {
  ------------------
  |  Branch (4202:7): [True: 0, False: 0]
  |  Branch (4202:23): [True: 0, False: 0]
  |  Branch (4202:35): [True: 0, False: 0]
  ------------------
 4203|       |		/* check whether applet is still selected */
 4204|      0|		unsigned char aid[16];
 4205|       |
 4206|      0|		r = sc_get_data(card, 0x004F, aid, sizeof aid);
 4207|      0|		if ((size_t) r != priv->mf->file->namelen
  ------------------
  |  Branch (4207:7): [True: 0, False: 0]
  ------------------
 4208|      0|				|| 0 != memcmp(aid, priv->mf->file->name, r)) {
  ------------------
  |  Branch (4208:8): [True: 0, False: 0]
  ------------------
 4209|       |			/* reselect is required */
 4210|      0|			was_reset = 1;
 4211|      0|		}
 4212|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 4213|      0|	}
 4214|       |
 4215|  9.20k|	if (was_reset > 0) {
  ------------------
  |  Branch (4215:6): [True: 0, False: 9.20k]
  ------------------
 4216|      0|		sc_file_t	*file = NULL;
 4217|      0|		sc_path_t	path;
 4218|       |		/* select application "OpenPGP" */
 4219|      0|		sc_format_path("D276:0001:2401", &path);
 4220|      0|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 4221|      0|		r = iso_ops->select_file(card, &path, &file);
 4222|      0|		sc_file_free(file);
 4223|      0|	}
 4224|       |
 4225|  9.20k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  9.20k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.20k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.20k|	int _ret = r; \
  |  |  |  |  155|  9.20k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.20k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.20k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9.20k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.20k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.20k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.20k|	return _ret; \
  |  |  |  |  163|  9.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4226|  9.20k|}

sc_get_piv_driver:
 6721|  16.1k|{
 6722|  16.1k|	return sc_get_driver();
 6723|  16.1k|}
card-piv.c:sc_get_driver:
 6694|  16.1k|{
 6695|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6696|       |
 6697|  16.1k|	piv_ops = *iso_drv->ops;
 6698|  16.1k|	piv_ops.match_card = piv_match_card;
 6699|  16.1k|	piv_ops.init = piv_init;
 6700|  16.1k|	piv_ops.finish = piv_finish;
 6701|       |
 6702|  16.1k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6703|  16.1k|	piv_ops.get_challenge = piv_get_challenge;
 6704|  16.1k|	piv_ops.logout = piv_logout;
 6705|  16.1k|	piv_ops.read_binary = piv_read_binary;
 6706|  16.1k|	piv_ops.write_binary = piv_write_binary;
 6707|  16.1k|	piv_ops.set_security_env = piv_set_security_env;
 6708|  16.1k|	piv_ops.restore_security_env = piv_restore_security_env;
 6709|  16.1k|	piv_ops.compute_signature = piv_compute_signature;
 6710|  16.1k|	piv_ops.decipher = piv_decipher;
 6711|  16.1k|	piv_ops.check_sw = piv_check_sw;
 6712|  16.1k|	piv_ops.card_ctl = piv_card_ctl;
 6713|  16.1k|	piv_ops.pin_cmd = piv_pin_cmd;
 6714|  16.1k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6715|       |
 6716|  16.1k|	return &piv_drv;
 6717|  16.1k|}
card-piv.c:piv_match_card:
 5639|  5.89k|{
 5640|  5.89k|	int r = 0;
 5641|       |
 5642|  5.89k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.89k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5643|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5644|       |	/* user provided card type must be one we know */
 5645|  5.89k|	switch (card->type) {
 5646|  5.89k|	case -1:
  ------------------
  |  Branch (5646:2): [True: 5.89k, False: 0]
  ------------------
 5647|  5.89k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5647:2): [True: 0, False: 5.89k]
  ------------------
 5648|  5.89k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5648:2): [True: 0, False: 5.89k]
  ------------------
 5649|  5.89k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5649:2): [True: 0, False: 5.89k]
  ------------------
 5650|  5.89k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5650:2): [True: 0, False: 5.89k]
  ------------------
 5651|  5.89k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5651:2): [True: 0, False: 5.89k]
  ------------------
 5652|  5.89k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5652:2): [True: 0, False: 5.89k]
  ------------------
 5653|  5.89k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5653:2): [True: 0, False: 5.89k]
  ------------------
 5654|  5.89k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5654:2): [True: 0, False: 5.89k]
  ------------------
 5655|  5.89k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5655:2): [True: 0, False: 5.89k]
  ------------------
 5656|  5.89k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5656:2): [True: 0, False: 5.89k]
  ------------------
 5657|  5.89k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5657:2): [True: 0, False: 5.89k]
  ------------------
 5658|  5.89k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5658:2): [True: 0, False: 5.89k]
  ------------------
 5659|  5.89k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5659:2): [True: 0, False: 5.89k]
  ------------------
 5660|  5.89k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5660:2): [True: 0, False: 5.89k]
  ------------------
 5661|  5.89k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5661:2): [True: 0, False: 5.89k]
  ------------------
 5662|  5.89k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5662:2): [True: 0, False: 5.89k]
  ------------------
 5663|  5.89k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5663:2): [True: 0, False: 5.89k]
  ------------------
 5664|  5.89k|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5664:2): [True: 0, False: 5.89k]
  ------------------
 5665|  5.89k|		break;
 5666|      0|	default:
  ------------------
  |  Branch (5666:2): [True: 0, False: 5.89k]
  ------------------
 5667|      0|		return 0; /* can not handle the card */
 5668|  5.89k|	}
 5669|       |
 5670|  5.89k|	r = sc_lock(card);
 5671|  5.89k|	if (r < 0)
  ------------------
  |  Branch (5671:6): [True: 0, False: 5.89k]
  ------------------
 5672|      0|		return 0;
 5673|       |	/* its one we know, or we can test for it in piv_init */
 5674|  5.89k|	r = piv_match_card_continued(card);
 5675|  5.89k|	sc_unlock(card);
 5676|       |
 5677|  5.89k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5677:6): [True: 4.77k, False: 1.11k]
  |  Branch (5677:15): [True: 0, False: 1.11k]
  ------------------
 5678|       |		/* clean up what we left in card */
 5679|  4.77k|		piv_finish(card);
 5680|  4.77k|		return 0; /* match failed */
 5681|  4.77k|	}
 5682|       |
 5683|  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__
  |  |  ------------------
  ------------------
 5684|  1.11k|	return 1; /* matched */
 5685|  5.89k|}
card-piv.c:piv_match_card_continued:
 5689|  5.89k|{
 5690|  5.89k|	int i, r = 0, r2 = 0;
 5691|  5.89k|	int type = -1;
 5692|  5.89k|	piv_private_data_t *priv = NULL;
 5693|  5.89k|	int saved_type = card->type;
 5694|  5.89k|	sc_apdu_t apdu;
 5695|  5.89k|	u8 yubico_version_buf[3] = {0};
 5696|       |
 5697|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5698|       |	/* User provided card type must be one we know */
 5699|       |
 5700|  5.89k|	switch (card->type) {
 5701|  5.89k|	case -1:
  ------------------
  |  Branch (5701:2): [True: 5.89k, False: 0]
  ------------------
 5702|  5.89k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5702:2): [True: 0, False: 5.89k]
  ------------------
 5703|  5.89k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5703:2): [True: 0, False: 5.89k]
  ------------------
 5704|  5.89k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5704:2): [True: 0, False: 5.89k]
  ------------------
 5705|  5.89k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5705:2): [True: 0, False: 5.89k]
  ------------------
 5706|  5.89k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5706:2): [True: 0, False: 5.89k]
  ------------------
 5707|  5.89k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5707:2): [True: 0, False: 5.89k]
  ------------------
 5708|  5.89k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5708:2): [True: 0, False: 5.89k]
  ------------------
 5709|  5.89k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5709:2): [True: 0, False: 5.89k]
  ------------------
 5710|  5.89k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5710:2): [True: 0, False: 5.89k]
  ------------------
 5711|  5.89k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5711:2): [True: 0, False: 5.89k]
  ------------------
 5712|  5.89k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5712:2): [True: 0, False: 5.89k]
  ------------------
 5713|  5.89k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5713:2): [True: 0, False: 5.89k]
  ------------------
 5714|  5.89k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5714:2): [True: 0, False: 5.89k]
  ------------------
 5715|  5.89k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5715:2): [True: 0, False: 5.89k]
  ------------------
 5716|  5.89k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5716:2): [True: 0, False: 5.89k]
  ------------------
 5717|  5.89k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5717:2): [True: 0, False: 5.89k]
  ------------------
 5718|  5.89k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5718:2): [True: 0, False: 5.89k]
  ------------------
 5719|  5.89k|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5719:2): [True: 0, False: 5.89k]
  ------------------
 5720|       |
 5721|  5.89k|		type = card->type;
 5722|  5.89k|		break;
 5723|      0|	default:
  ------------------
  |  Branch (5723:2): [True: 0, False: 5.89k]
  ------------------
 5724|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5725|  5.89k|	}
 5726|  5.89k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.89k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5727|  5.89k|	if (type == -1) {
  ------------------
  |  Branch (5727:6): [True: 5.89k, False: 0]
  ------------------
 5728|       |		/*
 5729|       |		 * Try to identify card by ATR or historical data in ATR
 5730|       |		 * currently all PIV card will respond to piv_find_aid
 5731|       |		 * the same. But in future may need to know card type first,
 5732|       |		 * so do it here.
 5733|       |		 */
 5734|       |
 5735|  5.89k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5735:7): [True: 2.73k, False: 3.15k]
  ------------------
 5736|  2.73k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5736:8): [True: 618, False: 2.11k]
  ------------------
 5737|    618|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5737:6): [True: 228, False: 390]
  ------------------
 5738|    228|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5739|  2.50k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5739:15): [True: 1.78k, False: 724]
  ------------------
 5740|  1.78k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5740:6): [True: 319, False: 1.46k]
  ------------------
 5741|    319|				type = SC_CARD_TYPE_PIV_II_NEO;
 5742|  2.18k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5742:15): [True: 1.51k, False: 676]
  ------------------
 5743|  1.51k|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5743:6): [True: 130, False: 1.38k]
  ------------------
 5744|    130|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5745|  2.05k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5745:15): [True: 1.38k, False: 676]
  ------------------
 5746|  1.38k|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5746:6): [True: 23, False: 1.35k]
  ------------------
 5747|     23|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5748|     23|			}
 5749|       |			/* look for TLV historic data */
 5750|  2.03k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5750:13): [True: 1.99k, False: 37]
  ------------------
 5751|  1.99k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5751:6): [True: 589, False: 1.40k]
  ------------------
 5752|    589|				size_t datalen;
 5753|    589|				const u8 *data;
 5754|       |
 5755|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5756|    589|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5756:9): [True: 59, False: 530]
  ------------------
 5757|    589|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5758|     59|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5758:10): [True: 29, False: 30]
  |  Branch (5758:26): [True: 17, False: 12]
  ------------------
 5759|     17|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5760|     42|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5760:17): [True: 25, False: 17]
  |  Branch (5760:33): [True: 1, False: 24]
  ------------------
 5761|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5762|      1|					}
 5763|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5764|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5765|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5766|       |					 * will look at only 6 bytes that do match
 5767|       |					 */
 5768|     41|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5768:15): [True: 24, False: 17]
  |  Branch (5768:31): [True: 1, False: 23]
  ------------------
 5769|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5770|      1|					}
 5771|    530|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5771:16): [True: 141, False: 389]
  ------------------
 5772|    530|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5773|    141|					int k;
 5774|       |
 5775|    248|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5775:18): [True: 195, False: 53]
  ------------------
 5776|    195|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5776:11): [True: 179, False: 16]
  ------------------
 5777|    179|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5777:9): [True: 88, False: 91]
  ------------------
 5778|     88|							type = SC_CARD_TYPE_PIV_II_HIST;
 5779|     88|							break;
 5780|     88|						}
 5781|    195|					}
 5782|    141|				}
 5783|    589|			}
 5784|  2.73k|		}
 5785|       |
 5786|  5.89k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.89k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5787|       |
 5788|  5.89k|		if (type == -1) {
  ------------------
  |  Branch (5788:7): [True: 5.08k, False: 807]
  ------------------
 5789|       |			/* use known ATRs  which changes the type */
 5790|  5.08k|			i = _sc_match_atr(card, piv_atrs, &type);
 5791|  5.08k|			if (i < 0)
  ------------------
  |  Branch (5791:8): [True: 5.05k, False: 28]
  ------------------
 5792|  5.05k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5793|  5.08k|		}
 5794|  5.89k|	}
 5795|       |
 5796|  5.89k|	card->type = type;
 5797|       |
 5798|       |	/* we either found via ATR historic bytes or ATR directly */
 5799|  5.89k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.89k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5800|       |
 5801|       |	/* allocate and init basic fields */
 5802|  5.89k|	priv = calloc(1, sizeof(piv_private_data_t));
 5803|       |
 5804|  5.89k|	if (!priv)
  ------------------
  |  Branch (5804:6): [True: 0, False: 5.89k]
  ------------------
 5805|  5.89k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5806|       |
 5807|  5.89k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5808|       |	/*
 5809|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5810|       |	 * If for some reason future cards have larger objects, this value needs to
 5811|       |	 * be increased here.
 5812|       |	 */
 5813|  5.89k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  220|  5.89k|#define MAX_FILE_SIZE 65535
  ------------------
 5814|  5.89k|	priv->selected_obj = -1;
 5815|  5.89k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5816|  5.89k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|  5.89k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5817|  5.89k|	priv->pstate = PIV_STATE_MATCH;
 5818|       |
 5819|       |#ifdef ENABLE_PIV_SM
 5820|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5821|       |	card->sm_ctx.ops.open = piv_sm_open;
 5822|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5823|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5824|       |	card->sm_ctx.ops.close = piv_sm_close;
 5825|       |#endif /* ENABLE_PIV_SM */
 5826|       |
 5827|       |	/* See if contactless  or run as virtual card */
 5828|       |	/* PivApplet in .github/test_piv.sh for example */
 5829|  5.89k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5829:6): [True: 3.03k, False: 2.85k]
  ------------------
 5830|  3.03k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5830:4): [True: 2.75k, False: 284]
  ------------------
 5831|  2.75k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5831:4): [True: 285, False: 2.46k]
  ------------------
 5832|    285|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5832:4): [True: 198, False: 87]
  ------------------
 5833|    198|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5833:4): [True: 182, False: 16]
  ------------------
 5834|    182|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  385|    182|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5835|    182|	}
 5836|       |
 5837|   359k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5837:14): [True: 353k, False: 5.89k]
  ------------------
 5838|   353k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  655|   353k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5838:7): [True: 117k, False: 235k]
  ------------------
 5839|   117k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|   123k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5840|       |	/*
 5841|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5842|       |	 * and PIV must be the default application.
 5843|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5844|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5845|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5846|       |	 *
 5847|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5848|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5849|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5850|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5851|       |	 */
 5852|       |
 5853|       |	/*
 5854|       |	 * if ATR matched or user forced card type
 5855|       |	 * test if PIV is active applet without using AID If fails try AID
 5856|       |	 */
 5857|       |
 5858|  5.89k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5858:6): [True: 835, False: 5.05k]
  ------------------
 5859|    835|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  385|    835|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5859:4): [True: 828, False: 7]
  ------------------
 5860|    828|		r = piv_find_discovery(card);
 5861|    828|		if (r < 0) {
  ------------------
  |  Branch (5861:7): [True: 514, False: 314]
  ------------------
 5862|    514|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5863|    514|			r = piv_find_aid(card);
 5864|    514|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    514|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    514|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    514|	int _ret = (r); \
  |  |  |  |  178|    514|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 121, False: 393]
  |  |  |  |  ------------------
  |  |  |  |  179|    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
  |  |  |  |  ------------------
  |  |  |  |  180|    121|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    121|		goto err; \
  |  |  |  |  182|    121|	} \
  |  |  |  |  183|    514|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 393]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5865|    514|		}
 5866|  5.06k|	} else {
 5867|       |		/* piv_find_aid saves al_label from response */
 5868|  5.06k|		r = piv_find_aid(card);
 5869|  5.06k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  5.06k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.06k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.06k|	int _ret = (r); \
  |  |  |  |  178|  5.06k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.65k, False: 404]
  |  |  |  |  ------------------
  |  |  |  |  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.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 404]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5870|  5.06k|	}
 5871|       |
 5872|       |	/* Know to be PIV card but not the type */
 5873|       |
 5874|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5875|  1.11k|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5875:6): [True: 14, False: 1.09k]
  |  Branch (5875:24): [True: 12, False: 2]
  ------------------
 5876|     12|		switch (card->type) {
  ------------------
  |  Branch (5876:11): [True: 9, False: 3]
  ------------------
 5877|      9|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5877:3): [True: 9, False: 3]
  ------------------
 5878|      9|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5878:3): [True: 0, False: 12]
  ------------------
 5879|     24|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5879:16): [True: 17, False: 7]
  ------------------
 5880|     17|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5880:9): [True: 15, False: 2]
  ------------------
 5881|     15|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5881:7): [True: 2, False: 13]
  ------------------
 5882|      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__
  |  |  ------------------
  ------------------
 5883|      2|					card->type = al_map[i].al_type;
 5884|      2|					break;
 5885|      2|				}
 5886|     17|			}
 5887|      9|			break;
 5888|     12|		}
 5889|     12|	}
 5890|       |
 5891|  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__
  |  |  ------------------
  ------------------
 5892|  1.11k|			card->type, priv->card_issues, r, priv->alg_ids);
 5893|       |
 5894|       |	/*
 5895|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5896|       |	 * via ATR, ATR Historic bytes or Application Label
 5897|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5898|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5899|       |	 */
 5900|  1.11k|	switch (card->type) {
  ------------------
  |  Branch (5900:10): [True: 927, False: 184]
  ------------------
 5901|    275|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5901:2): [True: 275, False: 836]
  ------------------
 5902|    493|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5902:2): [True: 218, False: 893]
  ------------------
 5903|    509|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5903:2): [True: 16, False: 1.09k]
  ------------------
 5904|    524|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5904:2): [True: 15, False: 1.09k]
  ------------------
 5905|    525|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5905:2): [True: 1, False: 1.11k]
  ------------------
 5906|    526|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5906:2): [True: 1, False: 1.11k]
  ------------------
 5907|    526|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5907:2): [True: 0, False: 1.11k]
  ------------------
 5908|    927|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5908:2): [True: 401, False: 710]
  ------------------
 5909|    927|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    927|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5910|    927|		apdu.lc = 0;
 5911|    927|		apdu.data = NULL;
 5912|    927|		apdu.datalen = 0;
 5913|    927|		apdu.resp = yubico_version_buf;
 5914|    927|		apdu.resplen = sizeof(yubico_version_buf);
 5915|    927|		apdu.le = apdu.resplen;
 5916|    927|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5917|    927|		if (r2 == SC_SUCCESS && apdu.resplen == 3) {
  ------------------
  |  |   28|  1.85k|#define SC_SUCCESS				0
  ------------------
  |  Branch (5917:7): [True: 922, False: 5]
  |  Branch (5917:27): [True: 542, False: 380]
  ------------------
 5918|    542|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5919|    542|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    542|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5920|    542|			if (priv->yubico_version == 1) {
  ------------------
  |  Branch (5920:8): [True: 3, False: 539]
  ------------------
 5921|      3|				sc_log(card->ctx, "Detected Alpha/development version of yubikey. Assuming v6");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5922|      3|				priv->yubico_version = 0x060000;
 5923|      3|			}
 5924|    542|		}
 5925|    927|		break;
 5926|  1.11k|	}
 5927|       |
 5928|  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__
  |  |  ------------------
  ------------------
 5929|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5930|       |
 5931|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5932|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5933|  1.11k|	switch (card->type) {
  ------------------
  |  Branch (5933:10): [True: 492, False: 619]
  ------------------
 5934|       |	/*
 5935|       |	 * For cards that may also be CAC, try and read the CCC
 5936|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5937|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5938|       |	 */
 5939|    401|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5939:2): [True: 401, False: 710]
  ------------------
 5940|    401|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5940:2): [True: 0, False: 1.11k]
  ------------------
 5941|    485|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5941:2): [True: 84, False: 1.02k]
  ------------------
 5942|    485|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5942:2): [True: 0, False: 1.11k]
  ------------------
 5943|    485|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5943:2): [True: 0, False: 1.11k]
  ------------------
 5944|    492|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5944:2): [True: 7, False: 1.10k]
  ------------------
 5945|    492|		r2 = piv_process_ccc(card);
 5946|    492|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    492|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5947|    492|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5948|       |		/* Ignore any error. */
 5949|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5950|    492|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  174|    492|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5950:7): [True: 7, False: 485]
  ------------------
 5951|      7|			switch (card->type) {
  ------------------
  |  Branch (5951:12): [True: 7, False: 0]
  ------------------
 5952|      1|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5952:4): [True: 1, False: 6]
  ------------------
 5953|      1|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5953:4): [True: 0, False: 7]
  ------------------
 5954|      6|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5954:4): [True: 5, False: 2]
  ------------------
 5955|      6|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5955:4): [True: 0, False: 7]
  ------------------
 5956|      6|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5957|      6|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|      6|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5958|      6|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      6|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5959|      6|				break;
 5960|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5960:4): [True: 0, False: 7]
  ------------------
 5961|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5962|      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 */
  ------------------
 5963|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5964|      0|				break;
 5965|      1|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5965:4): [True: 1, False: 6]
  ------------------
 5966|      1|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5967|      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 */
  ------------------
 5968|      1|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      1|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5969|      1|				break;
 5970|      7|			}
 5971|      7|		}
 5972|    492|		break;
 5973|       |
 5974|    492|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5974:2): [True: 0, False: 1.11k]
  ------------------
 5975|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5975:2): [True: 0, False: 1.11k]
  ------------------
 5976|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5976:2): [True: 0, False: 1.11k]
  ------------------
 5977|      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 */
  ------------------
 5978|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5979|      0|		break;
 5980|  1.11k|	}
 5981|  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__
  |  |  ------------------
  ------------------
 5982|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5983|       |
 5984|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5985|  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|    314|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5985:6): [True: 314, False: 797]
  |  Branch (5985:51): [True: 0, False: 314]
  ------------------
 5986|      0|		r2 = piv_find_aid(card);
 5987|      0|	}
 5988|       |
 5989|       |	/* Read AID if needed for these cards types */
 5990|  1.11k|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  380|  1.11k|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5990:6): [True: 314, False: 797]
  ------------------
 5991|    314|		switch (card->type) {
  ------------------
  |  Branch (5991:11): [True: 31, False: 283]
  ------------------
 5992|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5992:3): [True: 0, False: 314]
  ------------------
 5993|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5993:3): [True: 0, False: 314]
  ------------------
 5994|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5994:3): [True: 0, False: 314]
  ------------------
 5995|     16|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5995:3): [True: 16, False: 298]
  ------------------
 5996|     31|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5996:3): [True: 15, False: 299]
  ------------------
 5997|     31|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5997:3): [True: 0, False: 314]
  ------------------
 5998|     31|		case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (5998:3): [True: 0, False: 314]
  ------------------
 5999|       |
 6000|     31|			r2 = piv_find_aid(card);
 6001|    314|		}
 6002|    314|	}
 6003|       |
 6004|  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__
  |  |  ------------------
  ------------------
 6005|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6006|       |
 6007|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 6008|  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 (6008:6): [True: 1.10k, False: 2]
  ------------------
 6009|  1.10k|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  617|  1.10k|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  608|  1.10k|#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.10k|#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.10k|#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.10k|#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.10k|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 6010|  1.10k|	}
 6011|       |
 6012|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 6013|  1.11k|	switch (card->type) {
  ------------------
  |  Branch (6013:10): [True: 400, False: 711]
  ------------------
 6014|    400|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (6014:2): [True: 400, False: 711]
  ------------------
 6015|    400|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (6015:2): [True: 0, False: 1.11k]
  ------------------
 6016|    400|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  381|    400|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (6016:7): [True: 0, False: 400]
  ------------------
 6017|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 6018|      0|		}
 6019|       |
 6020|       |#ifdef ENABLE_PIV_SM
 6021|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 6022|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 6023|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 6024|       |		}
 6025|       |#endif
 6026|    400|		break;
 6027|  1.11k|	}
 6028|       |
 6029|  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__
  |  |  ------------------
  ------------------
 6030|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6031|       |
 6032|       |	/*
 6033|       |	 * Set card_issues flags based card->type and version numbers if available.
 6034|       |	 *
 6035|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 6036|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 6037|       |	 * access to all the different devices or versions of the devices.
 6038|       |	 * Vendor and user input is welcome on any compliance issues.
 6039|       |	 *
 6040|       |	 * For the Yubico devices The assumption is also made that if a bug is
 6041|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 6042|       |	 *
 6043|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 6044|       |	 * may be set earlier or later then in the following code.
 6045|       |	 */
 6046|       |
 6047|  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__
  |  |  ------------------
  ------------------
 6048|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6049|  1.11k|	switch (card->type) {
 6050|    275|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (6050:2): [True: 275, False: 836]
  ------------------
 6051|    275|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  603|    275|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 6052|    275|				     CI_VERIFY_630X |
  ------------------
  |  |  591|    275|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 6053|    275|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|    275|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6054|    275|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  596|    275|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6055|    275|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  601|    275|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 6056|    275|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (6056:7): [True: 192, False: 83]
  ------------------
 6057|    192|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  592|    192|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6058|    275|		break;
 6059|       |
 6060|      1|	case SC_CARD_TYPE_PIV_II_OPENFIPS201:
  ------------------
  |  Branch (6060:2): [True: 1, False: 1.11k]
  ------------------
 6061|       |		/* also supports using yubico-piv-tool */
 6062|      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 */
  ------------------
 6063|      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!!! */
  ------------------
 6064|      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 */
  ------------------
 6065|      1|		break;
 6066|       |
 6067|    218|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (6067:2): [True: 218, False: 893]
  ------------------
 6068|    219|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (6068:2): [True: 1, False: 1.11k]
  ------------------
 6069|    234|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (6069:2): [True: 15, False: 1.09k]
  ------------------
 6070|    234|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  600|    234|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6071|    234|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  596|    234|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 6072|    234|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (6072:7): [True: 56, False: 178]
  ------------------
 6073|     56|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  592|     56|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6074|    234|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (6074:7): [True: 169, False: 65]
  ------------------
 6075|    169|			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  611|    169|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  614|    169|#define AI_25519			    0x00100000U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519 | AI_X25519;
  ------------------
  |  |  615|    169|#define AI_X25519			    0x00200000U
  ------------------
 6076|    234|		break;
 6077|       |
 6078|     16|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (6078:2): [True: 16, False: 1.09k]
  ------------------
 6079|     16|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|     16|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6080|     16|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (6080:7): [True: 10, False: 6]
  ------------------
 6081|     10|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  611|     10|#define AI_RSA_4096			    0x00000008U
  ------------------
 6082|     16|		break;
 6083|       |
 6084|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (6084:2): [True: 0, False: 1.11k]
  ------------------
 6085|      6|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (6085:2): [True: 6, False: 1.10k]
  ------------------
 6086|      6|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (6086:2): [True: 0, False: 1.11k]
  ------------------
 6087|      6|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (6087:2): [True: 0, False: 1.11k]
  ------------------
 6088|      6|		priv->card_issues |= 0; /* could add others here */
 6089|      6|		break;
 6090|       |
 6091|    400|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (6091:2): [True: 400, False: 711]
  ------------------
 6092|    479|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (6092:2): [True: 79, False: 1.03k]
  ------------------
 6093|    479|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (6093:2): [True: 0, False: 1.11k]
  ------------------
 6094|    479|		priv->card_issues |= 0; /* could add others here */
 6095|    479|		break;
 6096|       |
 6097|      6|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (6097:2): [True: 6, False: 1.10k]
  ------------------
 6098|      6|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (6098:2): [True: 0, False: 1.11k]
  ------------------
 6099|      7|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (6099:2): [True: 1, False: 1.11k]
  ------------------
 6100|      7|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|      7|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6101|      7|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  598|      7|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 6102|      7|				     CI_NO_RANDOM |
  ------------------
  |  |  594|      7|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 6103|      7|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  600|      7|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 6104|      7|		break;
 6105|       |
 6106|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (6106:2): [True: 0, False: 1.11k]
  ------------------
 6107|      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 */
  ------------------
 6108|      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!!! */
  ------------------
 6109|      0|		break;
 6110|       |
 6111|     93|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (6111:2): [True: 93, False: 1.01k]
  ------------------
 6112|     93|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  592|     93|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 6113|     93|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  598|     93|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 6114|     93|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  594|     93|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 6115|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 6116|     93|		break;
 6117|       |
 6118|      0|	default:
  ------------------
  |  Branch (6118:2): [True: 0, False: 1.11k]
  ------------------
 6119|      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 */
  ------------------
 6120|      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!!! */
  ------------------
 6121|       |		/* opensc.conf may have it wrong, continue anyway */
 6122|      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__
  |  |  ------------------
  ------------------
 6123|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 6124|  1.11k|	}
 6125|  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__
  |  |  ------------------
  ------------------
 6126|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6127|       |
 6128|  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.10k|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (6128:6): [True: 1.10k, False: 7]
  |  Branch (6128:53): [True: 791, False: 313]
  ------------------
 6129|       |		/*
 6130|       |		 * We now know PIV AID is active, test DISCOVERY object again
 6131|       |		 * Some PIV don't support DISCOVERY and return
 6132|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 6133|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 6134|       |		 * to test for active AID.
 6135|       |		 */
 6136|    791|		r2 = piv_find_discovery(card);
 6137|       |
 6138|    791|		if (r2 < 0) {
  ------------------
  |  Branch (6138:7): [True: 700, False: 91]
  ------------------
 6139|    700|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  597|    700|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 6140|    700|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  153|    700|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 6141|    700|		}
 6142|    791|	}
 6143|       |
 6144|  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__
  |  |  ------------------
  ------------------
 6145|  1.11k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6146|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 6147|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6148|       |
 6149|  4.77k|err:
 6150|  4.77k|	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.77k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6151|  4.77k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 6152|       |	/* don't match. Does not have a PIV applet. */
 6153|  4.77k|	piv_finish(card);
 6154|  4.77k|	card->type = saved_type;
 6155|  4.77k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.77k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.77k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.77k|	int _ret = r; \
  |  |  |  |  155|  4.77k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.77k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  4.77k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.77k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.77k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.77k|	return _ret; \
  |  |  |  |  163|  4.77k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6156|  4.77k|}
card-piv.c:piv_find_discovery:
 5286|  5.51k|{
 5287|  5.51k|	int r = 0;
 5288|  5.51k|	size_t rbuflen;
 5289|  5.51k|	u8 *rbuf = NULL;
 5290|  5.51k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  5.51k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5291|       |
 5292|  5.51k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 5293|       |
 5294|       |	/*
 5295|       |	 * During piv_card_reader_lock_obtained,
 5296|       |	 * we use the discovery object to test if card present, and
 5297|       |	 * if PIV AID is active.
 5298|       |	 */
 5299|  5.51k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  5.51k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5299:6): [True: 0, False: 5.51k]
  ------------------
 5300|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5301|      0|		goto end;
 5302|      0|	}
 5303|       |
 5304|       |	/* If not valid: read, test,  cache */
 5305|  5.51k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  151|  5.51k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5305:6): [True: 1.61k, False: 3.89k]
  ------------------
 5306|  1.61k|		r = piv_process_discovery(card);
 5307|  3.89k|	} else {
 5308|       |		/* if already in cache,force read */
 5309|  3.89k|		rbuflen = 1;
 5310|  3.89k|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5311|       |		/* if same response as last, no need to parse */
 5312|  3.89k|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5312:7): [True: 0, False: 3.89k]
  |  Branch (5312:17): [True: 0, False: 0]
  ------------------
 5313|      0|			goto end;
 5314|       |
 5315|  3.89k|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5315:7): [True: 60, False: 3.83k]
  |  Branch (5315:17): [True: 49, False: 11]
  ------------------
 5316|     49|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5316:5): [True: 49, False: 0]
  ------------------
 5317|     49|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5317:5): [True: 18, False: 31]
  ------------------
 5318|     18|			goto end;
 5319|     18|		}
 5320|       |		/* This should not happen  bad card */
 5321|  3.87k|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|  3.87k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5322|  3.87k|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  3.87k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5323|  3.87k|		goto end;
 5324|  3.89k|	}
 5325|       |
 5326|  5.51k|end:
 5327|  5.51k|	free(rbuf);
 5328|  5.51k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  5.51k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.51k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.51k|	int _ret = r; \
  |  |  |  |  155|  5.51k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.49k, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.49k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.09k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.09k, False: 405]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.49k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.49k|	} else { \
  |  |  |  |  159|     18|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     18|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     18|	} \
  |  |  |  |  162|  5.51k|	return _ret; \
  |  |  |  |  163|  5.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5329|  5.51k|}
card-piv.c:piv_process_discovery:
 5179|  1.61k|{
 5180|  1.61k|	int r;
 5181|  1.61k|	u8 *rbuf = NULL;
 5182|  1.61k|	size_t rbuflen = 0;
 5183|       |
 5184|  1.61k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5185|       |	/* Note rbuf and rbuflen are now pointers into cache */
 5186|  1.61k|	if (r < 0)
  ------------------
  |  Branch (5186:6): [True: 1.17k, False: 447]
  ------------------
 5187|  1.17k|		goto err;
 5188|       |
 5189|       |	/* the object is now cached, see what we have */
 5190|    447|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 5191|       |
 5192|  1.61k|err:
 5193|  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.21k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.21k, False: 405]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5194|  1.61k|}
card-piv.c:piv_get_cached_data:
 3213|  16.1k|{
 3214|       |
 3215|  16.1k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  16.1k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3216|  16.1k|	int r;
 3217|  16.1k|	u8 *rbuf = NULL;
 3218|  16.1k|	size_t rbuflen;
 3219|       |
 3220|  16.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  16.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  16.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  16.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16.1k]
  |  |  ------------------
  ------------------
 3221|       |
 3222|  16.1k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3222:6): [True: 0, False: 16.1k]
  |  Branch (3222:21): [True: 0, False: 16.1k]
  ------------------
 3223|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3224|       |
 3225|  16.1k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 3226|       |
 3227|       |	/* see if we have it cached */
 3228|  16.1k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  151|  16.1k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3228:6): [True: 2.46k, False: 13.6k]
  ------------------
 3229|       |
 3230|  2.46k|		sc_log(card->ctx, "found #%d %p:%zu %p:%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3231|  2.46k|				enumtag,
 3232|  2.46k|				priv->obj_cache[enumtag].obj_data,
 3233|  2.46k|				priv->obj_cache[enumtag].obj_len,
 3234|  2.46k|				priv->obj_cache[enumtag].internal_obj_data,
 3235|  2.46k|				priv->obj_cache[enumtag].internal_obj_len);
 3236|       |
 3237|  2.46k|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3237:7): [True: 0, False: 2.46k]
  ------------------
 3238|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3239|      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__
  |  |  ------------------
  ------------------
 3240|      0|			goto err;
 3241|      0|		}
 3242|  2.46k|		*buf = priv->obj_cache[enumtag].obj_data;
 3243|  2.46k|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3244|  2.46k|		r = (int)*buf_len;
 3245|  2.46k|		goto ok;
 3246|  2.46k|	}
 3247|       |
 3248|       |	/*
 3249|       |	 * If we know it can not be on the card  i.e. History object
 3250|       |	 * has been read, and we know what other certs may or
 3251|       |	 * may not be on the card. We can avoid extra overhead
 3252|       |	 * Also used if object on card was not parsable
 3253|       |	 */
 3254|       |
 3255|  13.6k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  153|  13.6k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3255:6): [True: 0, False: 13.6k]
  ------------------
 3256|      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__
  |  |  ------------------
  ------------------
 3257|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3258|      0|		goto err;
 3259|      0|	}
 3260|       |
 3261|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3262|  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__
  |  |  ------------------
  ------------------
 3263|  13.6k|	rbuflen = 1;
 3264|  13.6k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3265|  13.6k|	if (r > 0) {
  ------------------
  |  Branch (3265:6): [True: 3.43k, False: 10.2k]
  ------------------
 3266|  3.43k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  3.43k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3267|  3.43k|		priv->obj_cache[enumtag].obj_len = r;
 3268|  3.43k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3269|  3.43k|		*buf = rbuf;
 3270|  3.43k|		*buf_len = r;
 3271|       |
 3272|  3.43k|		sc_log(card->ctx, "added #%d  %p:%zu %p:%zu",
  ------------------
  |  |   71|  3.43k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3273|  3.43k|				enumtag,
 3274|  3.43k|				priv->obj_cache[enumtag].obj_data,
 3275|  3.43k|				priv->obj_cache[enumtag].obj_len,
 3276|  3.43k|				priv->obj_cache[enumtag].internal_obj_data,
 3277|  3.43k|				priv->obj_cache[enumtag].internal_obj_len);
 3278|       |
 3279|  10.2k|	} else {
 3280|  10.2k|		free(rbuf);
 3281|  10.2k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  10.2k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3281:7): [True: 0, False: 10.2k]
  |  Branch (3281:17): [True: 1.90k, False: 8.33k]
  ------------------
 3282|  1.90k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.90k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3283|  1.90k|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|  1.90k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3284|  1.90k|			priv->obj_cache[enumtag].obj_len = 0;
 3285|  8.33k|		} else {
 3286|  8.33k|			goto err;
 3287|  8.33k|		}
 3288|  10.2k|	}
 3289|  7.80k|ok:
 3290|       |
 3291|  16.1k|err:
 3292|  16.1k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  16.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.1k|	int _ret = r; \
  |  |  |  |  155|  16.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.2k, False: 5.90k]
  |  |  |  |  ------------------
  |  |  |  |  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.90k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  5.90k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  5.90k|	} \
  |  |  |  |  162|  16.1k|	return _ret; \
  |  |  |  |  163|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3293|  16.1k|}
card-piv.c:piv_parse_discovery:
 5123|    447|{
 5124|    447|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|    447|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5125|    447|	int r = 0;
 5126|    447|	const u8 *body;
 5127|    447|	size_t bodylen;
 5128|    447|	const u8 *aid;
 5129|    447|	size_t aidlen;
 5130|    447|	const u8 *pinp;
 5131|    447|	size_t pinplen;
 5132|    447|	unsigned int cla_out, tag_out;
 5133|       |
 5134|    447|	if (rbuflen != 0) {
  ------------------
  |  Branch (5134:6): [True: 447, False: 0]
  ------------------
 5135|    447|		body = rbuf;
 5136|    447|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    894|#define SC_SUCCESS				0
  ------------------
  |  Branch (5136:7): [True: 0, False: 447]
  ------------------
 5137|    447|				body == NULL ||
  ------------------
  |  Branch (5137:5): [True: 0, False: 447]
  ------------------
 5138|    447|				bodylen == 0 ||
  ------------------
  |  Branch (5138:5): [True: 2, False: 445]
  ------------------
 5139|    445|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (5139:5): [True: 0, False: 445]
  ------------------
 5140|      2|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5141|      2|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      2|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5142|      2|			goto err;
 5143|      2|		}
 5144|       |
 5145|    445|		sc_log(card->ctx, "Discovery 0x%2.2x 0x%2.2x %p:%zu",
  ------------------
  |  |   71|    445|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5146|    445|				cla_out, tag_out, body, bodylen);
 5147|    445|		aidlen = 0;
 5148|    445|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 5149|    445|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (5149:7): [True: 14, False: 431]
  |  Branch (5149:22): [True: 1, False: 430]
  ------------------
 5150|    430|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (5150:5): [True: 25, False: 405]
  ------------------
 5151|     40|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   71|     40|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5152|     40|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     40|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 5153|     40|			goto err;
 5154|     40|		}
 5155|    405|		if (aid_only == 0) {
  ------------------
  |  Branch (5155:7): [True: 405, False: 0]
  ------------------
 5156|    405|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 5157|    405|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (5157:8): [True: 212, False: 193]
  |  Branch (5157:16): [True: 204, False: 8]
  ------------------
 5158|    204|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  383|    204|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 5159|    204|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 5160|    204|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5161|    204|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|    204|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|    204|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  371|    204|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  372|    204|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (5161:9): [True: 9, False: 195]
  ------------------
 5162|      9|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  377|      9|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (5162:7): [True: 5, False: 4]
  ------------------
 5163|      5|					sc_log(card->ctx, "Pin Preference - Global");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 5164|      5|					priv->pin_preference = 0x00;
 5165|      5|				}
 5166|    204|			}
 5167|    405|		}
 5168|    405|		r = SC_SUCCESS;
  ------------------
  |  |   28|    405|#define SC_SUCCESS				0
  ------------------
 5169|    405|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  382|    405|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 5170|    405|	}
 5171|       |
 5172|    447|err:
 5173|    447|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    447|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    447|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    447|	int _ret = r; \
  |  |  |  |  155|    447|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 447, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    447|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 405]
  |  |  |  |  ------------------
  |  |  |  |  157|    447|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    447|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    447|	return _ret; \
  |  |  |  |  163|    447|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5174|    447|}
card-piv.c:piv_get_data:
 3103|  17.6k|{
 3104|  17.6k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  17.6k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3105|  17.6k|	u8 *p;
 3106|  17.6k|	u8 *tbuf;
 3107|  17.6k|	int r = 0;
 3108|  17.6k|	u8 tagbuf[8];
 3109|  17.6k|	size_t tag_len;
 3110|  17.6k|	int alloc_buf = 0;
 3111|       |
 3112|  17.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  17.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  17.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  17.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 17.6k]
  |  |  ------------------
  ------------------
 3113|       |
 3114|  17.6k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  17.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__
  |  |  ------------------
  ------------------
 3115|       |
 3116|  17.6k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3117|  17.6k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  17.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3117:6): [True: 0, False: 17.6k]
  ------------------
 3118|      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__
  |  |  ------------------
  ------------------
 3119|      0|		return r;
 3120|      0|	}
 3121|       |
 3122|  17.6k|	tag_len = piv_objects[enumtag].tag_len;
 3123|       |
 3124|  17.6k|	p = tagbuf;
 3125|  17.6k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3126|  17.6k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  17.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3126:6): [True: 0, False: 17.6k]
  ------------------
 3127|      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__
  |  |  ------------------
  ------------------
 3128|      0|		goto err;
 3129|      0|	}
 3130|       |
 3131|  17.6k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3131:6): [True: 17.5k, False: 37]
  |  Branch (3131:23): [True: 17.5k, False: 0]
  ------------------
 3132|  17.5k|		*buf_len = priv->max_object_size; /* will allocate below */
 3133|  17.5k|		alloc_buf = 1;
 3134|  17.5k|	}
 3135|       |
 3136|  17.6k|	sc_log(card->ctx, "buffer for #%d *buf=0x%p len=%zu", enumtag, *buf, *buf_len);
  ------------------
  |  |   71|  17.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__
  |  |  ------------------
  ------------------
 3137|  17.6k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3137:6): [True: 17.5k, False: 37]
  |  Branch (3137:22): [True: 17.5k, False: 0]
  ------------------
 3138|  17.5k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  17.5k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3138:7): [True: 0, False: 17.5k]
  ------------------
 3139|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3140|      0|			goto err;
 3141|      0|		}
 3142|  17.5k|		*buf = malloc(*buf_len);
 3143|  17.5k|		if (*buf == NULL) {
  ------------------
  |  Branch (3143:7): [True: 0, False: 17.5k]
  ------------------
 3144|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3145|      0|			goto err;
 3146|      0|		}
 3147|  17.5k|	}
 3148|       |
 3149|       |#ifdef ENABLE_PIV_SM
 3150|       |	/*
 3151|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3152|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3153|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3154|       |	 * i.e. no interference from other applications
 3155|       |	 */
 3156|       |	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",
 3157|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3158|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3159|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3160|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3161|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3162|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3163|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3164|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3165|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3166|       |	}
 3167|       |
 3168|       |#endif /* ENABLE_PIV_SM */
 3169|  17.6k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3170|  17.6k|	if (r > 0) {
  ------------------
  |  Branch (3170:6): [True: 4.67k, False: 12.9k]
  ------------------
 3171|  4.67k|		int r_tag;
 3172|  4.67k|		unsigned int cla_out, tag_out;
 3173|  4.67k|		size_t bodylen = 0;
 3174|  4.67k|		const u8 *body = *buf;
 3175|  4.67k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3176|  4.67k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  9.34k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3176:7): [True: 710, False: 3.96k]
  |  Branch (3176:30): [True: 88, False: 3.87k]
  ------------------
 3177|  3.87k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3177:5): [True: 381, False: 3.49k]
  ------------------
 3178|  1.17k|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|  1.17k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3179|  1.17k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.17k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3180|  1.17k|			goto err;
 3181|  1.17k|		}
 3182|  3.49k|		*buf_len = (body - *buf) + bodylen;
 3183|  12.9k|	} else if (r == 0) {
  ------------------
  |  Branch (3183:13): [True: 583, False: 12.3k]
  ------------------
 3184|    583|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    583|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3185|    583|		goto err;
 3186|  12.3k|	} else {
 3187|  12.3k|		goto err;
 3188|  12.3k|	}
 3189|       |
 3190|  3.49k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3190:6): [True: 3.49k, False: 2]
  |  Branch (3190:19): [True: 3.49k, False: 0]
  ------------------
 3191|  3.49k|		tbuf = malloc(r);
 3192|  3.49k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3192:7): [True: 0, False: 3.49k]
  ------------------
 3193|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3194|      0|			goto err;
 3195|      0|		}
 3196|  3.49k|		memcpy(tbuf, *buf, r);
 3197|  3.49k|		free(*buf);
 3198|  3.49k|		alloc_buf = 0;
 3199|  3.49k|		*buf = tbuf;
 3200|  3.49k|	}
 3201|       |
 3202|  17.6k|err:
 3203|  17.6k|	if (alloc_buf) {
  ------------------
  |  Branch (3203:6): [True: 14.0k, False: 3.52k]
  ------------------
 3204|  14.0k|		free(*buf);
 3205|  14.0k|		*buf = NULL;
 3206|  14.0k|	}
 3207|  17.6k|	sc_unlock(card);
 3208|  17.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  17.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.6k|	int _ret = r; \
  |  |  |  |  155|  17.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14.1k, False: 3.49k]
  |  |  |  |  ------------------
  |  |  |  |  156|  14.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|  14.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  14.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.1k|	} else { \
  |  |  |  |  159|  3.49k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.49k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.49k|	} \
  |  |  |  |  162|  17.6k|	return _ret; \
  |  |  |  |  163|  17.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3209|  17.6k|}
card-piv.c:piv_general_io:
 1803|  32.1k|{
 1804|  32.1k|	int r, cse;
 1805|  32.1k|	sc_apdu_t apdu;
 1806|       |
 1807|  32.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  32.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  32.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  32.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 32.1k]
  |  |  ------------------
  ------------------
 1808|       |
 1809|  32.1k|	r = sc_lock(card);
 1810|  32.1k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  32.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1810:6): [True: 0, False: 32.1k]
  ------------------
 1811|  32.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1812|       |
 1813|  32.1k|	cse = recvbuf ? (sendbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_2_SHORT) :
  ------------------
  |  |  294|  20.8k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	cse = recvbuf ? (sendbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_2_SHORT) :
  ------------------
  |  |  292|  11.3k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  |  Branch (1813:8): [True: 32.1k, False: 0]
  |  Branch (1813:19): [True: 20.8k, False: 11.3k]
  ------------------
 1814|  32.1k|			(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.1k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
 1817|  32.1k|	if (sendbuflen > 255) {
  ------------------
  |  Branch (1817:6): [True: 204, False: 31.9k]
  ------------------
 1818|    204|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    204|#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|    204|	}
 1826|  32.1k|	apdu.lc = sendbuflen;
 1827|  32.1k|	apdu.datalen = sendbuflen;
 1828|  32.1k|	apdu.data = sendbuf;
 1829|       |
 1830|  32.1k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1830:6): [True: 32.1k, False: 0]
  |  Branch (1830:17): [True: 32.1k, False: 0]
  ------------------
 1831|  32.1k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1831:13): [True: 32.1k, False: 37]
  ------------------
 1832|  32.1k|		apdu.resplen = recvbuflen;
 1833|  32.1k|	} else {
 1834|      0|		apdu.le = 0;
 1835|      0|		apdu.resplen = 0;
 1836|      0|	}
 1837|  32.1k|	apdu.resp = recvbuf;
 1838|       |
 1839|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1840|  32.1k|	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.1k|	if (r < 0) {
  ------------------
  |  Branch (1843:6): [True: 766, False: 31.4k]
  ------------------
 1844|    766|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    766|#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|    766|		goto err;
 1846|    766|	}
 1847|       |
 1848|  31.4k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1848:6): [True: 334, False: 31.0k]
  |  Branch (1848:26): [True: 33, False: 301]
  ------------------
 1849|     33|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     33|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1850|  31.3k|	else
 1851|  31.3k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1852|       |
 1853|  31.4k|	if (r < 0) {
  ------------------
  |  Branch (1853:6): [True: 24.4k, False: 6.99k]
  ------------------
 1854|  24.4k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  24.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__
  |  |  ------------------
  ------------------
 1855|  24.4k|		goto err;
 1856|  24.4k|	}
 1857|       |
 1858|  6.99k|	r = (int)apdu.resplen;
 1859|       |
 1860|  32.1k|err:
 1861|  32.1k|	sc_unlock(card);
 1862|  32.1k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  32.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  32.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  32.1k|	int _ret = r; \
  |  |  |  |  155|  32.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.2k, False: 5.90k]
  |  |  |  |  ------------------
  |  |  |  |  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.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 25.1k, False: 1.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  26.2k|	} else { \
  |  |  |  |  159|  5.90k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  5.90k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  5.90k|	} \
  |  |  |  |  162|  32.1k|	return _ret; \
  |  |  |  |  163|  32.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1863|  32.1k|}
card-piv.c:piv_obj_cache_free_entry:
 5583|   354k|{
 5584|   354k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|   354k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5585|       |
 5586|   354k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5586:6): [True: 3.43k, False: 351k]
  ------------------
 5587|  3.43k|		free(priv->obj_cache[enumtag].obj_data);
 5588|   354k|	priv->obj_cache[enumtag].obj_data = NULL;
 5589|   354k|	priv->obj_cache[enumtag].obj_len = 0;
 5590|       |
 5591|   354k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5591:6): [True: 2.46k, False: 352k]
  ------------------
 5592|  2.46k|		free(priv->obj_cache[enumtag].internal_obj_data);
 5593|   354k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5594|   354k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5595|   354k|	priv->obj_cache[enumtag].flags = flags;
 5596|       |
 5597|   354k|	return SC_SUCCESS;
  ------------------
  |  |   28|   354k|#define SC_SUCCESS				0
  ------------------
 5598|   354k|}
card-piv.c:piv_find_aid:
 2914|  6.69k|{
 2915|  6.69k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  6.69k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2916|  6.69k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2917|  6.69k|	int r, i, j;
 2918|  6.69k|	const u8 *tag;
 2919|  6.69k|	size_t taglen;
 2920|  6.69k|	const u8 *nextac;
 2921|  6.69k|	const u8 *next80;
 2922|  6.69k|	const u8 *pix;
 2923|  6.69k|	size_t pixlen;
 2924|  6.69k|	const u8 *al_label;
 2925|  6.69k|	size_t al_labellen;
 2926|  6.69k|	const u8 *actag; /* Cipher Suite */
 2927|  6.69k|	size_t actaglen;
 2928|  6.69k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2929|  6.69k|	size_t csailen;
 2930|  6.69k|	size_t resplen = sizeof(rbuf);
 2931|       |#ifdef ENABLE_PIV_SM
 2932|       |	int found_csai = 0;
 2933|       |#endif
 2934|       |
 2935|  6.69k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.69k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.69k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.69k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.69k]
  |  |  ------------------
  ------------------
 2936|       |
 2937|       |	/* first  see if the default application will return a template
 2938|       |	 * that we know about.
 2939|       |	 */
 2940|       |
 2941|  6.69k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2942|  6.69k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2942:6): [True: 0, False: 6.69k]
  |  Branch (2942:15): [True: 0, False: 0]
  |  Branch (2942:38): [True: 0, False: 0]
  |  Branch (2942:70): [True: 0, False: 0]
  ------------------
 2943|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2944|       |		/* no need to parse again, same as last time */
 2945|      0|	}
 2946|  6.69k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2946:6): [True: 1.01k, False: 5.67k]
  |  Branch (2946:16): [True: 925, False: 91]
  ------------------
 2947|    925|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2948|    925|		if (tag != NULL) {
  ------------------
  |  Branch (2948:7): [True: 868, False: 57]
  ------------------
 2949|    868|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  380|    868|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2950|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2951|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2952|       |			 * where xx is the SM csID either 27 or 2E.
 2953|       |			 * Some vendors may include entries for supported Algorithms even when
 2954|       |			 * not required. We will use these if possible
 2955|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2956|       |			 */
 2957|    868|			nextac = tag;
 2958|    905|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2958:11): [True: 37, False: 868]
  ------------------
 2959|    905|						0xAC, &actaglen)) != NULL) {
 2960|     37|				nextac = actag + actaglen;
 2961|       |
 2962|     37|				next80 = actag;
 2963|     98|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2963:12): [True: 61, False: 37]
  ------------------
 2964|     98|							0x80, &csailen)) != NULL) {
 2965|     61|					next80 = csai + csailen;
 2966|     61|					if (csailen == 1) {
  ------------------
  |  Branch (2966:10): [True: 26, False: 35]
  ------------------
 2967|     26|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2968|     26|						j = piv_ai_map_find_by_id(card, *csai);
 2969|     26|						if (j >= 0) {
  ------------------
  |  Branch (2969:11): [True: 15, False: 11]
  ------------------
 2970|     15|							priv->alg_ids |= ai_map[j].ai_flag;
 2971|     15|							continue;
 2972|     15|						}
 2973|       |#ifdef ENABLE_PIV_SM
 2974|       |						/* check if id is NIST SM */
 2975|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2976|       |							if (*csai != css[i].id)
 2977|       |								continue;
 2978|       |							if (found_csai) {
 2979|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2980|       |							} else {
 2981|       |								priv->cs = &css[i];
 2982|       |								priv->csID = *csai;
 2983|       |								found_csai++;
 2984|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2985|       |							}
 2986|       |						}
 2987|       |#endif /* ENABLE_PIV_SM */
 2988|     26|					}
 2989|     61|				}
 2990|     37|			}
 2991|       |
 2992|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2993|    868|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2994|    868|			if (al_label != NULL) {
  ------------------
  |  Branch (2994:8): [True: 14, False: 854]
  ------------------
 2995|     14|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  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__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2996|     14|				free(priv->al_label);
 2997|     14|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2997:9): [True: 0, False: 14]
  ------------------
 2998|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2999|      0|				}
 3000|     14|				memcpy(priv->al_label, al_label, al_labellen);
 3001|     14|				priv->al_labellen = (int)al_labellen;
 3002|     14|			}
 3003|       |
 3004|    868|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 3005|    868|			if (pix != NULL) {
  ------------------
  |  Branch (3005:8): [True: 834, False: 34]
  ------------------
 3006|    834|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    834|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3007|       |
 3008|       |				/* early cards returned full AID, rather then just the pix */
 3009|    913|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (3009:17): [True: 881, False: 32]
  ------------------
 3010|    881|					if ((pixlen >= piv_aids[i].len_long - 5 &&
  ------------------
  |  Branch (3010:11): [True: 869, False: 12]
  ------------------
 3011|    869|							    memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (3011:12): [True: 465, False: 404]
  ------------------
 3012|    416|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (3012:10): [True: 387, False: 29]
  |  Branch (3012:45): [True: 337, False: 50]
  ------------------
 3013|    802|													     piv_aids[i].len_short) == 0))) {
 3014|    802|						free(priv->aid_der.value); /* free previous value if any */
 3015|    802|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (3015:11): [True: 0, False: 802]
  ------------------
 3016|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3017|      0|						}
 3018|    802|						memcpy(priv->aid_der.value, rbuf, resplen);
 3019|    802|						priv->aid_der.len = resplen;
 3020|    802|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|    802|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    802|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    802|	int _ret = r; \
  |  |  |  |  155|    802|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 787, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  156|    787|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 787]
  |  |  |  |  ------------------
  |  |  |  |  157|    787|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    787|	} 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|    802|	return _ret; \
  |  |  |  |  163|    802|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3021|    802|					}
 3022|    881|				}
 3023|    834|			}
 3024|    868|		}
 3025|    925|	}
 3026|       |
 3027|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3028|  5.89k|}
card-piv.c:piv_ai_map_find_by_id:
 2897|     26|{
 2898|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2899|     26|	int i;
 2900|       |
 2901|    181|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2901:14): [True: 170, False: 11]
  ------------------
 2902|    170|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2902:7): [True: 15, False: 155]
  ------------------
 2903|     15|			return i;
 2904|    170|	}
 2905|     11|	return -1;
 2906|     26|}
card-piv.c:piv_process_ccc:
 5267|    492|{
 5268|    492|	int r = 0;
 5269|    492|	u8 *rbuf = NULL;
 5270|    492|	size_t rbuflen = 0;
 5271|       |
 5272|    492|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    492|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    492|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    492|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 492]
  |  |  ------------------
  ------------------
 5273|    492|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5274|       |
 5275|    492|	if (r < 0)
  ------------------
  |  Branch (5275:6): [True: 422, False: 70]
  ------------------
 5276|    422|		goto err;
 5277|       |
 5278|       |	/* the object is now cached, see what we have */
 5279|     70|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5280|    492|err:
 5281|    492|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    492|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    492|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    492|	int _ret = r; \
  |  |  |  |  155|    492|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 492, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    492|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    479|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 479, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|    492|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    492|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    492|	return _ret; \
  |  |  |  |  163|    492|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5282|    492|}
card-piv.c:piv_parse_ccc:
 5203|     70|{
 5204|     70|	int r = 0;
 5205|     70|	const u8 *body;
 5206|     70|	size_t bodylen;
 5207|     70|	unsigned int cla_out, tag_out;
 5208|       |
 5209|     70|	u8 tag;
 5210|     70|	const u8 *end;
 5211|     70|	size_t len;
 5212|       |
 5213|     70|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     70|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5214|       |
 5215|     70|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     70|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     70|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     70|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 70]
  |  |  ------------------
  ------------------
 5216|       |
 5217|     70|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (5217:6): [True: 0, False: 70]
  |  Branch (5217:22): [True: 0, False: 70]
  ------------------
 5218|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 5219|      0|		goto err;
 5220|      0|	}
 5221|       |
 5222|       |	/* Outer layer is a DER tlv */
 5223|     70|	body = rbuf;
 5224|     70|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    140|#define SC_SUCCESS				0
  ------------------
  |  Branch (5224:6): [True: 0, False: 70]
  ------------------
 5225|     70|			body == NULL ||
  ------------------
  |  Branch (5225:4): [True: 0, False: 70]
  ------------------
 5226|     70|			bodylen == 0 ||
  ------------------
  |  Branch (5226:4): [True: 1, False: 69]
  ------------------
 5227|     69|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (5227:4): [True: 0, False: 69]
  ------------------
 5228|      1|		sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5229|      1|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5230|      1|		goto err;
 5231|      1|	}
 5232|       |
 5233|     69|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  170|     69|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5234|       |
 5235|       |	/* CCC  entries are simple tlv */
 5236|     69|	end = body + bodylen;
 5237|    626|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5237:9): [True: 613, False: 13]
  ------------------
 5238|    613|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len, SC_SIMPLETLV_LITTLE_ENDIAN);
 5239|    613|		if (r < 0)
  ------------------
  |  Branch (5239:7): [True: 56, False: 557]
  ------------------
 5240|     56|			goto err;
 5241|    557|		switch (tag) {
  ------------------
  |  Branch (5241:11): [True: 126, False: 431]
  ------------------
 5242|     70|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  176|     70|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5242:3): [True: 70, False: 487]
  ------------------
 5243|     70|			if (len == 0x15) {
  ------------------
  |  Branch (5243:8): [True: 52, False: 18]
  ------------------
 5244|     52|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5244:9): [True: 12, False: 40]
  ------------------
 5245|     12|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  171|     12|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5246|     40|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5246:14): [True: 12, False: 28]
  ------------------
 5247|     12|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  172|     12|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5248|     52|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5248:9): [True: 8, False: 44]
  ------------------
 5249|      8|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  173|      8|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5250|     52|			}
 5251|     70|			break;
 5252|     56|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  177|     56|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5252:3): [True: 56, False: 501]
  ------------------
 5253|     56|			if (len == 0x10) {
  ------------------
  |  Branch (5253:8): [True: 41, False: 15]
  ------------------
 5254|     41|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5254:9): [True: 13, False: 28]
  ------------------
 5255|     13|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  174|     13|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5256|     41|			}
 5257|     56|			break;
 5258|    557|		}
 5259|    557|	}
 5260|       |
 5261|     70|err:
 5262|     70|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|     57|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 57, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5263|     70|}
card-piv.c:piv_init:
 6160|  1.11k|{
 6161|  1.11k|	int r = 0;
 6162|  1.11k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.11k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6163|  1.11k|	unsigned long flags;
 6164|  1.11k|	unsigned long flags_eddsa;
 6165|  1.11k|	unsigned long flags_xeddsa;
 6166|  1.11k|	unsigned long ext_flags;
 6167|       |
 6168|  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]
  |  |  ------------------
  ------------------
 6169|       |
 6170|  1.11k|	r = sc_lock(card); /* hold until match or init is complete */
 6171|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6172|       |
 6173|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 6174|  1.11k|	if (priv == NULL) {
  ------------------
  |  Branch (6174:6): [True: 0, False: 1.11k]
  ------------------
 6175|      0|		r = piv_match_card_continued(card);
 6176|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  447|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6177|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (6177:7): [True: 0, False: 0]
  |  Branch (6177:16): [True: 0, False: 0]
  ------------------
 6178|      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__
  |  |  ------------------
  ------------------
 6179|      0|			sc_unlock(card);
 6180|      0|			piv_finish(card);
 6181|       |			/* tell sc_connect_card to try other driver */
 6182|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6183|      0|		}
 6184|      0|	}
 6185|       |
 6186|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 6187|  1.11k|	piv_load_options(card);
 6188|       |
 6189|  1.11k|	priv->pstate = PIV_STATE_INIT;
 6190|       |
 6191|  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__
  |  |  ------------------
  ------------------
 6192|  1.11k|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 6193|  1.11k|	card->cla = 0x00;
 6194|  1.11k|	if (card->name == NULL)
  ------------------
  |  Branch (6194:6): [True: 1.11k, False: 0]
  ------------------
 6195|  1.11k|		card->name = card->driver->name;
 6196|       |
 6197|  1.11k|	priv->enumtag = piv_aids[0].enumtag;
 6198|       |
 6199|       |	/* PKCS#11 may try to generate session keys, and get confused
 6200|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 6201|       |	 * piv-tool can still do this, just don't tell PKCS#11
 6202|       |	 */
 6203|       |
 6204|  1.11k|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|  1.11k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 6205|       |
 6206|  1.11k|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (6206:6): [True: 0, False: 1.11k]
  ------------------
 6207|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 6208|      0|	}
 6209|       |
 6210|  1.11k|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  608|  1.11k|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (6210:6): [True: 1.11k, False: 1]
  ------------------
 6211|  1.11k|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 6212|       |
 6213|  1.11k|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  609|  1.11k|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (6213:6): [True: 1.10k, False: 2]
  ------------------
 6214|  1.10k|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 6215|       |
 6216|  1.11k|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  610|  1.11k|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (6216:6): [True: 1.11k, False: 1]
  ------------------
 6217|  1.11k|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 6218|       |
 6219|  1.11k|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  611|  1.11k|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (6219:6): [True: 179, False: 932]
  ------------------
 6220|    179|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 6221|       |
 6222|  1.11k|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  604|  1.11k|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (6222:6): [True: 1.11k, False: 0]
  ------------------
 6223|  1.11k|		int i;
 6224|  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 */
  |  |  ------------------
  ------------------
 6225|  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
  ------------------
 6226|  1.11k|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  188|  1.11k|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 6227|  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
  ------------------
 6228|       |
 6229|  5.55k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (6229:15): [True: 4.44k, False: 1.11k]
  ------------------
 6230|  4.44k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  4.44k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (6230:8): [True: 2.22k, False: 2.22k]
  ------------------
 6231|  2.22k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  603|  4.44k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (6231:11): [True: 550, False: 1.67k]
  |  Branch (6231:46): [True: 275, False: 275]
  ------------------
 6232|  1.94k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 6233|  2.22k|			}
 6234|       |
 6235|  2.22k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  614|  4.44k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|    340|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (6235:13): [True: 340, False: 1.88k]
  |  Branch (6235:41): [True: 170, False: 170]
  ------------------
 6236|    170|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 6237|       |
 6238|  2.05k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  615|  4.10k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|    171|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (6238:13): [True: 171, False: 1.88k]
  |  Branch (6238:42): [True: 170, False: 1]
  ------------------
 6239|    170|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 6240|  4.44k|		}
 6241|  1.11k|	}
 6242|       |
 6243|  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 (6243:6): [True: 1.01k, False: 100]
  ------------------
 6244|  1.01k|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  550|  1.01k|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 6245|       |
 6246|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6247|  1.11k|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|  1.11k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6248|       |
 6249|       |	/*
 6250|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6251|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6252|       |	 */
 6253|       |
 6254|       |#ifdef ENABLE_PIV_SM
 6255|       |	/*
 6256|       |	 * 800-73-4
 6257|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6258|       |	 */
 6259|       |	if (priv->csID && priv->cs != NULL) {
 6260|       |		/*
 6261|       |		 * Main point in SM and VCI is to allow contactless access
 6262|       |		 */
 6263|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6264|       |
 6265|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6266|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6267|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6268|       |			r = SC_SUCCESS; /* Users choice */
 6269|       |
 6270|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6271|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6272|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6273|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6274|       |
 6275|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6276|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6277|       |				(priv->pairing_code[0] == 0x00)) {
 6278|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6279|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6280|       |
 6281|       |		} else {
 6282|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6283|       |			r = piv_sm_open(card);
 6284|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6285|       |		}
 6286|       |
 6287|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6288|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6289|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6290|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6291|       |		}
 6292|       |
 6293|       |		/* user has wrong or no required pairing code */
 6294|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6295|       |			LOG_FUNC_RETURN(card->ctx, r);
 6296|       |
 6297|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6298|       |	}
 6299|       |#endif /* ENABLE_PIV_SM */
 6300|       |
 6301|       |	/*
 6302|       |	 * 800-73-3 cards may have a history object
 6303|       |	 * We want to process it now as this has information on what
 6304|       |	 * keys and certs. "piv like" cards may or may not have history
 6305|       |	 */
 6306|  1.11k|	piv_process_history(card);
 6307|       |
 6308|  1.11k|	priv->pstate = PIV_STATE_NORMAL;
 6309|  1.11k|	sc_unlock(card);
 6310|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6311|  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.22k|	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:
 5339|  1.11k|{
 5340|  1.11k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.11k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5341|  1.11k|	int r;
 5342|  1.11k|	int i, tmplen, tmplen2, tmplen3;
 5343|  1.11k|	int enumtag;
 5344|  1.11k|	u8 *rbuf = NULL;
 5345|  1.11k|	size_t rbuflen = 0;
 5346|  1.11k|	const u8 *body;
 5347|  1.11k|	size_t bodylen;
 5348|  1.11k|	const u8 *num;
 5349|  1.11k|	size_t numlen;
 5350|  1.11k|	const u8 *url = NULL;
 5351|  1.11k|	size_t urllen;
 5352|  1.11k|	u8 *ocfhfbuf = NULL;
 5353|  1.11k|	unsigned int cla_out, tag_out;
 5354|  1.11k|	size_t ocfhflen;
 5355|  1.11k|	const u8 *seq;
 5356|  1.11k|	const u8 *seqtag;
 5357|  1.11k|	size_t seqlen;
 5358|  1.11k|	const u8 *keyref;
 5359|  1.11k|	size_t keyreflen;
 5360|  1.11k|	const u8 *cert;
 5361|  1.11k|	size_t certlen;
 5362|  1.11k|	size_t certobjlen, i2;
 5363|  1.11k|	u8 *certobj;
 5364|  1.11k|	u8 *cp;
 5365|       |
 5366|  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]
  |  |  ------------------
  ------------------
 5367|       |
 5368|  1.11k|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5369|  1.11k|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  1.11k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5369:6): [True: 173, False: 938]
  ------------------
 5370|    173|		r = 0; /* OK if not found */
 5371|  1.11k|	if (r <= 0) {
  ------------------
  |  Branch (5371:6): [True: 845, False: 266]
  ------------------
 5372|    845|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|    845|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5373|    845|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5374|    845|	}
 5375|       |
 5376|       |	/* the object is now cached, see what we have */
 5377|    266|	if (rbuflen != 0) {
  ------------------
  |  Branch (5377:6): [True: 266, False: 0]
  ------------------
 5378|    266|		body = rbuf;
 5379|    266|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    532|#define SC_SUCCESS				0
  ------------------
  |  Branch (5379:7): [True: 0, False: 266]
  ------------------
 5380|    266|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5380:5): [True: 0, False: 266]
  ------------------
 5381|      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__
  |  |  ------------------
  ------------------
 5382|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5383|      0|			goto err;
 5384|      0|		}
 5385|       |
 5386|    266|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5386:7): [True: 266, False: 0]
  |  Branch (5386:23): [True: 264, False: 2]
  ------------------
 5387|    264|			numlen = 0;
 5388|    264|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5389|    264|			if (num) {
  ------------------
  |  Branch (5389:8): [True: 244, False: 20]
  ------------------
 5390|    244|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5390:9): [True: 1, False: 243]
  |  Branch (5390:24): [True: 5, False: 238]
  ------------------
 5391|      6|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5392|      6|					goto err;
 5393|      6|				}
 5394|       |
 5395|    238|				priv->keysWithOnCardCerts = *num;
 5396|    238|			}
 5397|       |
 5398|    258|			numlen = 0;
 5399|    258|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5400|    258|			if (num) {
  ------------------
  |  Branch (5400:8): [True: 224, False: 34]
  ------------------
 5401|    224|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5401:9): [True: 1, False: 223]
  |  Branch (5401:24): [True: 2, False: 221]
  ------------------
 5402|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5403|      3|					goto err;
 5404|      3|				}
 5405|       |
 5406|    221|				priv->keysWithOffCardCerts = *num;
 5407|    221|			}
 5408|       |
 5409|    255|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5410|    255|			if (url) {
  ------------------
  |  Branch (5410:8): [True: 218, False: 37]
  ------------------
 5411|    218|				if (urllen > 118) {
  ------------------
  |  Branch (5411:9): [True: 0, False: 218]
  ------------------
 5412|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5413|      0|					goto err;
 5414|      0|				}
 5415|    218|				priv->offCardCertURL = calloc(1, urllen + 1);
 5416|    218|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5416:9): [True: 0, False: 218]
  ------------------
 5417|    218|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5418|    218|				memcpy(priv->offCardCertURL, url, urllen);
 5419|    218|			}
 5420|    255|		} else {
 5421|      2|			sc_log(card->ctx, "Problem with History object\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__
  |  |  ------------------
  ------------------
 5422|      2|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 5423|      2|			goto err;
 5424|      2|		}
 5425|    266|	}
 5426|    255|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   71|    510|#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: 218, False: 37]
  |  |  ------------------
  ------------------
 5427|    255|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5428|    255|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5429|       |
 5430|       |	/* now mark what objects are on the card */
 5431|  4.04k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5431:14): [True: 3.78k, False: 255]
  ------------------
 5432|  3.78k|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|  4.04k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5433|       |
 5434|       |	/*
 5435|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5436|       |	 * we will read in and add the certs to the cache as listed on
 5437|       |	 * the card. some of the certs may be on the card as well.
 5438|       |	 *
 5439|       |	 * Get file name from url. verify that the filename is valid
 5440|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5441|       |	 * in the directory used for the  PKCS15 cache
 5442|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5443|       |	 */
 5444|       |
 5445|    255|	r = 0;
 5446|    255|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5446:6): [True: 218, False: 37]
  ------------------
 5447|    218|		char *fp;
 5448|    218|		char filename[PATH_MAX];
 5449|       |
 5450|    218|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5450:7): [True: 205, False: 13]
  ------------------
 5451|    205|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    205|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5452|    205|			goto err;
 5453|    205|		}
 5454|       |		/* find the last /  so we have the filename part */
 5455|     13|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5456|     13|		if (fp == NULL) {
  ------------------
  |  Branch (5456:7): [True: 5, False: 8]
  ------------------
 5457|      5|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      5|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5458|      5|			goto err;
 5459|      5|		}
 5460|      8|		fp++;
 5461|      8|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5461:7): [True: 1, False: 7]
  ------------------
 5462|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5463|      1|			goto err;
 5464|      1|		}
 5465|    110|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5465:15): [True: 109, False: 1]
  ------------------
 5466|    109|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5466:8): [True: 6, False: 103]
  ------------------
 5467|      6|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5468|      6|				goto err;
 5469|      6|			}
 5470|    109|		}
 5471|       |
 5472|       |		/* Use the same directory as used for other OpenSC cached items */
 5473|      1|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5474|      1|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (5474:7): [True: 0, False: 1]
  ------------------
 5475|      0|			goto err;
 5476|       |#ifdef _WIN32
 5477|       |		strlcat(filename, "\\", PATH_MAX);
 5478|       |#else
 5479|      1|		strlcat(filename, "/", PATH_MAX);
 5480|      1|#endif
 5481|      1|		strlcat(filename, fp, PATH_MAX);
 5482|       |
 5483|      1|		r = piv_read_obj_from_file(card, filename,
 5484|      1|				&ocfhfbuf, &ocfhflen);
 5485|      1|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5485:7): [True: 1, False: 0]
  ------------------
 5486|      1|			r = 0;
 5487|      1|			goto err;
 5488|      1|		}
 5489|       |
 5490|       |		/*
 5491|       |		 * Its a seq of seq of a key ref and cert
 5492|       |		 */
 5493|       |
 5494|      0|		body = ocfhfbuf;
 5495|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5495:7): [True: 0, False: 0]
  ------------------
 5496|      0|				body == NULL ||
  ------------------
  |  Branch (5496:5): [True: 0, False: 0]
  ------------------
 5497|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5497:5): [True: 0, False: 0]
  ------------------
 5498|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5498:5): [True: 0, False: 0]
  ------------------
 5499|      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__
  |  |  ------------------
  ------------------
 5500|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5501|      0|			goto err;
 5502|      0|		}
 5503|      0|		seq = body;
 5504|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5504:10): [True: 0, False: 0]
  ------------------
 5505|      0|			seqtag = seq;
 5506|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5506:8): [True: 0, False: 0]
  ------------------
 5507|      0|					seq == 0 ||
  ------------------
  |  Branch (5507:6): [True: 0, False: 0]
  ------------------
 5508|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5508:6): [True: 0, False: 0]
  ------------------
 5509|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5509:6): [True: 0, False: 0]
  ------------------
 5510|      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__
  |  |  ------------------
  ------------------
 5511|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5512|      0|				goto err;
 5513|      0|			}
 5514|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5515|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5515:8): [True: 0, False: 0]
  |  Branch (5515:19): [True: 0, False: 0]
  ------------------
 5516|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5516:7): [True: 0, False: 0]
  |  Branch (5516:25): [True: 0, False: 0]
  ------------------
 5517|      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__
  |  |  ------------------
  ------------------
 5518|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5519|      0|				goto err;
 5520|      0|			}
 5521|      0|			cert = keyref + keyreflen;
 5522|      0|			certlen = seqlen - (cert - seq);
 5523|       |
 5524|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5525|       |			/* now add the cert like another object */
 5526|       |
 5527|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5527:8): [True: 0, False: 0]
  ------------------
 5528|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5528:6): [True: 0, False: 0]
  ------------------
 5529|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5529:6): [True: 0, False: 0]
  ------------------
 5530|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5531|      0|				goto err;
 5532|      0|			}
 5533|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5534|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5535|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5535:8): [True: 0, False: 0]
  ------------------
 5536|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5537|      0|				goto err;
 5538|      0|			}
 5539|       |
 5540|      0|			certobjlen = tmplen;
 5541|      0|			certobj = malloc(certobjlen);
 5542|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5542:8): [True: 0, False: 0]
  ------------------
 5543|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5544|      0|				goto err;
 5545|      0|			}
 5546|      0|			cp = certobj;
 5547|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5547:8): [True: 0, False: 0]
  ------------------
 5548|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5548:6): [True: 0, False: 0]
  ------------------
 5549|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5549:6): [True: 0, False: 0]
  ------------------
 5550|      0|				goto err;
 5551|      0|			}
 5552|      0|			*cp++ = 0x00;
 5553|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5554|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5554:8): [True: 0, False: 0]
  ------------------
 5555|      0|				goto err;
 5556|      0|			}
 5557|       |
 5558|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5559|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5560|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  151|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5561|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  153|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5562|       |
 5563|      0|			r = piv_cache_internal_data(card, enumtag);
 5564|      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__
  |  |  ------------------
  ------------------
 5565|       |
 5566|      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__
  |  |  ------------------
  ------------------
 5567|      0|					enumtag,
 5568|      0|					priv->obj_cache[enumtag].obj_data,
 5569|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5570|       |
 5571|      0|			bodylen -= (seqlen + seq - seqtag);
 5572|      0|			seq += seqlen;
 5573|      0|		}
 5574|      0|	}
 5575|  1.11k|err:
 5576|  1.11k|	if (ocfhfbuf)
  ------------------
  |  Branch (5576:6): [True: 0, False: 1.11k]
  ------------------
 5577|      0|		free(ocfhfbuf);
 5578|  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|    898|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 898, False: 213]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5579|  1.11k|}
card-piv.c:piv_read_obj_from_file:
 3039|      1|{
 3040|      1|	int r;
 3041|      1|	int r_tag;
 3042|      1|	int f = -1;
 3043|      1|	size_t len;
 3044|      1|	u8 tagbuf[16];
 3045|      1|	size_t rbuflen;
 3046|      1|	const u8 *body;
 3047|      1|	unsigned int cla_out, tag_out;
 3048|      1|	size_t bodylen;
 3049|       |
 3050|      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]
  |  |  ------------------
  ------------------
 3051|       |
 3052|      1|	*buf = NULL;
 3053|      1|	*buf_len = 0;
 3054|      1|	f = open(filename, O_RDONLY);
 3055|      1|	if (f < 0) {
  ------------------
  |  Branch (3055:6): [True: 1, False: 0]
  ------------------
 3056|      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__
  |  |  ------------------
  ------------------
 3057|      1|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3058|      1|		goto err;
 3059|      1|	}
 3060|      0|	len = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
 3061|      0|	if (len < 2 || len > sizeof(tagbuf)) {
  ------------------
  |  Branch (3061:6): [True: 0, False: 0]
  |  Branch (3061:17): [True: 0, False: 0]
  ------------------
 3062|      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__
  |  |  ------------------
  ------------------
 3063|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 3064|      0|		goto err;
 3065|      0|	}
 3066|      0|	body = tagbuf;
 3067|       |	/* accept any tag for now, just get length */
 3068|      0|	r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 3069|      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 (3069:7): [True: 0, False: 0]
  |  Branch (3069:30): [True: 0, False: 0]
  ------------------
 3070|      0|			body == NULL) {
  ------------------
  |  Branch (3070:4): [True: 0, False: 0]
  ------------------
 3071|      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__
  |  |  ------------------
  ------------------
 3072|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3073|      0|		goto err;
 3074|      0|	}
 3075|      0|	rbuflen = body - tagbuf + bodylen;
 3076|      0|	*buf = malloc(rbuflen);
 3077|      0|	if (!*buf) {
  ------------------
  |  Branch (3077:6): [True: 0, False: 0]
  ------------------
 3078|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3079|      0|		goto err;
 3080|      0|	}
 3081|      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]
  |  |  ------------------
  ------------------
 3082|       |	/* read rest of file */
 3083|      0|	if (rbuflen > len + sizeof(tagbuf)) {
  ------------------
  |  Branch (3083:6): [True: 0, False: 0]
  ------------------
 3084|      0|		len = read(f, *buf + sizeof(tagbuf), rbuflen - sizeof(tagbuf)); /* read rest */
 3085|      0|		if (len != rbuflen - sizeof(tagbuf)) {
  ------------------
  |  Branch (3085:7): [True: 0, False: 0]
  ------------------
 3086|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 3087|      0|			free(*buf);
 3088|      0|			*buf = NULL;
 3089|      0|			goto err;
 3090|      0|		}
 3091|      0|	}
 3092|      0|	r = (int)rbuflen;
 3093|      0|	*buf_len = rbuflen;
 3094|      1|err:
 3095|      1|	if (f >= 0)
  ------------------
  |  Branch (3095:6): [True: 0, False: 1]
  ------------------
 3096|      0|		close(f);
 3097|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3098|      1|}
card-piv.c:piv_cache_internal_data:
 3297|  5.05k|{
 3298|  5.05k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  5.05k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3299|  5.05k|	const u8 *tag;
 3300|  5.05k|	const u8 *body;
 3301|  5.05k|	size_t taglen;
 3302|  5.05k|	size_t bodylen;
 3303|  5.05k|	int compressed = 0;
 3304|  5.05k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  5.05k|#define SC_SUCCESS				0
  ------------------
 3305|       |#ifdef ENABLE_PIV_SM
 3306|       |	u8 *cvc_start = NULL;
 3307|       |	size_t cvc_len = 0;
 3308|       |#endif
 3309|       |
 3310|       |	/* if already cached */
 3311|  5.05k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3311:6): [True: 2.46k, False: 2.58k]
  |  Branch (3311:52): [True: 2.46k, False: 0]
  ------------------
 3312|  2.46k|		sc_log(card->ctx, "#%d found internal %p:%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3313|  2.46k|				enumtag,
 3314|  2.46k|				priv->obj_cache[enumtag].internal_obj_data,
 3315|  2.46k|				priv->obj_cache[enumtag].internal_obj_len);
 3316|  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.46k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.46k|	return _ret; \
  |  |  |  |  163|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3317|  2.46k|	}
 3318|       |
 3319|  2.58k|	body = sc_asn1_find_tag(card->ctx,
 3320|  2.58k|			priv->obj_cache[enumtag].obj_data,
 3321|  2.58k|			priv->obj_cache[enumtag].obj_len,
 3322|  2.58k|			0x53, &bodylen);
 3323|       |
 3324|  2.58k|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3324:6): [True: 0, False: 2.58k]
  |  Branch (3324:22): [True: 0, False: 2.58k]
  ------------------
 3325|  2.58k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3326|       |
 3327|       |	/* get the certificate out */
 3328|  2.58k|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  653|  2.58k|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3328:6): [True: 2.58k, False: 0]
  ------------------
 3329|       |
 3330|  2.58k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3331|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3332|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3333|  2.58k|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3333:7): [True: 1.28k, False: 1.29k]
  |  Branch (3333:14): [True: 1.25k, False: 37]
  |  Branch (3333:29): [True: 10, False: 1.24k]
  |  Branch (3333:48): [True: 12, False: 1.22k]
  ------------------
 3334|     22|			compressed = 1;
 3335|       |
 3336|       |#ifdef ENABLE_PIV_SM
 3337|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3338|       |#endif
 3339|       |
 3340|  2.58k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3341|  2.58k|		if (tag == NULL)
  ------------------
  |  Branch (3341:7): [True: 107, False: 2.48k]
  ------------------
 3342|  2.58k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  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|    107|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 107, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3343|       |
 3344|  2.48k|		if (taglen == 0)
  ------------------
  |  Branch (3344:7): [True: 11, False: 2.46k]
  ------------------
 3345|  2.48k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3346|       |
 3347|  2.46k|		if (compressed) {
  ------------------
  |  Branch (3347:7): [True: 20, False: 2.44k]
  ------------------
 3348|     20|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  152|     20|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3349|     20|		}
 3350|       |		/* internal certificate remains compressed */
 3351|  2.46k|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3351:7): [True: 0, False: 2.46k]
  ------------------
 3352|  2.46k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3353|       |
 3354|  2.46k|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3355|  2.46k|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3356|       |
 3357|       |#ifdef ENABLE_PIV_SM
 3358|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3359|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3360|       |			/* cvc if present should be at cvc_start.
 3361|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3362|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3363|       |			 * as the size of (L) depends on the length of value
 3364|       |			 */
 3365|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3366|       |					cvc_start &&
 3367|       |					cvc_start < tag &&
 3368|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3369|       |				cvc_len = tag - cvc_start + taglen;
 3370|       |				/* decode the intermediate CVC */
 3371|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3372|       |				if (r < 0) {
 3373|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3374|       |				}
 3375|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3376|       |			}
 3377|       |		}
 3378|       |#endif /* ENABLE_PIV_SM */
 3379|       |
 3380|       |		/* convert pub key to internal */
 3381|  2.46k|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3381:13): [True: 0, False: 0]
  ------------------
 3382|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3383|      0|		if (tag == NULL)
  ------------------
  |  Branch (3383:7): [True: 0, False: 0]
  ------------------
 3384|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3385|       |
 3386|      0|		if (taglen == 0)
  ------------------
  |  Branch (3386:7): [True: 0, False: 0]
  ------------------
 3387|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3388|       |
 3389|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3389:7): [True: 0, False: 0]
  ------------------
 3390|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3391|       |
 3392|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3393|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3394|      0|	} else {
 3395|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3396|      0|	}
 3397|       |
 3398|  2.46k|	sc_log(card->ctx, "added #%d internal %p:%zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3399|  2.46k|			enumtag,
 3400|  2.46k|			priv->obj_cache[enumtag].internal_obj_data,
 3401|  2.46k|			priv->obj_cache[enumtag].internal_obj_len);
 3402|       |
 3403|  2.46k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.46k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.46k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.46k|	int _ret = r; \
  |  |  |  |  155|  2.46k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.46k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.46k|	return _ret; \
  |  |  |  |  163|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3404|  2.46k|}
card-piv.c:piv_finish:
 5602|  10.6k|{
 5603|  10.6k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  10.6k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5604|  10.6k|	int i;
 5605|       |
 5606|  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]
  |  |  ------------------
  ------------------
 5607|  10.6k|	if (priv) {
  ------------------
  |  Branch (5607:6): [True: 5.89k, False: 4.77k]
  ------------------
 5608|  5.89k|		if (priv->context_specific) {
  ------------------
  |  Branch (5608:7): [True: 0, False: 5.89k]
  ------------------
 5609|      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__
  |  |  ------------------
  ------------------
 5610|      0|			priv->context_specific = 0;
 5611|      0|			sc_unlock(card);
 5612|      0|		}
 5613|  5.89k|		free(priv->aid_der.value);
 5614|  5.89k|		free(priv->al_label);
 5615|  5.89k|		if (priv->w_buf)
  ------------------
  |  Branch (5615:7): [True: 0, False: 5.89k]
  ------------------
 5616|      0|			free(priv->w_buf);
 5617|  5.89k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5617:7): [True: 218, False: 5.67k]
  ------------------
 5618|    218|			free(priv->offCardCertURL);
 5619|   359k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5619:15): [True: 353k, False: 5.89k]
  ------------------
 5620|   353k|			piv_obj_cache_free_entry(card, i, 0);
 5621|   353k|		}
 5622|   159k|		for (i = 0; i < PIV_NUM_YK_SLOT_INFO; i++) {
  ------------------
  |  |  389|   159k|#define PIV_NUM_YK_SLOT_INFO 26
  ------------------
  |  Branch (5622:15): [True: 153k, False: 5.89k]
  ------------------
 5623|   153k|			free(priv->yk_slot_info[i].pubkey.value);
 5624|   153k|		}
 5625|       |#ifdef ENABLE_PIV_SM
 5626|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5627|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5628|       |		piv_clear_sm_session(&priv->sm_session);
 5629|       |#endif /* ENABLE_PIV_SM */
 5630|       |
 5631|  5.89k|		free(priv);
 5632|       |		card->drv_data = NULL; /* priv */
 5633|  5.89k|	}
 5634|  10.6k|	return 0;
 5635|  10.6k|}
card-piv.c:piv_select_file:
 5030|  11.0k|{
 5031|  11.0k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  11.0k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5032|  11.0k|	int r;
 5033|  11.0k|	int i;
 5034|  11.0k|	const u8 *path;
 5035|  11.0k|	size_t pathlen;
 5036|  11.0k|	sc_file_t *file = NULL;
 5037|  11.0k|	u8 *rbuf = NULL;
 5038|  11.0k|	size_t rbuflen = 0;
 5039|       |
 5040|  11.0k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  11.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.0k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.0k]
  |  |  ------------------
  ------------------
 5041|       |
 5042|  11.0k|	if (in_path->len < 2)
  ------------------
  |  Branch (5042:6): [True: 0, False: 11.0k]
  ------------------
 5043|  11.0k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5044|       |
 5045|  11.0k|	path = in_path->value;
 5046|  11.0k|	pathlen = in_path->len;
 5047|       |
 5048|       |	/* only support single EF in current application */
 5049|       |	/*
 5050|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 5051|       |	 * select_file and read_binary. The emulation adds path emulated structures
 5052|       |	 * so piv_select_file will find it.
 5053|       |	 * there is no dir. Only direct access to emulated files
 5054|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 5055|       |	 */
 5056|       |
 5057|  11.0k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (5057:6): [True: 1.65k, False: 9.38k]
  ------------------
 5058|  1.65k|		if (pathlen > 2) {
  ------------------
  |  Branch (5058:7): [True: 1.65k, False: 0]
  ------------------
 5059|  1.65k|			path += 2;
 5060|  1.65k|			pathlen -= 2;
 5061|  1.65k|		}
 5062|  1.65k|	}
 5063|       |
 5064|  11.0k|	if (pathlen < 2)
  ------------------
  |  Branch (5064:6): [True: 0, False: 11.0k]
  ------------------
 5065|  11.0k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5066|       |
 5067|  11.0k|	i = piv_find_obj_by_containerid(card, path);
 5068|       |
 5069|  11.0k|	if (i < 0)
  ------------------
  |  Branch (5069:6): [True: 1.69k, False: 9.34k]
  ------------------
 5070|  11.0k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5071|       |
 5072|       |	/*
 5073|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 5074|       |	 * with cece added to path to request only the cert from the cert obj
 5075|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 5076|       |	 */
 5077|  9.34k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (5077:28): [True: 9.34k, False: 0]
  |  Branch (5077:44): [True: 9.34k, False: 0]
  |  Branch (5077:63): [True: 9.34k, False: 0]
  ------------------
 5078|       |
 5079|  9.34k|	priv->selected_obj = i;
 5080|  9.34k|	priv->rwb_state = -1;
 5081|       |
 5082|       |	/* make it look like the file was found. */
 5083|       |	/* We don't want to read it now  unless we need the length */
 5084|       |
 5085|  9.34k|	if (file_out) {
  ------------------
  |  Branch (5085:6): [True: 9.34k, False: 0]
  ------------------
 5086|       |		/* we need to read it now, to get length into cache */
 5087|  9.34k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 5088|       |
 5089|  9.34k|		if (r < 0)
  ------------------
  |  Branch (5089:7): [True: 6.75k, False: 2.58k]
  ------------------
 5090|  9.34k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  6.75k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.75k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.75k|	int _ret = r; \
  |  |  |  |  155|  6.75k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.75k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.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|  6.75k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.75k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.75k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.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|  6.75k|	return _ret; \
  |  |  |  |  163|  6.75k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5091|       |
 5092|       |		/* get the cert or the pub key out and into the cache too */
 5093|  2.58k|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (5093:7): [True: 2.58k, False: 0]
  |  Branch (5093:33): [True: 0, False: 0]
  ------------------
 5094|  2.58k|			r = piv_cache_internal_data(card, i);
 5095|  2.58k|			if (r < 0)
  ------------------
  |  Branch (5095:8): [True: 118, False: 2.46k]
  ------------------
 5096|  2.58k|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    118|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    118|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    118|	int _ret = r; \
  |  |  |  |  155|    118|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 118, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    118|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    118|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 118, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    118|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    118|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    118|	return _ret; \
  |  |  |  |  163|    118|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5097|  2.58k|		}
 5098|       |
 5099|  2.46k|		file = sc_file_new();
 5100|  2.46k|		if (file == NULL)
  ------------------
  |  Branch (5100:7): [True: 0, False: 2.46k]
  ------------------
 5101|  2.46k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5102|       |
 5103|  2.46k|		file->path = *in_path;
 5104|       |		/* this could be like the FCI */
 5105|  2.46k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  2.46k|#define SC_FILE_TYPE_DF			0x04
  ------------------
 5106|  2.46k|		file->shareable = 0;
 5107|  2.46k|		file->ef_structure = 0;
 5108|  2.46k|		if (priv->return_only_cert)
  ------------------
  |  Branch (5108:7): [True: 2.46k, False: 0]
  ------------------
 5109|  2.46k|			file->size = priv->obj_cache[i].internal_obj_len;
 5110|      0|		else
 5111|      0|			file->size = priv->obj_cache[i].obj_len;
 5112|       |
 5113|  2.46k|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 5114|       |
 5115|  2.46k|		*file_out = file;
 5116|  2.46k|	}
 5117|       |
 5118|  2.46k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.46k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.46k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.46k|	int _ret = r; \
  |  |  |  |  155|  2.46k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.46k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.46k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.46k|	return _ret; \
  |  |  |  |  163|  2.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5119|  2.46k|}
card-piv.c:piv_find_obj_by_containerid:
 1779|  79.9k|{
 1780|  79.9k|	int i;
 1781|       |
 1782|  79.9k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  79.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  79.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  79.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  79.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 79.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1783|  79.9k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  79.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__
  |  |  ------------------
  ------------------
 1784|       |
 1785|  1.63M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1785:14): [True: 1.62M, False: 2.80k]
  ------------------
 1786|  1.62M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1786:7): [True: 695k, False: 934k]
  |  Branch (1786:50): [True: 77.1k, False: 618k]
  ------------------
 1787|  1.62M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  77.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  77.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  77.1k|	int _ret = r; \
  |  |  |  |  155|  77.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.11k, False: 76.0k]
  |  |  |  |  ------------------
  |  |  |  |  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.0k|	} else { \
  |  |  |  |  159|  76.0k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  76.0k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  76.0k|	} \
  |  |  |  |  162|  77.1k|	return _ret; \
  |  |  |  |  163|  77.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1788|  1.62M|	}
 1789|       |
 1790|  2.80k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  2.80k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.80k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.80k|	int _ret = r; \
  |  |  |  |  155|  2.80k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  2.80k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.80k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.80k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.80k|	return _ret; \
  |  |  |  |  163|  2.80k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1791|  2.80k|}
card-piv.c:piv_read_binary:
 3413|  2.55k|{
 3414|  2.55k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.55k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3415|  2.55k|	int enumtag;
 3416|  2.55k|	int r;
 3417|  2.55k|	u8 *rbuf = NULL;
 3418|  2.55k|	size_t rbuflen = 0;
 3419|  2.55k|	const u8 *body;
 3420|  2.55k|	size_t bodylen;
 3421|       |
 3422|  2.55k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.55k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.55k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.55k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.55k]
  |  |  ------------------
  ------------------
 3423|  2.55k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3423:6): [True: 0, False: 2.55k]
  ------------------
 3424|  2.55k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3425|  2.55k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3426|       |
 3427|  2.55k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3427:6): [True: 2.46k, False: 84]
  ------------------
 3428|  2.46k|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3429|       |
 3430|  2.46k|		if (r >= 0) {
  ------------------
  |  Branch (3430:7): [True: 2.46k, False: 0]
  ------------------
 3431|       |			/* an object with no data will be considered not found */
 3432|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3433|  2.46k|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3433:8): [True: 0, False: 2.46k]
  |  Branch (3433:17): [True: 0, False: 2.46k]
  |  Branch (3433:37): [True: 2.46k, False: 0]
  |  Branch (3433:65): [True: 0, False: 2.46k]
  ------------------
 3434|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3435|      0|				goto err;
 3436|      0|			}
 3437|       |
 3438|  2.46k|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3439|  2.46k|			if (body == NULL) {
  ------------------
  |  Branch (3439:8): [True: 0, False: 2.46k]
  ------------------
 3440|       |				/* if missing, assume its the body */
 3441|       |				/* DEE bug in the beta card */
 3442|      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__
  |  |  ------------------
  ------------------
 3443|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3444|      0|				goto err;
 3445|      0|			}
 3446|  2.46k|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3446:8): [True: 0, False: 2.46k]
  ------------------
 3447|      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__
  |  |  ------------------
  ------------------
 3448|      0|						bodylen, body - rbuf, rbuflen);
 3449|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3450|      0|				goto err;
 3451|      0|			}
 3452|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3453|  2.46k|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3453:8): [True: 2.46k, False: 0]
  |  Branch (3453:34): [True: 0, False: 0]
  ------------------
 3454|  2.46k|				r = piv_cache_internal_data(card, enumtag);
 3455|  2.46k|				if (r < 0)
  ------------------
  |  Branch (3455:9): [True: 0, False: 2.46k]
  ------------------
 3456|      0|					goto err;
 3457|  2.46k|			}
 3458|  2.46k|		}
 3459|  2.46k|		priv->rwb_state = 0;
 3460|  2.46k|	}
 3461|       |
 3462|  2.55k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  654|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3462:6): [True: 2.55k, False: 0]
  |  Branch (3462:32): [True: 0, False: 0]
  ------------------
 3463|  2.55k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3464|  2.55k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3465|  2.55k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  152|  2.55k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3465:7): [True: 22, False: 2.53k]
  |  Branch (3465:70): [True: 22, False: 0]
  ------------------
 3466|     22|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     22|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3467|     22|		}
 3468|  2.55k|	} else {
 3469|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3470|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3471|      0|	}
 3472|       |	/* rbuf rbuflen has pointer and length to cached data */
 3473|       |
 3474|  2.55k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3474:6): [True: 0, False: 2.55k]
  ------------------
 3475|      0|		count = rbuflen - idx;
 3476|  2.55k|	if (count <= 0) {
  ------------------
  |  Branch (3476:6): [True: 0, False: 2.55k]
  ------------------
 3477|      0|		r = 0;
 3478|      0|		priv->rwb_state = 1;
 3479|  2.55k|	} else {
 3480|  2.55k|		memcpy(buf, rbuf + idx, count);
 3481|  2.55k|		r = (int)count;
 3482|  2.55k|	}
 3483|       |
 3484|  2.55k|err:
 3485|  2.55k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.55k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.55k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.55k|	int _ret = r; \
  |  |  |  |  155|  2.55k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 2.55k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.55k|	} else { \
  |  |  |  |  159|  2.55k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.55k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.55k|	} \
  |  |  |  |  162|  2.55k|	return _ret; \
  |  |  |  |  163|  2.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3486|  2.55k|}
card-piv.c:piv_set_security_env:
 4762|  4.46k|{
 4763|  4.46k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  4.46k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4764|  4.46k|	int r = 0;
 4765|       |
 4766|  4.46k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.46k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.46k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.46k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.46k]
  |  |  ------------------
  ------------------
 4767|       |
 4768|  4.46k|	sc_log(card->ctx, "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%zu",
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 4769|  4.46k|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4770|  4.46k|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4771|       |
 4772|  4.46k|	priv->operation = env->operation;
 4773|  4.46k|	priv->algorithm = env->algorithm;
 4774|       |
 4775|  4.46k|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   69|  4.46k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4775:6): [True: 1.30k, False: 3.16k]
  ------------------
 4776|  1.30k|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4777|  3.16k|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   70|  3.16k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4777:13): [True: 3.16k, False: 0]
  ------------------
 4778|  3.16k|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|  3.16k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4778:7): [True: 3.16k, False: 0]
  ------------------
 4779|  3.16k|			switch (env->algorithm_ref) {
 4780|  3.05k|			case 256:
  ------------------
  |  Branch (4780:4): [True: 3.05k, False: 107]
  ------------------
 4781|  3.05k|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4782|  3.05k|				priv->key_size = 256;
 4783|  3.05k|				break;
 4784|    107|			case 384:
  ------------------
  |  Branch (4784:4): [True: 107, False: 3.05k]
  ------------------
 4785|    107|				priv->alg_id = 0x14;
 4786|    107|				priv->key_size = 384;
 4787|    107|				break;
 4788|      0|			default:
  ------------------
  |  Branch (4788:4): [True: 0, False: 3.16k]
  ------------------
 4789|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4790|  3.16k|			}
 4791|  3.16k|		} else
 4792|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4793|  3.16k|	} else if (env->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (4793:13): [True: 0, False: 0]
  ------------------
 4794|      0|		priv->alg_id = 0xE0;
 4795|      0|		priv->key_size = 255;
 4796|      0|	} else if (env->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4796:13): [True: 0, False: 0]
  ------------------
 4797|      0|		priv->alg_id = 0xE1;
 4798|      0|		priv->key_size = 255;
 4799|      0|	} else
 4800|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4801|  4.46k|	priv->key_ref = env->key_ref[0];
 4802|       |
 4803|  4.46k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.46k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.46k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.46k|	int _ret = r; \
  |  |  |  |  155|  4.46k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.46k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.46k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 4.46k]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.46k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.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|  4.46k|	return _ret; \
  |  |  |  |  163|  4.46k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4804|  4.46k|}
card-piv.c:piv_compute_signature:
 4935|  2.75k|{
 4936|  2.75k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.75k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4937|  2.75k|	int r;
 4938|  2.75k|	u8 *ecdata = NULL;
 4939|  2.75k|	size_t ecdatalen = 0;
 4940|  2.75k|	size_t ecpadlen = 0;
 4941|  2.75k|	size_t nLen;
 4942|  2.75k|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4943|       |
 4944|  2.75k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.75k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.75k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.75k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.75k]
  |  |  ------------------
  ------------------
 4945|       |
 4946|       |	/* The PIV returns a DER SEQUENCE{INTEGER, INTEGER}
 4947|       |	 * Which may have leading 00 to force a positive integer
 4948|       |	 * But PKCS11 just wants 2* field_length in bytes
 4949|       |	 * So we have to strip out the integers
 4950|       |	 * and pad on left if too short.
 4951|       |	 */
 4952|       |
 4953|  2.75k|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4953:6): [True: 2.53k, False: 214]
  |  Branch (4953:30): [True: 96, False: 118]
  ------------------
 4954|  2.63k|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  145|  2.63k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4955|       |
 4956|       |		/* One applet is known to enforce the hash size
 4957|       |		 * must match the field_length in bytes. But Windows
 4958|       |		 * may try ECDSA without a hash when offline
 4959|       |		 * So we will pad input to hash size.
 4960|       |		 */
 4961|  2.63k|		if (priv->card_issues & CI_ENFORCES_EC_HASH_EQ_KEYSIZE &&
  ------------------
  |  |  605|  5.26k|#define CI_ENFORCES_EC_HASH_EQ_KEYSIZE	    0x00001000U /* Applet enforces hash size == EC field size for ECDSA. Windows issue */
  ------------------
  |  Branch (4961:7): [True: 0, False: 2.63k]
  ------------------
 4962|      0|				!strcmp(card->ctx->app_name, "cardmod") &&
  ------------------
  |  Branch (4962:5): [True: 0, False: 0]
  ------------------
 4963|      0|				(datalen < nLen)) {
  ------------------
  |  Branch (4963:5): [True: 0, False: 0]
  ------------------
 4964|      0|			ecpadlen = nLen - datalen;
 4965|  2.63k|		} else {
 4966|  2.63k|			ecpadlen = 0;
 4967|  2.63k|		}
 4968|       |
 4969|  2.63k|		ecdatalen = datalen + ecpadlen;
 4970|  2.63k|		ecdata = calloc(ecdatalen, sizeof(u8));
 4971|  2.63k|		if (ecdata == NULL) {
  ------------------
  |  Branch (4971:7): [True: 0, False: 2.63k]
  ------------------
 4972|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 4973|      0|			goto err;
 4974|      0|		}
 4975|  2.63k|		memcpy(ecdata + ecpadlen, data, datalen);
 4976|       |
 4977|  2.63k|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4977:7): [True: 0, False: 2.63k]
  ------------------
 4978|      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__
  |  |  ------------------
  ------------------
 4979|      0|					outlen, 2 * nLen);
 4980|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4981|      0|			goto err;
 4982|      0|		}
 4983|       |
 4984|  2.63k|		r = piv_validate_general_authentication(card, ecdata, ecdatalen, rbuf, sizeof rbuf);
 4985|  2.63k|		if (r < 0)
  ------------------
  |  Branch (4985:7): [True: 2.62k, False: 8]
  ------------------
 4986|  2.62k|			goto err;
 4987|       |
 4988|      8|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4989|       |		/* Yubikey 5.7.x supports ED25519 */
 4990|    118|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4990:13): [True: 0, False: 118]
  ------------------
 4991|      0|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  145|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4992|      0|		if (outlen < nLen) {
  ------------------
  |  Branch (4992:7): [True: 0, False: 0]
  ------------------
 4993|      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__
  |  |  ------------------
  ------------------
 4994|      0|					outlen, nLen);
 4995|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4996|      0|			goto err;
 4997|      0|		}
 4998|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4999|       |
 5000|    118|	} else { /* RSA is all set */
 5001|    118|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 5002|    118|	}
 5003|       |
 5004|  2.75k|err:
 5005|  2.75k|	free(ecdata);
 5006|  2.75k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.75k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.75k|	int _ret = r; \
  |  |  155|  2.75k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.75k, False: 0]
  |  |  ------------------
  |  |  156|  2.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|  2.75k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.75k, False: 0]
  |  |  ------------------
  |  |  157|  2.75k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.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|  2.75k|	return _ret; \
  |  |  163|  2.75k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 5007|  2.75k|}
card-piv.c:piv_validate_general_authentication:
 4835|  3.50k|{
 4836|  3.50k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  3.50k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4837|  3.50k|	int r, tmplen, tmplen2;
 4838|  3.50k|	u8 *p;
 4839|  3.50k|	const unsigned char *p2;
 4840|  3.50k|	size_t taglen;
 4841|  3.50k|	size_t bodylen;
 4842|  3.50k|	unsigned int cla, tag;
 4843|  3.50k|	unsigned int real_alg_id, op_tag;
 4844|       |
 4845|  3.50k|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4846|  3.50k|	size_t sbuflen = sizeof(sbuf);
 4847|  3.50k|	u8 rbuf[4096];
 4848|       |
 4849|  3.50k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  3.50k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  3.50k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  3.50k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 3.50k]
  |  |  ------------------
  ------------------
 4850|       |
 4851|       |	/* should assume large send data */
 4852|  3.50k|	p = sbuf;
 4853|  3.50k|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4854|  3.50k|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4855|  3.50k|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4855:6): [True: 0, False: 3.50k]
  |  Branch (4855:21): [True: 0, False: 3.50k]
  ------------------
 4856|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4857|      0|	}
 4858|  3.50k|	tmplen += tmplen2;
 4859|  3.50k|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|  7.01k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4859:6): [True: 69, False: 3.44k]
  ------------------
 4860|  3.44k|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|  3.44k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4860:4): [True: 0, False: 3.44k]
  ------------------
 4861|     69|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     69|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     69|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     69|	return _ret; \
  |  |  |  |  163|     69|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4862|     69|	}
 4863|  3.44k|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   50|  6.88k|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   70|    376|#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 (4863:6): [True: 188, False: 3.25k]
  |  Branch (4863:53): [True: 188, False: 0]
  |  Branch (4863:91): [True: 0, False: 0]
  ------------------
 4864|    188|		op_tag = 0x85;
 4865|  3.25k|	} else {
 4866|  3.25k|		op_tag = 0x81;
 4867|  3.25k|	}
 4868|  3.44k|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4869|  3.44k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  3.44k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4869:6): [True: 0, False: 3.44k]
  ------------------
 4870|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4871|      0|	}
 4872|       |
 4873|       |	/*
 4874|       |	 * alg_id=06 is a place holder for all RSA keys.
 4875|       |	 * Derive the real alg_id based on the size of the
 4876|       |	 * the data, as we are always using raw mode.
 4877|       |	 * Non RSA keys needs some work in this area.
 4878|       |	 */
 4879|       |
 4880|  3.44k|	real_alg_id = priv->alg_id;
 4881|  3.44k|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4881:6): [True: 620, False: 2.82k]
  ------------------
 4882|    620|		switch (datalen) {
 4883|    180|		case 128:
  ------------------
  |  Branch (4883:3): [True: 180, False: 440]
  ------------------
 4884|    180|			real_alg_id = 0x06;
 4885|    180|			break;
 4886|     64|		case 256:
  ------------------
  |  Branch (4886:3): [True: 64, False: 556]
  ------------------
 4887|     64|			real_alg_id = 0x07;
 4888|     64|			break;
 4889|     62|		case 384:
  ------------------
  |  Branch (4889:3): [True: 62, False: 558]
  ------------------
 4890|     62|			real_alg_id = 0x05;
 4891|     62|			break;
 4892|     68|		case 512:
  ------------------
  |  Branch (4892:3): [True: 68, False: 552]
  ------------------
 4893|     68|			real_alg_id = 0x16;
 4894|     68|			break;
 4895|    246|		default:
  ------------------
  |  Branch (4895:3): [True: 246, False: 374]
  ------------------
 4896|    246|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  153|    246|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    246|	int _ret = r; \
  |  |  155|    246|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 246, False: 0]
  |  |  ------------------
  |  |  156|    246|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    246|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 246, False: 0]
  |  |  ------------------
  |  |  157|    246|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    246|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    246|	return _ret; \
  |  |  163|    246|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4897|    620|		}
 4898|    620|	}
 4899|       |	/* EC and ED alg_id was already set */
 4900|       |
 4901|  3.19k|	piv_yk_notify_touch_policy(card, priv->key_ref);
 4902|  3.19k|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4903|  3.19k|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4904|  3.19k|	if (r < 0)
  ------------------
  |  Branch (4904:6): [True: 2.85k, False: 337]
  ------------------
 4905|  2.85k|		goto err;
 4906|       |
 4907|    337|	p2 = rbuf;
 4908|    337|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4909|    337|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4909:6): [True: 101, False: 236]
  |  Branch (4909:20): [True: 106, False: 130]
  |  Branch (4909:29): [True: 60, False: 70]
  |  Branch (4909:45): [True: 57, False: 13]
  ------------------
 4910|    324|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    324|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4911|    324|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can't find 0x7C");
  ------------------
  |  |  184|    324|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    324|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    324|	int _ret = (r); \
  |  |  |  |  178|    324|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 324, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    324|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    324|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    324|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    324|		goto err; \
  |  |  |  |  182|    324|	} \
  |  |  |  |  183|    324|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4912|    324|	}
 4913|       |
 4914|     13|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4915|     13|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4915:6): [True: 1, False: 12]
  |  Branch (4915:20): [True: 1, False: 11]
  |  Branch (4915:29): [True: 1, False: 10]
  |  Branch (4915:44): [True: 1, False: 9]
  ------------------
 4916|      4|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      4|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4917|      4|		LOG_TEST_GOTO_ERR(card->ctx, r, "Can't find 0x82");
  ------------------
  |  |  184|      4|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      4|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      4|	int _ret = (r); \
  |  |  |  |  178|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4918|      4|	}
 4919|       |
 4920|      9|	if (taglen > outlen) {
  ------------------
  |  Branch (4920:6): [True: 0, False: 9]
  ------------------
 4921|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4922|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4923|      0|	}
 4924|       |
 4925|      9|	memcpy(out, p2, taglen);
 4926|      9|	r = (int)taglen;
 4927|       |
 4928|  3.19k|err:
 4929|  3.19k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  3.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.19k|	int _ret = r; \
  |  |  |  |  155|  3.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.18k, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.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|  3.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.18k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.18k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.18k|	} 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.19k|	return _ret; \
  |  |  |  |  163|  3.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4930|  3.19k|}
card-piv.c:piv_yk_notify_touch_policy:
 4816|  3.19k|{
 4817|  3.19k|	u8 touch_policy;
 4818|  3.19k|	const char *title = "Touch your Yubikey to continue";
 4819|       |
 4820|  3.19k|	piv_yk_get_metadata(card, key_ref, NULL, &touch_policy, NULL);
 4821|  3.19k|	switch (touch_policy) {
  ------------------
  |  Branch (4821:10): [True: 35, False: 3.15k]
  ------------------
 4822|     26|	case 0x02:
  ------------------
  |  Branch (4822:2): [True: 26, False: 3.16k]
  ------------------
 4823|     26|		sc_notify(title, "Touching the token is required for unlocking the key");
 4824|     26|		break;
 4825|      9|	case 0x03:
  ------------------
  |  Branch (4825:2): [True: 9, False: 3.18k]
  ------------------
 4826|      9|		sc_notify(title, "Touching the token is required unlocking the key (needed again after 15 seconds)");
 4827|      9|		break;
 4828|  3.19k|	}
 4829|  3.19k|}
card-piv.c:piv_yk_get_metadata:
 4548|  29.4k|{
 4549|  29.4k|	u8 resp[3072]; /* Should be enough to fit ML-DSA-87 key */
 4550|  29.4k|	int resplen = 0;
 4551|  29.4k|	size_t i;
 4552|  29.4k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  29.4k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4553|  29.4k|	int rc;
 4554|       |
 4555|       |	/* initialize with the default behaviour */
 4556|  29.4k|	if (pin_policy)
  ------------------
  |  Branch (4556:6): [True: 2.39k, False: 27.0k]
  ------------------
 4557|  2.39k|		*pin_policy = 0x00; /* i.e. use NIST defined */
 4558|  29.4k|	if (touch_policy)
  ------------------
  |  Branch (4558:6): [True: 3.19k, False: 26.2k]
  ------------------
 4559|  3.19k|		*touch_policy = 0x00;
 4560|  29.4k|	if (info) {
  ------------------
  |  Branch (4560:6): [True: 23.8k, False: 5.58k]
  ------------------
 4561|  23.8k|		info->algorithm = 0;
 4562|  23.8k|		info->pubkey.value = NULL;
 4563|  23.8k|		info->pubkey.len = 0;
 4564|  23.8k|	}
 4565|       |
 4566|  29.4k|	if (priv->yubico_version < 0x00050300) {
  ------------------
  |  Branch (4566:6): [True: 17.3k, False: 12.0k]
  ------------------
 4567|  17.3k|		if (priv->yubico_version != 0)
  ------------------
  |  Branch (4567:7): [True: 2.57k, False: 14.7k]
  ------------------
 4568|  2.57k|			sc_log(card->ctx, "Yubikey's Get metadata extension not available");
  ------------------
  |  |   71|  2.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4569|  17.3k|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  17.3k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4570|  17.3k|	}
 4571|       |
 4572|  41.0k|	for (i = 0; i < (PIV_NUM_YK_SLOT_INFO - 1); i++) {
  ------------------
  |  |  389|  41.0k|#define PIV_NUM_YK_SLOT_INFO 26
  ------------------
  |  Branch (4572:14): [True: 41.0k, False: 0]
  ------------------
 4573|  41.0k|		if (priv->yk_slot_info[i].slot == 0x00)
  ------------------
  |  Branch (4573:7): [True: 11.3k, False: 29.6k]
  ------------------
 4574|       |			/* reached the last initialized entry */
 4575|  11.3k|			break;
 4576|       |
 4577|  29.6k|		if (priv->yk_slot_info[i].slot == slot) {
  ------------------
  |  Branch (4577:7): [True: 701, False: 28.9k]
  ------------------
 4578|       |			/* metadata already initialized */
 4579|    701|			if (priv->yk_slot_info[i].invalid)
  ------------------
  |  Branch (4579:8): [True: 342, False: 359]
  ------------------
 4580|       |				/* already failed don't try again */
 4581|    342|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    342|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4582|    359|			break;
 4583|    701|		}
 4584|  29.6k|	}
 4585|       |
 4586|  11.7k|	if (priv->yk_slot_info[i].slot == 0x00) {
  ------------------
  |  Branch (4586:6): [True: 11.3k, False: 359]
  ------------------
 4587|       |		/* initialize this entry */
 4588|  11.3k|		rc = piv_general_io(card, 0xF7, 0x00, slot, NULL, 0, resp, sizeof(resp));
 4589|       |
 4590|  11.3k|		if (rc >= 0) { /* set defaults */
  ------------------
  |  Branch (4590:7): [True: 1.40k, False: 9.97k]
  ------------------
 4591|  1.40k|			priv->yk_slot_info[i].slot = slot;
 4592|  1.40k|		}
 4593|       |
 4594|  11.3k|		if (rc > 2) { /* at least 1 TLV */
  ------------------
  |  Branch (4594:7): [True: 700, False: 10.6k]
  ------------------
 4595|    700|			resplen = rc;
 4596|    700|			rc = piv_yk_metadata_get_policy(card->ctx, resp, resplen,
 4597|    700|					&priv->yk_slot_info[i].policy, &priv->yk_slot_info[i].touch);
 4598|    700|			if (SC_SUCCESS == rc) {
  ------------------
  |  |   28|    700|#define SC_SUCCESS				0
  ------------------
  |  Branch (4598:8): [True: 32, False: 668]
  ------------------
 4599|     32|				sc_log(card->ctx, "PIN policy for slot 0x%02X: 0x%02X (touch 0x%02X)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4600|     32|						slot, priv->yk_slot_info[i].policy, priv->yk_slot_info[i].touch);
 4601|     32|			}
 4602|    700|			rc = piv_yk_metadata_get_pubkey_info(card->ctx, resp, resplen, &priv->yk_slot_info[i]);
 4603|    700|			if (SC_SUCCESS == rc) {
  ------------------
  |  |   28|    700|#define SC_SUCCESS				0
  ------------------
  |  Branch (4603:8): [True: 18, False: 682]
  ------------------
 4604|     18|				sc_log(card->ctx, "Public key for slot 0x%02X: present", slot);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4605|     18|			}
 4606|  10.6k|		} else {
 4607|  10.6k|			sc_log(card->ctx, "Could not get Yubikey's PIN and touch policy");
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
 4608|  10.6k|			priv->yk_slot_info[i].invalid = 1;
 4609|  10.6k|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  10.6k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 4610|  10.6k|		}
 4611|  11.3k|	} else if (priv->yk_slot_info[i].slot != slot) {
  ------------------
  |  Branch (4611:13): [True: 0, False: 359]
  ------------------
 4612|      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__
  |  |  ------------------
  ------------------
 4613|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4614|      0|	}
 4615|       |
 4616|  1.05k|	if (pin_policy)
  ------------------
  |  Branch (4616:6): [True: 158, False: 901]
  ------------------
 4617|    158|		*pin_policy = priv->yk_slot_info[i].policy;
 4618|  1.05k|	if (touch_policy)
  ------------------
  |  Branch (4618:6): [True: 368, False: 691]
  ------------------
 4619|    368|		*touch_policy = priv->yk_slot_info[i].touch;
 4620|  1.05k|	if (info) {
  ------------------
  |  Branch (4620:6): [True: 533, False: 526]
  ------------------
 4621|    533|		info->algorithm = priv->yk_slot_info[i].algorithm;
 4622|    533|		info->pubkey.value = priv->yk_slot_info[i].pubkey.value;
 4623|    533|		info->pubkey.len = priv->yk_slot_info[i].pubkey.len;
 4624|    533|	}
 4625|       |
 4626|  1.05k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.05k|#define SC_SUCCESS				0
  ------------------
 4627|  11.7k|}
card-piv.c:piv_yk_metadata_get_policy:
 4501|    700|{
 4502|    700|	size_t policylen;
 4503|    700|	const u8 *policy = sc_asn1_find_tag(ctx, buf, buflen, 0x02, &policylen);
 4504|    700|	if (policy && policylen == 2) {
  ------------------
  |  Branch (4504:6): [True: 79, False: 621]
  |  Branch (4504:16): [True: 32, False: 47]
  ------------------
 4505|     32|		*pin = policy[0];
 4506|     32|		*touch = policy[1];
 4507|     32|		return SC_SUCCESS;
  ------------------
  |  |   28|     32|#define SC_SUCCESS				0
  ------------------
 4508|    668|	} else {
 4509|    668|		sc_log(ctx, "Yubikey PIN policy not found");
  ------------------
  |  |   71|    668|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4510|    668|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    668|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4511|    668|	}
 4512|    700|}
card-piv.c:piv_yk_metadata_get_pubkey_info:
 4516|    700|{
 4517|    700|	size_t tag_len = 0;
 4518|    700|	const u8 *pk = NULL;
 4519|       |
 4520|       |	/*  Tag 0x01: Algorithm/type of key */
 4521|    700|	pk = sc_asn1_find_tag(ctx, buf, buflen, 0x01, &tag_len);
 4522|    700|	if (pk && tag_len == 1) {
  ------------------
  |  Branch (4522:6): [True: 159, False: 541]
  |  Branch (4522:12): [True: 79, False: 80]
  ------------------
 4523|     79|		info->algorithm = pk[0];
 4524|    621|	} else {
 4525|    621|		sc_log(ctx, "Yubikey algorithm not found");
  ------------------
  |  |   71|    621|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4526|    621|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    621|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4527|    621|	}
 4528|       |
 4529|       |	/*  Tag 0x04: Public key */
 4530|     79|	pk = sc_asn1_find_tag(ctx, buf, buflen, 0x04, &tag_len);
 4531|     79|	if (pk && tag_len > 0) {
  ------------------
  |  Branch (4531:6): [True: 28, False: 51]
  |  Branch (4531:12): [True: 18, False: 10]
  ------------------
 4532|     18|		info->pubkey.value = malloc(tag_len);
 4533|     18|		if (info->pubkey.value == NULL) {
  ------------------
  |  Branch (4533:7): [True: 0, False: 18]
  ------------------
 4534|      0|			return SC_ERROR_MEMORY_FAILURE;
  ------------------
  |  |   57|      0|#define SC_ERROR_MEMORY_FAILURE			-1207
  ------------------
 4535|      0|		}
 4536|     18|		memcpy(info->pubkey.value, pk, tag_len);
 4537|     18|		info->pubkey.len = tag_len;
 4538|     61|	} else {
 4539|     61|		sc_log(ctx, "Yubikey public key not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4540|     61|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     61|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 4541|     61|	}
 4542|       |
 4543|     18|	return SC_SUCCESS;
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
 4544|     79|}
card-piv.c:piv_decipher:
 5011|    759|{
 5012|    759|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    759|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    759|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    759|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 759]
  |  |  ------------------
  ------------------
 5013|       |
 5014|    759|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, piv_validate_general_authentication(card, data, datalen, out, outlen));
  ------------------
  |  |  153|    759|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    759|	int _ret = r; \
  |  |  155|    759|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 758, False: 1]
  |  |  ------------------
  |  |  156|    758|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    758|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 758, False: 0]
  |  |  ------------------
  |  |  157|    758|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    758|	} 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|    759|	return _ret; \
  |  |  163|    759|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 5015|    759|}
card-piv.c:piv_check_sw:
 6315|  50.6k|{
 6316|  50.6k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6317|       |
 6318|  50.6k|	int r;
 6319|       |#ifdef ENABLE_PIV_SM
 6320|       |	int i;
 6321|       |#endif
 6322|  50.6k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  50.6k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6323|       |
 6324|  50.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  50.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  50.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  50.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 50.6k]
  |  |  ------------------
  ------------------
 6325|       |
 6326|       |	/* may be called before piv_init has allocated priv */
 6327|  50.6k|	if (priv) {
  ------------------
  |  Branch (6327:6): [True: 50.6k, False: 0]
  ------------------
 6328|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6329|       |
 6330|  50.6k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6330:7): [True: 3.54k, False: 47.0k]
  ------------------
 6331|  3.54k|			priv->pin_cmd_verify_sw1 = sw1;
 6332|  3.54k|			priv->pin_cmd_verify_sw2 = sw2;
 6333|  47.0k|		} else {
 6334|       |			/* a command has completed and it is not verify
 6335|       |			 * If we are in a context_specific sequence, unlock
 6336|       |			 * This just decrements the extra lock count
 6337|       |			 */
 6338|  47.0k|			if (priv->context_specific) {
  ------------------
  |  Branch (6338:8): [True: 0, False: 47.0k]
  ------------------
 6339|      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__
  |  |  ------------------
  ------------------
 6340|      0|				priv->context_specific = 0;
 6341|      0|				sc_unlock(card);
 6342|      0|			}
 6343|  47.0k|		}
 6344|       |
 6345|  50.6k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  591|  50.6k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6345:7): [True: 10.7k, False: 39.8k]
  ------------------
 6346|       |
 6347|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6348|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6349|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6350|       |			 */
 6351|  10.7k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6351:8): [True: 1.34k, False: 9.40k]
  |  Branch (6351:32): [True: 46, False: 1.30k]
  ------------------
 6352|     46|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6353|     46|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6353:9): [True: 19, False: 27]
  ------------------
 6354|     19|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6355|     19|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     19|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6356|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6357|     19|				}
 6358|     46|			}
 6359|  10.7k|		}
 6360|  50.6k|	}
 6361|       |#ifdef ENABLE_PIV_SM
 6362|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6363|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6364|       |	/* we stashed the sw1 and sw2 above for verify */
 6365|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6366|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6367|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6368|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6369|       |			return piv_sm_errors[i].errorno;
 6370|       |		}
 6371|       |	}
 6372|       |#endif
 6373|  50.5k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6374|  50.5k|	return r;
 6375|  50.6k|}
card-piv.c:piv_card_ctl:
 4653|  97.3k|{
 4654|  97.3k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  97.3k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4655|  97.3k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4656|       |
 4657|  97.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  97.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  97.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  97.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  97.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 97.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4658|       |
 4659|  97.3k|	if (priv == NULL) {
  ------------------
  |  Branch (4659:6): [True: 0, False: 97.3k]
  ------------------
 4660|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4661|      0|	}
 4662|  97.3k|	switch (cmd) {
  ------------------
  |  Branch (4662:10): [True: 97.3k, False: 0]
  ------------------
 4663|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4663:2): [True: 0, False: 97.3k]
  ------------------
 4664|      0|		opts = (u8 *)ptr;
 4665|      0|		switch (*opts) {
  ------------------
  |  Branch (4665:11): [True: 0, False: 0]
  ------------------
 4666|      0|		case 'A':
  ------------------
  |  Branch (4666:3): [True: 0, False: 0]
  ------------------
 4667|      0|			return piv_general_external_authenticate(card,
 4668|      0|					*(opts + 1), *(opts + 2));
 4669|      0|			break;
 4670|      0|		case 'M':
  ------------------
  |  Branch (4670:3): [True: 0, False: 0]
  ------------------
 4671|      0|			return piv_general_mutual_authenticate(card,
 4672|      0|					*(opts + 1), *(opts + 2));
 4673|      0|			break;
 4674|      0|		}
 4675|      0|		break;
 4676|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4676:2): [True: 0, False: 97.3k]
  ------------------
 4677|      0|		return piv_generate_key(card,
 4678|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4679|      0|		break;
 4680|  1.11k|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4680:2): [True: 1.11k, False: 96.2k]
  ------------------
 4681|  1.11k|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4682|      0|		break;
 4683|  1.11k|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4683:2): [True: 1.11k, False: 96.2k]
  ------------------
 4684|  1.11k|		return piv_get_pin_preference(card, ptr);
 4685|      0|		break;
 4686|  68.8k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4686:2): [True: 68.8k, False: 28.4k]
  ------------------
 4687|  68.8k|		return piv_is_object_present(card, ptr);
 4688|      0|		break;
 4689|  2.39k|	case SC_CARDCTL_PIV_YK_PIN_POLICY:
  ------------------
  |  Branch (4689:2): [True: 2.39k, False: 94.9k]
  ------------------
 4690|  2.39k|		return piv_yk_pin_policy(card, ptr);
 4691|      0|		break;
 4692|  23.8k|	case SC_CARDCTL_PIV_YK_GET_PUBKEY_INFO:
  ------------------
  |  Branch (4692:2): [True: 23.8k, False: 73.4k]
  ------------------
 4693|  23.8k|		return piv_yk_get_pubkey(card, ptr);
 4694|      0|		break;
 4695|  97.3k|	}
 4696|       |
 4697|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4698|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4381|  1.11k|{
 4382|  1.11k|	int r;
 4383|  1.11k|	int i;
 4384|  1.11k|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4385|  1.11k|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4386|  1.11k|	u8 *rbuf = NULL;
 4387|  1.11k|	const u8 *body;
 4388|  1.11k|	const u8 *fascn;
 4389|  1.11k|	const u8 *guid;
 4390|  1.11k|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4391|       |
 4392|  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]
  |  |  ------------------
  ------------------
 4393|  1.11k|	if (card->serialnr.len) {
  ------------------
  |  Branch (4393:6): [True: 0, False: 1.11k]
  ------------------
 4394|      0|		*serial = card->serialnr;
 4395|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4396|      0|	}
 4397|       |
 4398|       |	/*
 4399|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4400|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4401|       |	 * based on RFC 4122. If GUID present and not zero
 4402|       |	 * we will use the GUID as the serial number.
 4403|       |	 */
 4404|       |
 4405|  1.11k|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4406|  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.05k, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  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.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4407|       |
 4408|     61|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     61|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4409|     61|	if (rbuflen != 0) {
  ------------------
  |  Branch (4409:6): [True: 61, False: 0]
  ------------------
 4410|     61|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4411|     61|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4411:7): [True: 61, False: 0]
  |  Branch (4411:23): [True: 57, False: 4]
  |  Branch (4411:39): [True: 57, False: 0]
  ------------------
 4412|     57|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4413|       |
 4414|     57|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4414:8): [True: 36, False: 21]
  |  Branch (4414:17): [True: 34, False: 2]
  ------------------
 4415|    884|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4415:17): [True: 850, False: 34]
  ------------------
 4416|    850|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4416:14): [True: 686, False: 164]
  |  Branch (4416:23): [True: 33, False: 131]
  ------------------
 4417|    850|				}
 4418|     34|			}
 4419|       |
 4420|     57|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4421|       |
 4422|     57|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4422:8): [True: 14, False: 43]
  |  Branch (4422:16): [True: 10, False: 4]
  ------------------
 4423|    170|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4423:17): [True: 160, False: 10]
  ------------------
 4424|    160|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4425|    160|				}
 4426|     10|			}
 4427|     57|			sc_log(card->ctx, "fascn=%p,fascnlen=%zu,guid=%p,guidlen=%zu,gbits=%2.2x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4428|     57|					fascn, fascnlen, guid, guidlen, gbits);
 4429|       |
 4430|     57|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4430:8): [True: 36, False: 21]
  |  Branch (4430:17): [True: 34, False: 2]
  |  Branch (4430:35): [True: 33, False: 1]
  ------------------
 4431|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4432|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4433|     33|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4433:11): [True: 9, False: 24]
  |  Branch (4433:20): [True: 4, False: 5]
  |  Branch (4433:40): [True: 3, False: 1]
  ------------------
 4434|     32|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4434:11): [True: 2, False: 1]
  |  Branch (4434:31): [True: 1, False: 1]
  ------------------
 4435|       |					/* fascnlen is 25 */
 4436|     32|					serial->len = fascnlen;
 4437|     32|					memcpy(serial->value, fascn, serial->len);
 4438|     32|					r = SC_SUCCESS;
  ------------------
  |  |   28|     32|#define SC_SUCCESS				0
  ------------------
 4439|     32|					gbits = 0; /* set to skip using guid below */
 4440|     32|				}
 4441|     33|			}
 4442|     57|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4442:8): [True: 14, False: 43]
  |  Branch (4442:16): [True: 10, False: 4]
  |  Branch (4442:33): [True: 2, False: 8]
  ------------------
 4443|      2|				serial->len = guidlen;
 4444|      2|				memcpy(serial->value, guid, serial->len);
 4445|      2|				r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 4446|      2|			}
 4447|     57|		}
 4448|     61|	}
 4449|       |
 4450|     61|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4450:6): [True: 28, False: 33]
  |  Branch (4450:20): [True: 27, False: 1]
  ------------------
 4451|     27|		serial->len = 16;
 4452|     27|		memset(serial->value, 0x00, serial->len);
 4453|     27|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     27|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4454|     27|	}
 4455|       |
 4456|     61|	card->serialnr = *serial;
 4457|     61|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     61|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     61|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     61|	int _ret = r; \
  |  |  |  |  155|     61|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     27|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 27, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4458|     61|}
card-piv.c:piv_get_pin_preference:
 4492|  1.11k|{
 4493|  1.11k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  1.11k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4494|       |
 4495|  1.11k|	*pin_ref = priv->pin_preference;
 4496|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4497|  1.11k|}
card-piv.c:piv_is_object_present:
 4473|  68.8k|{
 4474|  68.8k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  68.8k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4475|  68.8k|	int r = 0;
 4476|  68.8k|	int enumtag;
 4477|       |
 4478|  68.8k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4479|  68.8k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  153|  67.7k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4479:6): [True: 67.7k, False: 1.11k]
  |  Branch (4479:22): [True: 38.4k, False: 29.3k]
  ------------------
 4480|  38.4k|		r = 1;
 4481|       |
 4482|  68.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  68.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  68.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  68.8k|	int _ret = r; \
  |  |  |  |  155|  68.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30.4k, False: 38.4k]
  |  |  |  |  ------------------
  |  |  |  |  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.4k|	} else { \
  |  |  |  |  159|  38.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  38.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  38.4k|	} \
  |  |  |  |  162|  68.8k|	return _ret; \
  |  |  |  |  163|  68.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4483|  68.8k|}
card-piv.c:piv_yk_pin_policy:
 4631|  2.39k|{
 4632|  2.39k|	u8 slot = *ptr;
 4633|  2.39k|	LOG_FUNC_RETURN(card->ctx, piv_yk_get_metadata(card, slot, ptr, NULL, NULL));
  ------------------
  |  |  164|  2.39k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.39k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.39k|	int _ret = r; \
  |  |  |  |  155|  2.39k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.39k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.39k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.23k, False: 158]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.39k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.39k|	} else { \
  |  |  |  |  159|      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.39k|	return _ret; \
  |  |  |  |  163|  2.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4634|  2.39k|}
card-piv.c:piv_yk_get_pubkey:
 4638|  23.8k|{
 4639|  23.8k|	int rc;
 4640|  23.8k|	u8 slot = info->slot;
 4641|       |
 4642|  23.8k|	rc = piv_yk_get_metadata(card, slot, NULL, NULL, info);
 4643|  23.8k|	LOG_TEST_RET(card->ctx, rc, "piv_yk_get_metadata failed");
  ------------------
  |  |  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: 23.3k, False: 533]
  |  |  |  |  ------------------
  |  |  |  |  169|  23.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|  23.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  23.3k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  23.3k|		return _ret; \
  |  |  |  |  172|  23.3k|	} \
  |  |  |  |  173|  23.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 533]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4644|    533|	if (info->pubkey.value == NULL || info->pubkey.len == 0 || info->algorithm == 0) {
  ------------------
  |  Branch (4644:6): [True: 515, False: 18]
  |  Branch (4644:36): [True: 0, False: 18]
  |  Branch (4644:61): [True: 1, False: 17]
  ------------------
 4645|    516|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_NOT_FOUND);
  ------------------
  |  |  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|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4646|    516|	}
 4647|       |
 4648|     17|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4649|     17|}
card-piv.c:piv_pin_cmd:
 6448|  2.57k|{
 6449|  2.57k|	int r = 0;
 6450|  2.57k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|  2.57k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6451|       |
 6452|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6453|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6454|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6455|       |	 */
 6456|  2.57k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6457|       |
 6458|  2.57k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.57k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.57k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.57k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.57k]
  |  |  ------------------
  ------------------
 6459|  2.57k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  2.57k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6460|  2.57k|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  416|  2.57k|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6460:6): [True: 108, False: 2.46k]
  ------------------
 6461|    108|		size_t i = 0;
 6462|    108|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6462:7): [True: 24, False: 84]
  ------------------
 6463|     24|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     24|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6464|     24|		}
 6465|    420|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6465:15): [True: 378, False: 42]
  ------------------
 6466|    378|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6466:8): [True: 42, False: 336]
  ------------------
 6467|     42|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     42|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6468|     42|			}
 6469|    378|		}
 6470|     84|	}
 6471|       |
 6472|  2.50k|	priv->pin_cmd_verify_sw1 = 0x00U;
 6473|       |
 6474|  2.50k|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  418|  2.50k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6474:6): [True: 2.18k, False: 323]
  ------------------
 6475|  2.18k|		data->pin1.logged_in = priv->logged_in;
 6476|  2.18k|		data->pin1.tries_left = priv->tries_left;
 6477|       |
 6478|       |		/*
 6479|       |		 * If called to check on the login state for a context specific login
 6480|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6481|       |		 */
 6482|  2.18k|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|  2.18k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6482:7): [True: 0, False: 2.18k]
  ------------------
 6483|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6484|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6485|      0|		}
 6486|       |
 6487|  2.18k|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  432|  2.18k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6487:7): [True: 47, False: 2.13k]
  ------------------
 6488|       |			/* Avoid status requests when the user is logged in to handle NIST
 6489|       |			 * 800-73-4 Part 2:
 6490|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6491|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6492|       |			 * PIN or OCC data must be submitted and verified every time
 6493|       |			 * immediately before a digital signature key operation.  This
 6494|       |			 * ensures cardholder participation every time the private key is
 6495|       |			 * used for digital signature generation */
 6496|     47|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     47|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     47|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     47|	int _ret = r; \
  |  |  |  |  155|     47|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 47, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  157|     47|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     47|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     47|	return _ret; \
  |  |  |  |  163|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6497|     47|		}
 6498|  2.18k|	}
 6499|       |
 6500|       |	/*
 6501|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6502|       |	 * to avoid any interference from other applications.
 6503|       |	 * Sc_unlock will be called at a later time after the next card command
 6504|       |	 * that should be a crypto operation. If its not then it is a error by the
 6505|       |	 * calling application.
 6506|       |	 */
 6507|  2.45k|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  415|  4.91k|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    173|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6507:6): [True: 173, False: 2.28k]
  |  Branch (6507:40): [True: 0, False: 173]
  ------------------
 6508|      0|		priv->context_specific = 1;
 6509|      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__
  |  |  ------------------
  ------------------
 6510|      0|		r = sc_lock(card);
 6511|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6511:7): [True: 0, False: 0]
  ------------------
 6512|      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__
  |  |  ------------------
  ------------------
 6513|      0|			return r;
 6514|      0|		}
 6515|      0|	}
 6516|       |
 6517|  2.45k|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6518|  2.45k|	r = iso_drv->ops->pin_cmd(card, data);
 6519|  2.45k|	priv->pin_cmd_verify = 0;
 6520|       |
 6521|       |	/* tell user verify not supported on contactless without VCI */
 6522|  2.45k|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6522:6): [True: 55, False: 2.40k]
  |  Branch (6522:42): [True: 25, False: 30]
  ------------------
 6523|     25|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  385|  2.48k|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6523:4): [True: 10, False: 15]
  ------------------
 6524|     10|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6524:4): [True: 0, False: 10]
  ------------------
 6525|      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__
  |  |  ------------------
  ------------------
 6526|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6527|      0|	}
 6528|       |
 6529|       |	/* if verify failed, release the lock */
 6530|  2.45k|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  415|  4.91k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6530:6): [True: 173, False: 2.28k]
  |  Branch (6530:40): [True: 137, False: 36]
  |  Branch (6530:49): [True: 0, False: 137]
  ------------------
 6531|      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__
  |  |  ------------------
  ------------------
 6532|      0|		priv->context_specific = 0;
 6533|      0|		sc_unlock(card);
 6534|      0|	}
 6535|       |
 6536|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6537|  2.45k|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  600|  4.91k|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6537:6): [True: 1.23k, False: 1.22k]
  |  Branch (6537:53): [True: 1.08k, False: 143]
  ------------------
 6538|  1.08k|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6539|  1.08k|		piv_find_aid(card);
 6540|       |
 6541|  1.08k|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6542|  1.08k|		r = iso_drv->ops->pin_cmd(card, data);
 6543|  1.08k|		priv->pin_cmd_verify = 0;
 6544|  1.08k|	}
 6545|       |
 6546|       |	/* If verify worked, we are logged_in */
 6547|  2.45k|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  415|  2.45k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6547:6): [True: 173, False: 2.28k]
  ------------------
 6548|    173|		if (r >= 0) {
  ------------------
  |  Branch (6548:7): [True: 37, False: 136]
  ------------------
 6549|     37|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|     37|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6550|       |			/* the card reset its retry counter; the reset value is issuer dependent */
 6551|     37|			priv->tries_left = -1;
 6552|    136|		} else {
 6553|    136|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|    136|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6554|    136|		}
 6555|    173|	}
 6556|       |
 6557|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6558|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6559|       |
 6560|  2.45k|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  418|  2.45k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6560:6): [True: 2.13k, False: 323]
  ------------------
 6561|  2.13k|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  595|  2.13k|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6561:7): [True: 6, False: 2.12k]
  ------------------
 6562|      6|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6563|      6|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6564|  2.12k|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  592|  4.25k|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6564:14): [True: 657, False: 1.47k]
  ------------------
 6565|    657|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6565:5): [True: 19, False: 638]
  ------------------
 6566|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6567|     19|			r = piv_check_protected_objects(card);
 6568|     19|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
  |  Branch (6568:8): [True: 2, False: 17]
  ------------------
 6569|      2|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|      2|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6570|     17|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|     17|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6570:13): [True: 15, False: 2]
  ------------------
 6571|     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 (6571:9): [True: 6, False: 9]
  ------------------
 6572|       |
 6573|      6|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6574|      9|				} else {
 6575|      9|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      9|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6576|      9|				}
 6577|     15|				r = SC_SUCCESS;
  ------------------
  |  |   28|     15|#define SC_SUCCESS				0
  ------------------
 6578|     15|			}
 6579|     19|		}
 6580|  2.13k|		priv->logged_in = data->pin1.logged_in;
 6581|  2.13k|		priv->tries_left = data->pin1.tries_left;
 6582|  2.13k|	}
 6583|       |
 6584|  2.45k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
 6585|  2.45k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.45k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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: 2.45k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  2.35k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.35k, False: 107]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.45k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.45k|	return _ret; \
  |  |  |  |  163|  2.45k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6586|  2.45k|}
card-piv.c:piv_check_protected_objects:
 6379|     19|{
 6380|     19|	int r = 0;
 6381|     19|	int i;
 6382|     19|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  447|     19|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6383|     19|	u8 buf[8]; /* tag of 53 with 82 xx xx  will fit in 4 */
 6384|     19|	u8 *rbuf;
 6385|     19|	size_t buf_len;
 6386|     19|	static int protected_objects[] = {PIV_OBJ_PI, PIV_OBJ_CHF, PIV_OBJ_IRIS_IMAGE};
 6387|       |
 6388|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6389|       |	/*
 6390|       |	 * routine only called from piv_pin_cmd after verify lc=0 did not return 90 00
 6391|       |	 * We will test for a protected object using GET DATA.
 6392|       |	 *
 6393|       |	 * Based on observations, of cards using the GET DATA APDU,
 6394|       |	 * SC_ERROR_SECURITY_STATUS_NOT_SATISFIED  means the PIN not verified,
 6395|       |	 * SC_SUCCESS means PIN has been verified even if it has length 0
 6396|       |	 * SC_ERROR_FILE_NOT_FOUND (which is the bug) does not tell us anything
 6397|       |	 * about the state of the PIN and we will try the next object.
 6398|       |	 *
 6399|       |	 * If we can't determine the security state from this process,
 6400|       |	 * set card_issues CI_CANT_USE_GETDATA_FOR_STATE
 6401|       |	 * and return SC_ERROR_PIN_CODE_INCORRECT
 6402|       |	 * The circumvention is to add a dummy Printed Info object in the card.
 6403|       |	 * so we will have an object to test.
 6404|       |	 *
 6405|       |	 * We save the object's number to use in the future.
 6406|       |	 *
 6407|       |	 */
 6408|     19|	if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6408:6): [True: 15, False: 4]
  ------------------
 6409|     39|		for (i = 0; i < (int)(sizeof(protected_objects) / sizeof(int)); i++) {
  ------------------
  |  Branch (6409:15): [True: 33, False: 6]
  ------------------
 6410|     33|			buf_len = sizeof(buf);
 6411|     33|			rbuf = buf;
 6412|     33|			r = piv_get_data(card, protected_objects[i], &rbuf, &buf_len);
 6413|     33|			if (r >= 0 || r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|     31|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6413:8): [True: 2, False: 31]
  |  Branch (6413:18): [True: 7, False: 24]
  ------------------
 6414|       |
 6415|       |				/* we can use this object next time if needed */
 6416|      9|				priv->object_test_verify = protected_objects[i];
 6417|      9|				break;
 6418|      9|			}
 6419|     33|		}
 6420|     15|		if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6420:7): [True: 6, False: 9]
  ------------------
 6421|       |			/*
 6422|       |			 * none of the objects returned acceptable sw1, sw2
 6423|       |			 */
 6424|      6|			sc_log(card->ctx, "No protected objects found, setting CI_CANT_USE_GETDATA_FOR_STATE");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6425|      6|			priv->card_issues |= CI_CANT_USE_GETDATA_FOR_STATE;
  ------------------
  |  |  595|      6|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
 6426|      6|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      6|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6427|      6|		}
 6428|     15|	} else {
 6429|       |		/* use the one object we found earlier. Test is security status has changed */
 6430|      4|		buf_len = sizeof(buf);
 6431|      4|		rbuf = buf;
 6432|      4|		r = piv_get_data(card, priv->object_test_verify, &rbuf, &buf_len);
 6433|      4|	}
 6434|     19|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|     19|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (6434:6): [True: 1, False: 18]
  ------------------
 6435|      1|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6436|     18|	else if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|     18|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6436:11): [True: 8, False: 10]
  ------------------
 6437|      8|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      8|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6438|     10|	else if (r > 0)
  ------------------
  |  Branch (6438:11): [True: 2, False: 8]
  ------------------
 6439|      2|		r = SC_SUCCESS;
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
 6440|       |
 6441|     19|	sc_log(card->ctx, "card->type:%d CI:%08x r:%d AI:%08x\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__
  |  |  ------------------
  ------------------
 6442|     19|			card->type, priv->card_issues, r, priv->alg_ids);
 6443|     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|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6444|     19|}
card-piv.c:piv_card_reader_lock_obtained:
 6625|  15.1k|{
 6626|  15.1k|	int r = 0;
 6627|  15.1k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6628|  15.1k|	size_t templen = sizeof(temp);
 6629|  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)
  ------------------
 6630|       |
 6631|  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]
  |  |  ------------------
  ------------------
 6632|       |
 6633|       |	/* We have a PCSC transaction and sc_lock */
 6634|  15.1k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6634:6): [True: 5.89k, False: 9.22k]
  |  Branch (6634:22): [True: 1.11k, False: 8.11k]
  ------------------
 6635|  7.00k|		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.89k]
  |  |  ------------------
  ------------------
 6636|  7.00k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6637|  7.00k|		r = 0; /* do nothing, piv_match will take care of it */
 6638|  7.00k|		goto err;
 6639|  7.00k|	}
 6640|       |
 6641|  8.11k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  8.11k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6642|       |
 6643|       |	/* make sure our application is active */
 6644|       |
 6645|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6646|       |	/* If not try selecting AID */
 6647|       |
 6648|       |	/* but if card does not support DISCOVERY object we can not use it */
 6649|  8.11k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  597|  8.11k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6649:6): [True: 4.22k, False: 3.89k]
  ------------------
 6650|  4.22k|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  4.22k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6651|  4.22k|	} else {
 6652|  3.89k|		r = piv_find_discovery(card);
 6653|       |#ifdef ENABLE_PIV_SM
 6654|       |		/*
 6655|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6656|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6657|       |		 * Discovery object can be read with contact or contactless
 6658|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6659|       |		 * sm.c will close the SM connectrion, and set defer
 6660|       |		 */
 6661|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6662|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6663|       |			piv_sm_open(card);
 6664|       |			r = piv_find_discovery(card);
 6665|       |		}
 6666|       |#endif /* ENABLE_PIV_SM */
 6667|  3.89k|	}
 6668|       |
 6669|  8.11k|	if (r < 0) {
  ------------------
  |  Branch (6669:6): [True: 8.09k, False: 18]
  ------------------
 6670|  8.09k|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  598|  8.09k|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6670:7): [True: 0, False: 8.09k]
  |  Branch (6670:24): [True: 7.58k, False: 517]
  ------------------
 6671|  7.58k|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6672|  7.58k|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  7.58k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6673|  7.58k|		} else {
 6674|    517|			r = 0; /* can't do anything with this card, hope there was no interference */
 6675|    517|		}
 6676|  8.09k|	}
 6677|       |
 6678|  8.11k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6678:6): [True: 7.14k, False: 968]
  ------------------
 6679|  7.14k|		goto err;
 6680|       |
 6681|    968|	if (was_reset > 0)
  ------------------
  |  Branch (6681:6): [True: 0, False: 968]
  ------------------
 6682|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6683|       |
 6684|    968|	r = 0;
 6685|       |
 6686|  15.1k|err:
 6687|  15.1k|	if (priv)
  ------------------
  |  Branch (6687:6): [True: 9.22k, False: 5.89k]
  ------------------
 6688|  9.22k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  384|  9.22k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6689|  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.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.14k, False: 7.96k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6690|  15.1k|}

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

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

sc_get_sc_hsm_driver:
 2020|  16.1k|{
 2021|  16.1k|	return sc_get_driver();
 2022|  16.1k|}
card-sc-hsm.c:sc_get_driver:
 1984|  16.1k|{
 1985|  16.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1986|       |
 1987|  16.1k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1987:6): [True: 1, False: 16.1k]
  ------------------
 1988|      1|		iso_ops = iso_drv->ops;
 1989|       |
 1990|  16.1k|	sc_hsm_ops                   = *iso_drv->ops;
 1991|  16.1k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1992|  16.1k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1993|  16.1k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1994|  16.1k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1995|  16.1k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1996|  16.1k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1997|  16.1k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1998|  16.1k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1999|  16.1k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 2000|  16.1k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 2001|  16.1k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 2002|  16.1k|	sc_hsm_ops.init              = sc_hsm_init;
 2003|  16.1k|	sc_hsm_ops.finish            = sc_hsm_finish;
 2004|  16.1k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 2005|  16.1k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 2006|  16.1k|	sc_hsm_ops.logout            = sc_hsm_logout;
 2007|       |
 2008|       |	/* no record oriented file services */
 2009|  16.1k|	sc_hsm_ops.read_record       = NULL;
 2010|  16.1k|	sc_hsm_ops.write_record      = NULL;
 2011|  16.1k|	sc_hsm_ops.append_record     = NULL;
 2012|  16.1k|	sc_hsm_ops.update_record     = NULL;
 2013|       |
 2014|  16.1k|	return &sc_hsm_drv;
 2015|  16.1k|}
card-sc-hsm.c:sc_hsm_match_card:
  267|  6.33k|{
  268|  6.33k|	sc_path_t path;
  269|  6.33k|	int i, r, type = 0;
  270|  6.33k|	sc_file_t *file = NULL;
  271|       |
  272|  6.33k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  273|  6.33k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (273:6): [True: 258, False: 6.07k]
  |  Branch (273:16): [True: 257, False: 1]
  ------------------
  274|    257|		card->type = type;
  275|    257|		return 1;
  276|    257|	}
  277|       |
  278|  6.08k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  6.08k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  279|  6.08k|	r = sc_hsm_select_file(card, &path, &file);
  280|  6.08k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  6.08k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.08k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.08k|	int _ret = (r); \
  |  |  |  |  168|  6.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.78k, False: 295]
  |  |  |  |  ------------------
  |  |  |  |  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.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 295]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  281|       |
  282|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  283|    295|	if (file != NULL) {
  ------------------
  |  Branch (283:6): [True: 295, False: 0]
  ------------------
  284|    295|		size_t sz = file->prop_attr_len;
  285|    295|		sc_file_free(file);
  286|    295|		if (sz < 2) {
  ------------------
  |  Branch (286:7): [True: 294, False: 1]
  ------------------
  287|    294|			return 0;
  288|    294|		}
  289|    295|	}
  290|       |
  291|      1|	if (type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (291:6): [True: 0, False: 1]
  ------------------
  292|      0|		card->type = SC_CARD_TYPE_SC_HSM_SOC;
  293|      1|	} else {
  294|      1|		card->type = SC_CARD_TYPE_SC_HSM;
  295|      1|	}
  296|       |
  297|      1|	return 1;
  298|    295|}
card-sc-hsm.c:sc_hsm_select_file:
  247|  8.26k|{
  248|  8.26k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  249|  8.26k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  149|  9.75k|{
  150|  9.75k|	int rv;
  151|  9.75k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  152|  9.75k|	sc_file_t *file = NULL;
  153|  9.75k|	sc_path_t cpath;
  154|  9.75k|	size_t card_max_recv_size = card->max_recv_size;
  155|  9.75k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  156|       |
  157|  9.75k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (157:6): [True: 1.23k, False: 8.52k]
  ------------------
  158|  1.23k|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  159|  1.23k|		sc_file_free(file);
  160|  1.23k|		return rv;
  161|  1.23k|	}
  162|       |
  163|  8.52k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  8.52k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (163:6): [True: 86, False: 8.43k]
  |  Branch (163:49): [True: 0, False: 86]
  ------------------
  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.52k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  17.0k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (180:6): [True: 7.19k, False: 1.32k]
  ------------------
  181|  1.32k|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  2.65k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (181:8): [True: 1.24k, False: 86]
  ------------------
  182|  1.24k|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (182:8): [True: 0, False: 1.24k]
  ------------------
  183|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (183:8): [True: 0, False: 0]
  ------------------
  184|  1.32k|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  2.65k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (184:8): [True: 1.24k, False: 86]
  ------------------
  185|  1.24k|				&& in_path->len == 0
  ------------------
  |  Branch (185:8): [True: 0, False: 1.24k]
  ------------------
  186|      0|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  7.19k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (187:8): [True: 0, False: 0]
  ------------------
  188|  7.19k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (188:7): [True: 6.08k, False: 1.11k]
  |  Branch (188:16): [True: 848, False: 263]
  |  Branch (188:41): [True: 0, False: 263]
  ------------------
  189|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  190|  6.92k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|  6.92k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  191|  6.92k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  192|  6.92k|			card->max_recv_size = card_max_recv_size;
  193|  6.92k|			card->reader->max_recv_size = reader_max_recv_size;
  194|  6.92k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  6.92k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.92k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.92k|	int _ret = (r); \
  |  |  |  |  168|  6.92k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.41k, False: 512]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.41k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  6.41k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.41k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.41k|		return _ret; \
  |  |  |  |  172|  6.41k|	} \
  |  |  |  |  173|  6.92k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 512]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    512|			if (priv) {
  ------------------
  |  Branch (196:8): [True: 217, False: 295]
  ------------------
  197|    217|				sc_file_free(priv->dffcp);
  198|       |				// Cache the FCP returned when selecting the applet
  199|    217|				sc_file_dup(&priv->dffcp, *file_out);
  200|    217|			}
  201|    512|		} else {
  202|    263|			sc_file_dup(file_out, priv->dffcp);
  203|    263|			rv = SC_SUCCESS;
  ------------------
  |  |   28|    263|#define SC_SUCCESS				0
  ------------------
  204|    263|		}
  205|    775|		return rv;
  206|  7.19k|	}
  207|       |
  208|  1.32k|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (208:6): [True: 1.32k, False: 0]
  |  Branch (208:29): [True: 771, False: 558]
  |  Branch (208:60): [True: 768, False: 3]
  ------------------
  209|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  210|    768|		if (in_path->len == 2) {
  ------------------
  |  Branch (210:7): [True: 0, False: 768]
  ------------------
  211|      0|			file = sc_file_new();
  212|      0|			if (file == NULL)
  ------------------
  |  Branch (212:8): [True: 0, False: 0]
  ------------------
  213|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  214|      0|			file->path = *in_path;
  215|      0|			file->id = 0x3F00;
  216|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  217|      0|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  218|       |
  219|      0|			*file_out = file;
  220|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  221|    768|		} else {
  222|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  223|    768|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    768|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  224|    768|			sc_path_t truncated;
  225|    768|			memcpy(&truncated, in_path, sizeof truncated);
  226|    768|			truncated.len = in_path->len - 2;
  227|    768|			memcpy(truncated.value, in_path->value+2, truncated.len);
  228|    768|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  229|    768|			card->max_recv_size = card_max_recv_size;
  230|    768|			card->reader->max_recv_size = reader_max_recv_size;
  231|    768|			return rv;
  232|    768|		}
  233|    768|	}
  234|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  235|    561|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  384|    561|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  236|    561|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  237|    561|	card->max_recv_size = card_max_recv_size;
  238|    561|	card->reader->max_recv_size = reader_max_recv_size;
  239|    561|	return rv;
  240|  1.32k|}
card-sc-hsm.c:sc_hsm_read_binary:
  802|    396|{
  803|    396|	sc_context_t *ctx = card->ctx;
  804|    396|	sc_apdu_t apdu;
  805|    396|	u8 cmdbuff[4];
  806|    396|	int r;
  807|       |
  808|    396|	if (idx > 0xffff) {
  ------------------
  |  Branch (808:6): [True: 0, False: 396]
  ------------------
  809|      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__
  |  |  ------------------
  ------------------
  810|      0|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  811|      0|	}
  812|       |
  813|    396|	cmdbuff[0] = 0x54;
  814|    396|	cmdbuff[1] = 0x02;
  815|    396|	cmdbuff[2] = (idx >> 8) & 0xFF;
  816|    396|	cmdbuff[3] = idx & 0xFF;
  817|       |
  818|    396|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (818:6): [True: 0, False: 396]
  ------------------
  819|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  820|    396|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    396|#define SC_APDU_CASE_4			0x24
  ------------------
  821|    396|	apdu.data = cmdbuff;
  822|    396|	apdu.datalen = 4;
  823|    396|	apdu.lc = 4;
  824|    396|	apdu.le = count;
  825|    396|	apdu.resplen = count;
  826|    396|	apdu.resp = buf;
  827|       |
  828|    396|	r = sc_transmit_apdu(card, &apdu);
  829|    396|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    396|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    396|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    396|	int _ret = (r); \
  |  |  |  |  168|    396|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 390]
  |  |  |  |  ------------------
  |  |  |  |  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|    396|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 390]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|       |
  831|    390|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  832|    390|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    390|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (832:6): [True: 334, False: 56]
  ------------------
  833|    334|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  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: 55, False: 279]
  |  |  |  |  ------------------
  |  |  |  |  169|     55|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     55|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     55|		return _ret; \
  |  |  |  |  172|     55|	} \
  |  |  |  |  173|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 279]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  834|    334|	}
  835|       |
  836|    335|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    335|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    335|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    335|	int _ret = r; \
  |  |  |  |  155|    335|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 319]
  |  |  |  |  ------------------
  |  |  |  |  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|    319|	} else { \
  |  |  |  |  159|    319|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    319|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    319|	} \
  |  |  |  |  162|    335|	return _ret; \
  |  |  |  |  163|    335|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  837|    335|}
card-sc-hsm.c:sc_hsm_set_security_env:
 1007|  1.61k|{
 1008|  1.61k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1009|       |
 1010|  1.61k|	priv->env = env;
 1011|       |
 1012|  1.61k|	switch(env->algorithm) {
 1013|  1.61k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|  1.61k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1013:2): [True: 1.61k, False: 0]
  ------------------
 1014|  1.61k|		if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) {
  ------------------
  |  |  111|  1.61k|#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.61k|#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.61k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1014:7): [True: 0, False: 1.61k]
  ------------------
 1015|      0|			if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1) {
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1015:8): [True: 0, False: 0]
  ------------------
 1016|      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 */
  ------------------
 1017|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256) {
  ------------------
  |  |  138|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (1017:15): [True: 0, False: 0]
  ------------------
 1018|      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 */
  ------------------
 1019|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA384) {
  ------------------
  |  |  139|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  |  Branch (1019:15): [True: 0, False: 0]
  ------------------
 1020|      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 */
  ------------------
 1021|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA512) {
  ------------------
  |  |  140|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  |  Branch (1021:15): [True: 0, False: 0]
  ------------------
 1022|      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 */
  ------------------
 1023|      0|			} else {
 1024|      0|				priv->algorithm = ALGO_RSA_PKCS1;
  ------------------
  |  |   40|      0|#define ALGO_RSA_PKCS1		0x30		/* RSA signature with DigestInfo input and PKCS#1 V1.5 padding */
  ------------------
 1025|      0|			}
 1026|  1.61k|		} else if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  107|  1.61k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1026:14): [True: 690, False: 920]
  ------------------
 1027|    690|			if ((env->algorithm_flags & SC_ALGORITHM_RSA_HASHES) &&
  ------------------
  |  |  142|    690|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1027:8): [True: 0, False: 690]
  ------------------
 1028|      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 (1028:6): [True: 0, False: 0]
  ------------------
 1029|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1030|      0|			}
 1031|    690|			priv->algorithm = ALGO_RSA_PSS;
  ------------------
  |  |   46|    690|#define ALGO_RSA_PSS	    0x40 /* RSA signature with external hash and PKCS#1 PSS padding*/
  ------------------
 1032|    920|		} else {
 1033|    920|			if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   47|    920|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1033:8): [True: 230, False: 690]
  ------------------
 1034|    230|				priv->algorithm = ALGO_RSA_DECRYPT;
  ------------------
  |  |   39|    230|#define ALGO_RSA_DECRYPT	0x21		/* RSA decrypt */
  ------------------
 1035|    690|			} else {
 1036|    690|				priv->algorithm = ALGO_RSA_RAW;
  ------------------
  |  |   38|    690|#define ALGO_RSA_RAW		0x20		/* RSA signature with external padding */
  ------------------
 1037|    690|			}
 1038|    920|		}
 1039|  1.61k|		break;
 1040|  1.61k|	case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1040:2): [True: 0, False: 1.61k]
  ------------------
 1041|      0|		if (env->operation == SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   50|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1041:7): [True: 0, False: 0]
  ------------------
 1042|      0|			priv->algorithm = ALGO_EC_DH;
  ------------------
  |  |   58|      0|#define ALGO_EC_DH     0x80 /* ECDH key derivation */
  ------------------
 1043|      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 (1043:14): [True: 0, False: 0]
  ------------------
 1044|      0|			priv->algorithm = ALGO_EC_RAW;
  ------------------
  |  |   52|      0|#define ALGO_EC_RAW    0x70 /* ECDSA signature with hash input */
  ------------------
 1045|      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 (1045:14): [True: 0, False: 0]
  ------------------
 1046|      0|			priv->algorithm = ALGO_EC_SHA1;
  ------------------
  |  |   53|      0|#define ALGO_EC_SHA1   0x71 /* ECDSA signature with SHA-1 hash */
  ------------------
 1047|      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 (1047:14): [True: 0, False: 0]
  ------------------
 1048|      0|			priv->algorithm = ALGO_EC_SHA224;
  ------------------
  |  |   54|      0|#define ALGO_EC_SHA224 0x72 /* ECDSA signature with SHA-224 hash */
  ------------------
 1049|      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 (1049:14): [True: 0, False: 0]
  ------------------
 1050|      0|			priv->algorithm = ALGO_EC_SHA256;
  ------------------
  |  |   55|      0|#define ALGO_EC_SHA256 0x73 /* ECDSA signature with SHA-256 hash */
  ------------------
 1051|      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 (1051:14): [True: 0, False: 0]
  ------------------
 1052|      0|			priv->algorithm = ALGO_EC_SHA384;
  ------------------
  |  |   56|      0|#define ALGO_EC_SHA384 0x74 /* ECDSA signature with SHA-384 hash */
  ------------------
 1053|      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 (1053:14): [True: 0, False: 0]
  ------------------
 1054|      0|			priv->algorithm = ALGO_EC_SHA512;
  ------------------
  |  |   57|      0|#define ALGO_EC_SHA512 0x75 /* ECDSA signature with SHA-512 hash */
  ------------------
 1055|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_RAW) {
  ------------------
  |  |  174|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (1055:14): [True: 0, False: 0]
  ------------------
 1056|      0|			priv->algorithm = ALGO_EC_RAW;
  ------------------
  |  |   52|      0|#define ALGO_EC_RAW    0x70 /* ECDSA signature with hash input */
  ------------------
 1057|      0|		} else {
 1058|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1059|      0|		}
 1060|      0|		break;
 1061|      0|	default:
  ------------------
  |  Branch (1061:2): [True: 0, False: 1.61k]
  ------------------
 1062|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1063|      0|		break;
 1064|  1.61k|	}
 1065|  1.61k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.61k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1066|  1.61k|}
card-sc-hsm.c:sc_hsm_compute_signature:
 1089|  1.38k|{
 1090|  1.38k|	int r;
 1091|  1.38k|	sc_apdu_t apdu;
 1092|  1.38k|	u8 rbuf[514];
 1093|  1.38k|	sc_hsm_private_data_t *priv;
 1094|       |
 1095|  1.38k|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1095:6): [True: 0, False: 1.38k]
  |  Branch (1095:22): [True: 0, False: 1.38k]
  |  Branch (1095:38): [True: 0, False: 1.38k]
  ------------------
 1096|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1097|      0|	}
 1098|  1.38k|	priv = (sc_hsm_private_data_t *) card->drv_data;
 1099|       |
 1100|  1.38k|	if (priv->env == NULL) {
  ------------------
  |  Branch (1100:6): [True: 0, False: 1.38k]
  ------------------
 1101|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1102|      0|	}
 1103|       |
 1104|  1.38k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_EXT, 0x68, priv->env->key_ref[0], priv->algorithm);
  ------------------
  |  |  299|  1.38k|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|  1.38k|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|  1.38k|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1105|  1.38k|	apdu.cla = 0x80;
 1106|  1.38k|	apdu.resp = rbuf;
 1107|  1.38k|	apdu.resplen = sizeof(rbuf);
 1108|  1.38k|	apdu.le = 512;
 1109|       |
 1110|  1.38k|	apdu.data = data;
 1111|  1.38k|	apdu.lc = datalen;
 1112|  1.38k|	apdu.datalen = datalen;
 1113|  1.38k|	r = sc_transmit_apdu(card, &apdu);
 1114|       |
 1115|  1.38k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.38k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.38k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.38k|	int _ret = (r); \
  |  |  |  |  168|  1.38k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 180, False: 1.20k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.38k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1116|  1.20k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1116:6): [True: 141, False: 1.05k]
  |  Branch (1116:26): [True: 122, False: 19]
  ------------------
 1117|    122|		int len;
 1118|       |
 1119|    122|		if ((priv->algorithm & 0xF0) == ALGO_EC_RAW) {
  ------------------
  |  |   52|    122|#define ALGO_EC_RAW    0x70 /* ECDSA signature with hash input */
  ------------------
  |  Branch (1119:7): [True: 0, False: 122]
  ------------------
 1120|      0|			len = sc_hsm_decode_ecdsa_signature(card, apdu.resp, apdu.resplen, out, outlen, priv->env->key_size_bits);
 1121|      0|			if (len < 0) {
  ------------------
  |  Branch (1121:8): [True: 0, False: 0]
  ------------------
 1122|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1123|      0|			}
 1124|    122|		} else {
 1125|    122|			len = (int)(apdu.resplen > outlen ? outlen : apdu.resplen);
  ------------------
  |  Branch (1125:16): [True: 0, False: 122]
  ------------------
 1126|    122|			memcpy(out, apdu.resp, len);
 1127|    122|		}
 1128|    122|		LOG_FUNC_RETURN(card->ctx, len);
  ------------------
  |  |  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: 41, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  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|     81|	} else { \
  |  |  |  |  159|     81|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     81|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     81|	} \
  |  |  |  |  162|    122|	return _ret; \
  |  |  |  |  163|    122|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1129|    122|	}
 1130|  1.07k|	LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  1.07k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.07k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.07k|	int _ret = r; \
  |  |  |  |  155|  1.07k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.07k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|  1.07k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.07k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.07k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.07k|	return _ret; \
  |  |  |  |  163|  1.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|  1.07k|}
card-sc-hsm.c:sc_hsm_decipher:
 1136|    218|{
 1137|    218|	int r;
 1138|    218|	size_t len;
 1139|    218|	sc_apdu_t apdu;
 1140|    218|	u8 rbuf[514];
 1141|    218|	sc_hsm_private_data_t *priv;
 1142|       |
 1143|    218|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1143:6): [True: 0, False: 218]
  |  Branch (1143:22): [True: 0, False: 218]
  |  Branch (1143:40): [True: 0, False: 218]
  ------------------
 1144|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1145|      0|	}
 1146|    218|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    218|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    218|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    218|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    218|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 218]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1147|    218|	priv = (sc_hsm_private_data_t *) card->drv_data;
 1148|       |
 1149|    218|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_EXT, 0x62, priv->env->key_ref[0], priv->algorithm);
  ------------------
  |  |  299|    218|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|    218|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|    218|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1150|    218|	apdu.cla = 0x80;
 1151|    218|	apdu.resp = rbuf;
 1152|    218|	apdu.resplen = sizeof(rbuf);
 1153|    218|	apdu.le = 512;
 1154|       |
 1155|    218|	apdu.data = (u8 *)crgram;
 1156|    218|	apdu.lc = crgram_len;
 1157|    218|	apdu.datalen = crgram_len;
 1158|       |
 1159|    218|	r = sc_transmit_apdu(card, &apdu);
 1160|       |
 1161|    218|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|    218|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    218|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    218|	int _ret = (r); \
  |  |  |  |  178|    218|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 22, False: 196]
  |  |  |  |  ------------------
  |  |  |  |  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|    218|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 196]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1162|    196|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1162:6): [True: 54, False: 142]
  |  Branch (1162:26): [True: 50, False: 4]
  ------------------
 1163|     50|		if (priv->algorithm == ALGO_EC_DH) {
  ------------------
  |  |   58|     50|#define ALGO_EC_DH     0x80 /* ECDH key derivation */
  ------------------
  |  Branch (1163:7): [True: 0, False: 50]
  ------------------
 1164|       |			//
 1165|       |			// The SmartCard-HSM returns the point result of the DH operation
 1166|       |			// with a leading '04'
 1167|      0|			if (apdu.resplen <= 0) {
  ------------------
  |  Branch (1167:8): [True: 0, False: 0]
  ------------------
 1168|      0|				r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1169|      0|				goto err;
 1170|      0|			}
 1171|      0|			len = apdu.resplen - 1 > outlen ? outlen : apdu.resplen - 1;
  ------------------
  |  Branch (1171:10): [True: 0, False: 0]
  ------------------
 1172|      0|			memcpy(out, apdu.resp + 1, len);
 1173|      0|			r = (int)len;
 1174|     50|		} else {
 1175|     50|			len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1175:10): [True: 0, False: 50]
  ------------------
 1176|     50|			memcpy(out, apdu.resp, len);
 1177|     50|			r = (int)len;
 1178|     50|		}
 1179|     50|	}
 1180|    146|	else
 1181|    146|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1182|       |
 1183|    218|err:
 1184|    218|	sc_mem_clear(rbuf, sizeof(rbuf));
 1185|    218|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    218|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    218|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    218|	int _ret = r; \
  |  |  |  |  155|    218|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 173, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  156|    173|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    168|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 168, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|    173|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    173|	} 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|    218|	return _ret; \
  |  |  |  |  163|    218|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1186|    218|}
card-sc-hsm.c:sc_hsm_init:
 1817|    258|{
 1818|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1819|       |	char expanded_val[PATH_MAX];
 1820|       |	size_t expanded_len = PATH_MAX;
 1821|       |#endif
 1822|    258|	int flags,ext_flags;
 1823|    258|	sc_file_t *file = NULL;
 1824|    258|	sc_path_t path;
 1825|    258|	sc_hsm_private_data_t *priv = NULL;
 1826|       |
 1827|    258|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    258|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    258|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    258|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    258|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 258]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1828|       |
 1829|    258|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|    258|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  107|    258|#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|    258|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1830|    258|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  134|    258|#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|    258|#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|    258|#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|    258|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1831|    258|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  146|    258|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  147|    258|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  148|    258|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1832|       |
 1833|    258|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1834|    258|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1835|    258|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1836|    258|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1837|    258|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1838|       |
 1839|    258|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  174|    258|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1840|    258|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  173|    258|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1841|    258|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  175|    258|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  133|    258|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1842|    258|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  176|    258|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  134|    258|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1843|    258|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  177|    258|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  141|    258|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1844|    258|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  178|    258|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  138|    258|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1845|    258|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  179|    258|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  139|    258|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1846|    258|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  180|    258|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  140|    258|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1847|    258|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    258|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1848|       |
 1849|    258|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  198|    258|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1850|    258|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  200|    258|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1851|    258|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  201|    258|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1852|    258|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  202|    258|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1853|    258|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |   93|    258|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1854|    258|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1855|    258|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1856|    258|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1857|    258|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1858|    258|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1859|    258|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1860|    258|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1861|       |
 1862|    258|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  550|    258|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|    258|#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|    258|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1863|       |
 1864|       |	// APDU Size limits
 1865|       |	//   JCOP 2.4.1r3           1462
 1866|       |	//   JCOP 2.4.2r3           1454
 1867|       |	//   JCOP 3                 1232
 1868|       |	//   JCOP 4                 1454
 1869|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1870|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1871|       |	//
 1872|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1873|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1874|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1875|       |	// class 3 APDU
 1876|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1877|       |
 1878|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1879|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1880|    258|	card->max_send_size = 1232 - 9;
 1881|       |	// Assume that card supports sending with extended length APDU and without limit
 1882|    258|	card->max_recv_size = 0;
 1883|       |
 1884|    258|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1884:6): [True: 0, False: 258]
  ------------------
 1885|    258|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1885:7): [True: 257, False: 1]
  ------------------
 1886|    257|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1887|    257|	} else {
 1888|       |		// Adjust to the limits set by the reader
 1889|      1|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1889:7): [True: 1, False: 0]
  ------------------
 1890|      1|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1890:8): [True: 1, False: 0]
  ------------------
 1891|      1|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCONSISTENT_CONFIGURATION);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1892|       |
 1893|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1894|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1895|      0|		}
 1896|       |
 1897|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1897:7): [True: 0, False: 0]
  ------------------
 1898|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1898:8): [True: 0, False: 0]
  ------------------
 1899|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1900|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1901|      0|		}
 1902|      0|	}
 1903|       |
 1904|    257|	priv = card->drv_data;
 1905|    257|	if (!priv) {
  ------------------
  |  Branch (1905:6): [True: 257, False: 0]
  ------------------
 1906|    257|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1907|    257|		if (!priv)
  ------------------
  |  Branch (1907:7): [True: 0, False: 257]
  ------------------
 1908|    257|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1909|    257|		card->drv_data = priv;
 1910|    257|	}
 1911|       |
 1912|    257|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    257|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1913|    257|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    514|#define SC_SUCCESS				0
  ------------------
  |  Branch (1913:6): [True: 46, False: 211]
  ------------------
 1914|     46|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1914:7): [True: 46, False: 0]
  |  Branch (1914:15): [True: 4, False: 42]
  |  Branch (1914:34): [True: 3, False: 1]
  ------------------
 1915|      3|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1916|      3|		u8 type = 0xFF;
 1917|      3|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1918|      3|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1919|      3|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1920|      3|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1921|      3|		char *p = "SmartCard-HSM";
 1922|      3|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1922:7): [True: 2, False: 1]
  ------------------
 1923|      2|			type = file->prop_attr[file->prop_attr_len - 3];
 1924|      2|		}
 1925|      3|		switch (type) {
 1926|      1|			case 0x00:
  ------------------
  |  Branch (1926:4): [True: 1, False: 2]
  ------------------
 1927|      1|				p = p00;
 1928|      1|				break;
 1929|      1|			case 0x01:
  ------------------
  |  Branch (1929:4): [True: 1, False: 2]
  ------------------
 1930|      1|				p = p01;
 1931|      1|				break;
 1932|      1|			default:
  ------------------
  |  Branch (1932:4): [True: 1, False: 2]
  ------------------
 1933|      1|				break;
 1934|      3|		}
 1935|      3|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1936|      3|		card->name = card_name;
 1937|       |
 1938|      3|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1938:7): [True: 1, False: 2]
  ------------------
 1939|      1|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  563|      1|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1940|      1|		}
 1941|      3|	}
 1942|    257|	sc_file_free(file);
 1943|       |
 1944|    257|	priv->EF_C_DevAut = NULL;
 1945|    257|	priv->EF_C_DevAut_len = 0;
 1946|       |
 1947|    257|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1948|    257|	EAC_init();
 1949|       |#ifdef _WIN32
 1950|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1951|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1952|       |		EAC_set_cvc_default_dir(expanded_val);
 1953|       |#else
 1954|    257|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    257|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1955|    257|#endif
 1956|    257|#endif
 1957|       |
 1958|    257|	return 0;
 1959|    257|}
card-sc-hsm.c:sc_hsm_finish:
 1964|    257|{
 1965|    257|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1966|    257|#ifdef ENABLE_SM
 1967|    257|	sc_sm_stop(card);
 1968|    257|#endif
 1969|    257|	if (priv) {
  ------------------
  |  Branch (1969:6): [True: 257, False: 0]
  ------------------
 1970|    257|		free(priv->serialno);
 1971|    257|		sc_file_free(priv->dffcp);
 1972|    257|		free(priv->EF_C_DevAut);
 1973|    257|		sc_mem_clear(priv, sizeof(sc_hsm_private_data_t));
 1974|    257|		free(priv);
 1975|    257|		card->drv_data = NULL;
 1976|    257|	}
 1977|       |
 1978|    257|	return SC_SUCCESS;
  ------------------
  |  |   28|    257|#define SC_SUCCESS				0
  ------------------
 1979|    257|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1788|    152|{
 1789|    152|	switch (cmd) {
  ------------------
  |  Branch (1789:10): [True: 152, False: 0]
  ------------------
 1790|    152|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1790:2): [True: 152, False: 0]
  ------------------
 1791|    152|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1792|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1792:2): [True: 0, False: 152]
  ------------------
 1793|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1794|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1794:2): [True: 0, False: 152]
  ------------------
 1795|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1796|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1796:2): [True: 0, False: 152]
  ------------------
 1797|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1798|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1798:2): [True: 0, False: 152]
  ------------------
 1799|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1800|      0|	case SC_CARDCTL_SC_HSM_MANAGE_KEY_DOMAIN:
  ------------------
  |  Branch (1800:2): [True: 0, False: 152]
  ------------------
 1801|      0|		return sc_hsm_manage_key_domain(card, (sc_cardctl_sc_hsm_key_domain_t *)ptr);
 1802|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1802:2): [True: 0, False: 152]
  ------------------
 1803|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1804|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1804:2): [True: 0, False: 152]
  ------------------
 1805|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1806|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1806:2): [True: 0, False: 152]
  ------------------
 1807|      0|		return sc_hsm_register_public_key(card, ptr);
 1808|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1808:2): [True: 0, False: 152]
  ------------------
 1809|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1810|    152|	}
 1811|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1812|    152|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1204|    152|{
 1205|    152|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1206|       |
 1207|    152|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    152|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    152|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    152|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    152|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 152]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1208|       |
 1209|    152|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1209:6): [True: 152, False: 0]
  |  Branch (1209:25): [True: 0, False: 152]
  ------------------
 1210|       |		/* sc-hsm initializes the serial number via its PKCS#15 layer.
 1211|       |		 * Create and destroy a dummy card to get this initialized.  Only do
 1212|       |		 * this for `opensc-tool --serial` to avoid unnecessary card commands
 1213|       |		 * in all other cases. */
 1214|      0|		sc_pkcs15_card_t *p15card = NULL;
 1215|      0|		(void)sc_pkcs15_bind(card, NULL, &p15card);
 1216|      0|		sc_pkcs15_unbind(p15card);
 1217|      0|	}
 1218|       |
 1219|    152|	if (!priv->serialno) {
  ------------------
  |  Branch (1219:6): [True: 152, False: 0]
  ------------------
 1220|    152|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    152|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1221|    152|	}
 1222|       |
 1223|      0|	serial->len = strlen(priv->serialno);
 1224|      0|	if (serial->len > sizeof(serial->value))
  ------------------
  |  Branch (1224:6): [True: 0, False: 0]
  ------------------
 1225|      0|		serial->len = sizeof(serial->value);
 1226|       |
 1227|      0|	memcpy(serial->value, priv->serialno, serial->len);
 1228|       |
 1229|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1230|      0|}
card-sc-hsm.c:sc_hsm_pin_cmd:
  620|    469|{
  621|    469|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  622|    469|	sc_apdu_t apdu;
  623|    469|	u8 cmdbuff[16];
  624|    469|#ifdef ENABLE_SM
  625|    469|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|    469|#endif
  627|    469|	int r;
  628|    469|	int cmd = data->cmd;
  629|    469|	size_t pin2_len = data->pin2.len;
  630|       |
  631|    469|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|    469|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (631:6): [True: 0, False: 469]
  ------------------
  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|    469|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    469|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (639:6): [True: 0, False: 469]
  ------------------
  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|    469|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    469|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (644:13): [True: 0, False: 469]
  ------------------
  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|    469|#ifdef ENABLE_SM
  652|       |	/* For contactless cards always establish a secure channel before PIN
  653|       |	 * verification. Also, Session PIN generation requires SM. */
  654|    469|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (654:7): [True: 0, False: 469]
  ------------------
  655|    469|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (655:8): [True: 469, 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|    469|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  418|    469|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (657:7): [True: 27, False: 442]
  ------------------
  658|     27|		struct sc_pin_cmd_data check_sm_pin_data;
  659|     27|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  660|     27|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|     27|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  661|     27|		check_sm_pin_data.pin_type = data->pin_type;
  662|     27|		check_sm_pin_data.pin_reference = data->pin_reference;
  663|       |
  664|     27|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|     27|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  665|     27|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|     27|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (665:7): [True: 0, False: 27]
  ------------------
  666|       |			/* check if the existing SM channel is still valid */
  667|      0|			r = sc_pin_cmd(card, &check_sm_pin_data);
  668|      0|		}
  669|     27|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|     54|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|     27|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (669:7): [True: 0, False: 27]
  |  Branch (669:46): [True: 27, False: 0]
  ------------------
  670|       |			/* need to establish a new SM channel */
  671|     27|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|     27|					sc_hsm_perform_chip_authentication(card),
  673|     27|					"Could not perform chip authentication");
  674|     27|		}
  675|     27|	}
  676|    442|#endif
  677|       |
  678|    442|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|    442|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (678:6): [True: 0, False: 442]
  ------------------
  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|    442|	} else {
  684|    442|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  415|    442|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (684:7): [True: 0, False: 442]
  |  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|    442|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  416|    442|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (695:7): [True: 0, False: 442]
  |  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|    442|#ifdef ENABLE_SM
  714|    442|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|    442|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (714:7): [True: 442, False: 0]
  ------------------
  715|    442|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|    442|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (715:8): [True: 0, False: 442]
  ------------------
  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|    442|#endif
  723|       |
  724|    442|		data->pin1.offset = 5;
  725|    442|		data->pin2.offset = 5;
  726|       |
  727|    442|		r = (*iso_ops->pin_cmd)(card, data);
  728|    442|		data->apdu = NULL;
  729|    442|		sc_mem_clear(cmdbuff, sizeof(cmdbuff));
  730|    442|	}
  731|    442|	LOG_TEST_RET(card->ctx, r, "Verification failed");
  ------------------
  |  |  174|    442|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    442|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    442|	int _ret = (r); \
  |  |  |  |  168|    442|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 281, False: 161]
  |  |  |  |  ------------------
  |  |  |  |  169|    281|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    281|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    281|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    281|		return _ret; \
  |  |  |  |  172|    281|	} \
  |  |  |  |  173|    442|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 161]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  732|       |
  733|    161|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  419|    161|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (733:6): [True: 0, False: 161]
  ------------------
  734|       |		/* reset data->cmd to its original value */
  735|      0|		data->cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  419|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  736|      0|		if (data->pin_reference == 0x81) {
  ------------------
  |  Branch (736:7): [True: 0, False: 0]
  ------------------
  737|      0|			u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  738|      0|#ifdef ENABLE_SM
  739|      0|			if (card->sm_ctx.sm_mode != SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (739:8): [True: 0, False: 0]
  ------------------
  740|      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__
  |  |  ------------------
  ------------------
  741|      0|						"Session PIN generation only supported in SM");
  742|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  743|      0|			}
  744|       |#else
  745|       |			sc_log(card->ctx,
  746|       |					"Session PIN generation only supported in SM");
  747|       |			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  748|       |#endif
  749|      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
  ------------------
  750|      0|			apdu.cla = 0x80;
  751|      0|			apdu.resp = recvbuf;
  752|      0|			apdu.resplen = sizeof recvbuf;
  753|      0|			apdu.le = 0;
  754|      0|			if (sc_transmit_apdu(card, &apdu) != SC_SUCCESS
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (754:8): [True: 0, False: 0]
  ------------------
  755|      0|					|| sc_check_sw(card, apdu.sw1, apdu.sw2) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (755:9): [True: 0, False: 0]
  ------------------
  756|      0|				sc_mem_clear(recvbuf, sizeof(recvbuf));
  757|      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__
  |  |  ------------------
  ------------------
  758|      0|						"Generating session PIN failed");
  759|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  760|      0|			}
  761|      0|			if (data->pin2.data && pin2_len > 0) {
  ------------------
  |  Branch (761:8): [True: 0, False: 0]
  |  Branch (761:27): [True: 0, False: 0]
  ------------------
  762|      0|				if (pin2_len >= apdu.resplen) {
  ------------------
  |  Branch (762:9): [True: 0, False: 0]
  ------------------
  763|      0|					memcpy((unsigned char *) data->pin2.data, apdu.resp,
  764|      0|							apdu.resplen);
  765|      0|					data->pin2.len = apdu.resplen;
  766|      0|				} else {
  767|      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__
  |  |  ------------------
  ------------------
  768|      0|							"Buffer too small for session PIN");
  769|      0|				}
  770|      0|			}
  771|      0|			sc_mem_clear(recvbuf, sizeof(recvbuf));
  772|      0|		} else {
  773|      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__
  |  |  ------------------
  ------------------
  774|      0|					"Session PIN not supported for this PIN (0x%02X)",
  775|      0|					data->pin_reference);
  776|      0|		}
  777|      0|	}
  778|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  779|    161|}
card-sc-hsm.c:sc_hsm_perform_chip_authentication:
  492|     27|{
  493|     27|	int r, protocol;
  494|     27|	sc_path_t path;
  495|     27|	u8 all_certs[1024];
  496|     27|	EAC_CTX *ctx = NULL;
  497|     27|	size_t all_certs_len = sizeof all_certs, left, device_cert_len, issuer_cert_len;
  498|     27|	const unsigned char *cert = all_certs, *device_cert, *issuer_cert;
  499|     27|	BUF_MEM *comp_pub_key = NULL;
  500|     27|	sc_cvc_t cvc_device, cvc_issuer;
  501|       |	/* this is only needed to call sc_pkcs15emu_sc_hsm_decode_cvc */
  502|     27|	sc_pkcs15_card_t p15card;
  503|     27|	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|     27|	p15card.card = card;
  507|       |
  508|     27|	memset(&cvc_device, 0, sizeof(cvc_device));
  509|     27|	memset(&cvc_issuer, 0, sizeof(cvc_issuer));
  510|       |
  511|       |
  512|     27|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (512:6): [True: 5, False: 22]
  |  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|     22|	} else {
  516|       |		/* get issuer and device certificate from the card */
  517|     22|		r = sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
  ------------------
  |  |  117|     22|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  518|     22|		if (r < 0)
  ------------------
  |  Branch (518:7): [True: 0, False: 22]
  ------------------
  519|      0|			goto err;
  520|     22|		r = sc_select_file(card, &path, NULL);
  521|     22|		if (r < 0)
  ------------------
  |  Branch (521:7): [True: 10, False: 12]
  ------------------
  522|     10|			goto err;
  523|     12|		r = sc_read_binary(card, 0, all_certs, all_certs_len, 0);
  524|     12|		if (r < 0)
  ------------------
  |  Branch (524:7): [True: 3, False: 9]
  ------------------
  525|      3|			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|     27|err:
  599|     27|	if (r < 0)
  ------------------
  |  Branch (599:6): [True: 27, False: 0]
  ------------------
  600|     27|		EAC_CTX_clear_free(ctx);
  601|     27|	if (comp_pub_key)
  ------------------
  |  Branch (601:6): [True: 0, False: 27]
  ------------------
  602|      0|		BUF_MEM_free(comp_pub_key);
  603|     27|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_device);
  604|     27|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_issuer);
  605|       |
  606|     27|	return r;
  607|      0|}

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

sc_get_skeid_driver:
  179|  16.1k|{
  180|  16.1k|	if (iso_ops == NULL) iso_ops = sc_get_iso7816_driver()->ops;
  ------------------
  |  Branch (180:6): [True: 1, False: 16.1k]
  ------------------
  181|  16.1k|	skeid_ops = *iso_ops;
  182|  16.1k|	skeid_ops.match_card = skeid_match_card;
  183|  16.1k|	skeid_ops.init = skeid_init;
  184|  16.1k|	skeid_ops.set_security_env = skeid_set_security_env;
  185|  16.1k|	skeid_ops.logout = skeid_logout;
  186|  16.1k|	return &skeid_drv;
  187|  16.1k|}
card-skeid.c:skeid_match_card:
   73|  15.0k|{
   74|  15.0k|	if (_sc_match_atr(card, skeid_atrs, &card->type) < 0 || skeid_known_url(card) != SC_SUCCESS)
  ------------------
  |  |   28|     80|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 14.9k, False: 80]
  |  Branch (74:58): [True: 57, False: 23]
  ------------------
   75|  15.0k|		return 0;
   76|       |
   77|     23|	sc_log(card->ctx,  "Slovak eID card v3 (CardOS 5.4)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   78|       |
   79|     23|	return 1;
   80|  15.0k|}
card-skeid.c:skeid_known_url:
   53|     80|{
   54|     80|	const struct sc_aid skeid_aid_eid = {{0xE8, 0x07, 0x04, 0x00, 0x7F, 0x00, 0x07, 0x03, 0x02}, 9};
   55|     80|	const char *known_url = "\x80\x01\x00\x5F\x50\x28http://www.minv.sk/cif/cif-sk-eid-v3.xml";
   56|     80|	u8 buf[SKEID_KNOWN_URL_LEN];
   57|       |
   58|     80|	sc_path_t url_path;
   59|       |
   60|     80|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|     80|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   61|       |
   62|     80|	sc_path_set(&url_path, SC_PATH_TYPE_DF_NAME, skeid_aid_eid.value, skeid_aid_eid.len, 0, 0);
  ------------------
  |  |  118|     80|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|       |
   64|     80|	if (sc_select_file(card, &url_path, NULL) == SC_SUCCESS
  ------------------
  |  |   28|    160|#define SC_SUCCESS				0
  ------------------
  |  Branch (64:6): [True: 37, False: 43]
  ------------------
   65|     37|		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|     37|#define SKEID_KNOWN_URL_LEN 46
  ------------------
              		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|    117|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (65:6): [True: 27, False: 10]
  ------------------
   66|     27|		&& !memcmp(buf, known_url, SKEID_KNOWN_URL_LEN))
  ------------------
  |  |   30|     27|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (66:6): [True: 23, False: 4]
  ------------------
   67|     23|		r = SC_SUCCESS;
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
   68|       |
   69|     80|	return r;
   70|     80|}
card-skeid.c:skeid_init:
  108|     23|{
  109|     23|	const unsigned long flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  111|     23|#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|     23|#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|     23|#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|     23|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  110|     23|	const size_t data_field_length = 437;
  111|     23|	int r;
  112|       |
  113|     23|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  114|       |
  115|     23|	card->name = "Slovak eID (CardOS)";
  116|     23|	card->type = SC_CARD_TYPE_SKEID_V3;
  117|     23|	card->cla = 0x00;
  118|       |
  119|     23|	r = skeid_get_serialnr(card);
  120|     23|	LOG_TEST_RET(card->ctx, r, "Error reading serial number.");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|       |
  122|     16|	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  547|     16|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|     16|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  123|       |
  124|     16|	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|     16|	card->max_send_size = sc_get_max_send_size(card); /* see card-cardos.c */
  135|     16|	card->max_recv_size = data_field_length - 2;
  136|     16|	card->max_recv_size = sc_get_max_recv_size(card);
  137|       |
  138|     16|	r = _sc_card_add_rsa_alg(card, 3072, flags, 0);
  139|       |
  140|     16|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     16|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     16|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     16|	int _ret = r; \
  |  |  |  |  155|     16|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|     16|}
card-skeid.c:skeid_get_serialnr:
   83|     23|{
   84|     23|	int r;
   85|     23|	sc_apdu_t apdu;
   86|     23|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
   87|       |
   88|     23|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0x81);
  ------------------
  |  |  292|     23|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   89|     23|	apdu.resp = rbuf;
   90|     23|	apdu.resplen = sizeof(rbuf);
   91|     23|	apdu.le = 256;
   92|     23|	r = sc_transmit_apdu(card, &apdu);
   93|     23|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 21]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|     21|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (94:6): [True: 3, False: 18]
  |  Branch (94:26): [True: 1, False: 17]
  ------------------
   95|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
   96|     17|	if (apdu.resplen == 8) {
  ------------------
  |  Branch (96:6): [True: 16, False: 1]
  ------------------
   97|       |		/* cache serial number */
   98|     16|		memcpy(card->serialnr.value, rbuf, 8);
   99|     16|		card->serialnr.len = 8;
  100|     16|	} else {
  101|      1|		sc_log(card->ctx, "unexpected response to GET DATA serial number");
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  102|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
  103|      1|	}
  104|     16|	return SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
  105|     17|}
card-skeid.c:skeid_set_security_env:
  146|     40|{
  147|     40|	int key_id;
  148|     40|	int r;
  149|       |
  150|     40|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (150:6): [True: 0, False: 40]
  |  Branch (150:22): [True: 0, False: 40]
  ------------------
  151|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  152|       |
  153|     40|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || env->key_ref_len != 1) {
  ------------------
  |  |   58|     40|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (153:6): [True: 0, False: 40]
  |  Branch (153:52): [True: 0, False: 40]
  ------------------
  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|     40|	key_id = env->key_ref[0];
  162|     40|	r = sc_restore_security_env(card, key_id);
  163|       |
  164|     40|	return r;
  165|     40|}

sc_get_srbeid_driver:
  317|  16.1k|{
  318|       |	/* Save ISO ops for delegation, then override what we handle. */
  319|  16.1k|	iso_ops = sc_get_iso7816_driver()->ops;
  320|  16.1k|	srbeid_ops = *iso_ops;
  321|  16.1k|	srbeid_ops.match_card = srbeid_match_card;
  322|  16.1k|	srbeid_ops.init = srbeid_init;
  323|  16.1k|	srbeid_ops.select_file = srbeid_select_file;
  324|  16.1k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  325|  16.1k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  326|  16.1k|	srbeid_ops.decipher = srbeid_decipher;
  327|       |
  328|  16.1k|	return &srbeid_drv;
  329|  16.1k|}
card-srbeid.c:srbeid_match_card:
   72|  7.73k|{
   73|  7.73k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   74|  7.73k|	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   30|    539|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   28|    539|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 539, False: 7.20k]
  |  Branch (74:16): [True: 294, False: 245]
  ------------------
   75|    294|		card->name = srbeid_atrs[i].name;
   76|    294|		return 1;
   77|    294|	}
   78|  7.44k|	return 0;
   79|  7.73k|}
card-srbeid.c:srbeid_init:
   83|    294|{
   84|    294|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    294|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    294|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    294|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    294|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 294]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   85|       |
   86|    294|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  553|    294|#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|    294|	_sc_card_add_rsa_alg(card, 2048,
   91|    294|			SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_RAW |
  ------------------
  |  |  109|    294|#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|    294|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   92|    294|					SC_ALGORITHM_RSA_HASH_NONE,
  ------------------
  |  |  133|    294|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   93|    294|			0);
   94|       |
   95|    294|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    294|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    294|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    294|	int _ret = r; \
  |  |  |  |  155|    294|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 294, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    294|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 294]
  |  |  |  |  ------------------
  |  |  |  |  157|    294|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    294|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    294|	return _ret; \
  |  |  |  |  163|    294|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   96|    294|}
card-srbeid.c:srbeid_select_file:
  112|  2.34k|{
  113|  2.34k|	sc_apdu_t apdu;
  114|  2.34k|	u8 fci[16];
  115|  2.34k|	sc_file_t *file;
  116|  2.34k|	int r;
  117|       |
  118|  2.34k|	if (!in_path)
  ------------------
  |  Branch (118:6): [True: 0, False: 2.34k]
  ------------------
  119|  2.34k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  120|       |
  121|  2.34k|	if (in_path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  2.34k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (121:6): [True: 657, False: 1.68k]
  ------------------
  122|    657|		return iso_ops->select_file(card, in_path, file_out);
  123|       |
  124|       |	/* AID-only path (path.len==0, path.aid.len>0): PKCS#15 layer wants
  125|       |	 * to select the applet before a PIN or key operation. */
  126|  1.68k|	if (in_path->len == 0 && in_path->aid.len > 0)
  ------------------
  |  Branch (126:6): [True: 55, False: 1.62k]
  |  Branch (126:27): [True: 55, False: 0]
  ------------------
  127|     55|		return iso7816_select_aid(card, in_path->aid.value,
  128|     55|				in_path->aid.len, NULL, NULL);
  129|       |
  130|  1.62k|	if (in_path->len != 2)
  ------------------
  |  Branch (130:6): [True: 882, False: 746]
  ------------------
  131|  1.62k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    882|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    882|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    882|	int _ret = r; \
  |  |  |  |  155|    882|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 882, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    882|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    882|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 882, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    882|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    882|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    882|	return _ret; \
  |  |  |  |  163|    882|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  132|       |
  133|    746|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|    746|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  134|    746|	apdu.data = in_path->value;
  135|    746|	apdu.datalen = 2;
  136|    746|	apdu.lc = 2;
  137|    746|	apdu.resp = fci;
  138|    746|	apdu.resplen = sizeof(fci);
  139|    746|	apdu.le = 10;
  140|       |
  141|    746|	r = sc_transmit_apdu(card, &apdu);
  142|    746|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    746|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    746|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    746|	int _ret = (r); \
  |  |  |  |  168|    746|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 28, False: 718]
  |  |  |  |  ------------------
  |  |  |  |  169|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     28|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     28|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     28|		return _ret; \
  |  |  |  |  172|     28|	} \
  |  |  |  |  173|    746|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 718]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  143|    718|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  144|    718|	LOG_TEST_RET(card->ctx, r, "SELECT FILE failed");
  ------------------
  |  |  174|    718|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    718|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    718|	int _ret = (r); \
  |  |  |  |  168|    718|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 214, False: 504]
  |  |  |  |  ------------------
  |  |  |  |  169|    214|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    214|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    214|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    214|		return _ret; \
  |  |  |  |  172|    214|	} \
  |  |  |  |  173|    718|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 504]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  145|       |
  146|    504|	if (apdu.resplen < 4)
  ------------------
  |  Branch (146:6): [True: 56, False: 448]
  ------------------
  147|    504|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     56|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     56|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     56|	int _ret = r; \
  |  |  |  |  155|     56|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 56, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     56|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     56|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 56, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     56|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     56|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     56|	return _ret; \
  |  |  |  |  163|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|       |
  149|    448|	if (file_out) {
  ------------------
  |  Branch (149:6): [True: 359, False: 89]
  ------------------
  150|    359|		file = sc_file_new();
  151|    359|		if (!file)
  ------------------
  |  Branch (151:7): [True: 0, False: 359]
  ------------------
  152|    359|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  153|       |
  154|    359|		file->id = ((unsigned)in_path->value[0] << 8) | in_path->value[1];
  155|    359|		file->path = *in_path;
  156|    359|		file->size = ((size_t)fci[2] << 8) | (size_t)fci[3];
  157|    359|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    359|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  158|    359|		*file_out = file;
  159|    359|	}
  160|       |
  161|    448|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 448]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|    448|}
card-srbeid.c:srbeid_set_security_env:
  180|    337|{
  181|    337|	sc_apdu_t apdu;
  182|    337|	u8 mse_data[7];
  183|    337|	unsigned key_ref;
  184|    337|	u8 p2;
  185|    337|	int r;
  186|       |
  187|    337|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    337|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    337|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    337|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    337|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 337]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|    337|	(void)se_num;
  189|       |
  190|    337|	if (!env)
  ------------------
  |  Branch (190:6): [True: 0, False: 337]
  ------------------
  191|    337|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|       |
  193|       |	/* Extract key FID. */
  194|    337|	if ((env->flags & SC_SEC_ENV_FILE_REF_PRESENT) && env->file_ref.len >= 2) {
  ------------------
  |  |   57|    337|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (194:6): [True: 0, False: 337]
  |  Branch (194:52): [True: 0, False: 0]
  ------------------
  195|      0|		key_ref = ((unsigned)env->file_ref.value[0] << 8) | (unsigned)env->file_ref.value[1];
  196|    337|	} else if ((env->flags & SC_SEC_ENV_KEY_REF_PRESENT) && env->key_ref_len >= 1) {
  ------------------
  |  |   58|    337|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (196:13): [True: 337, False: 0]
  |  Branch (196:58): [True: 337, False: 0]
  ------------------
  197|    337|		key_ref = CE_KEYS_BASE_FID | (unsigned)env->key_ref[0];
  ------------------
  |  |   33|    337|#define CE_KEYS_BASE_FID 0x6000u
  ------------------
  198|    337|	} else {
  199|      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__
  |  |  ------------------
  ------------------
  200|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  201|      0|	}
  202|       |
  203|       |	/* Determine MSE SET template from operation type. */
  204|    337|	switch (env->operation) {
  205|    192|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|    192|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (205:2): [True: 192, False: 145]
  ------------------
  206|    192|		p2 = 0xB6;
  207|    192|		break;
  208|    145|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    145|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (208:2): [True: 145, False: 192]
  ------------------
  209|    145|		p2 = 0xB8;
  210|    145|		break;
  211|      0|	default:
  ------------------
  |  Branch (211:2): [True: 0, False: 337]
  ------------------
  212|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  213|    337|	}
  214|       |
  215|       |	/* MSE SET: tag 0x80 = algorithm, tag 0x84 = key ref (2 bytes BE).
  216|       |	 * The algorithm byte tells the card to pad (PKCS#1) or not (raw RSA). */
  217|    337|	mse_data[0] = 0x80;
  218|    337|	mse_data[1] = 0x01;
  219|    337|	mse_data[2] = (env->algorithm_flags & SC_ALGORITHM_RSA_RAW)
  ------------------
  |  |  102|    337|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (219:16): [True: 243, False: 94]
  ------------------
  220|    337|				      ? CE_MSE_ALG_RSA_RAW
  ------------------
  |  |   37|    243|#define CE_MSE_ALG_RSA_RAW   0x00u /* raw RSA; OpenSC pads */
  ------------------
  221|    337|				      : CE_MSE_ALG_RSA_PKCS1;
  ------------------
  |  |   36|    431|#define CE_MSE_ALG_RSA_PKCS1 0x02u /* card adds PKCS#1 padding */
  ------------------
  222|    337|	mse_data[3] = 0x84;
  223|    337|	mse_data[4] = 0x02;
  224|    337|	mse_data[5] = (u8)((key_ref >> 8) & 0xFF);
  225|    337|	mse_data[6] = (u8)(key_ref & 0xFF);
  226|       |
  227|    337|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, p2);
  ------------------
  |  |  293|    337|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  228|    337|	apdu.data = mse_data;
  229|    337|	apdu.datalen = sizeof(mse_data);
  230|    337|	apdu.lc = sizeof(mse_data);
  231|       |
  232|    337|	r = sc_transmit_apdu(card, &apdu);
  233|    337|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    337|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    337|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    337|	int _ret = (r); \
  |  |  |  |  168|    337|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 326]
  |  |  |  |  ------------------
  |  |  |  |  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|    337|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 326]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|    326|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  235|    326|	LOG_TEST_RET(card->ctx, r, "MSE SET failed");
  ------------------
  |  |  174|    326|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    326|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    326|	int _ret = (r); \
  |  |  |  |  168|    326|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 203, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  169|    203|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    203|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    203|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    203|		return _ret; \
  |  |  |  |  172|    203|	} \
  |  |  |  |  173|    326|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  236|       |
  237|    123|	sc_log(card->ctx, "srbeid: set_security_env: key_ref=0x%04x p2=0x%02x algo=0x%02x",
  ------------------
  |  |   71|    123|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  238|    123|			key_ref, p2, mse_data[2]);
  239|    123|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    123|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    123|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    123|	int _ret = r; \
  |  |  |  |  155|    123|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 123, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    123|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  157|    123|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    123|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    123|	return _ret; \
  |  |  |  |  163|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  240|    123|}
card-srbeid.c:srbeid_compute_signature:
  294|     47|{
  295|     47|	return srbeid_pso(card, 0x9E, data, datalen, out, outlen);
  296|     47|}
card-srbeid.c:srbeid_pso:
  249|    127|{
  250|    127|	sc_apdu_t apdu;
  251|    127|	u8 resp[256];
  252|    127|	u8 p2 = 0x00;
  253|    127|	int r;
  254|       |
  255|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  256|       |
  257|    127|	if (datalen == 0 || datalen > sizeof(resp))
  ------------------
  |  Branch (257:6): [True: 13, False: 114]
  |  Branch (257:22): [True: 10, False: 104]
  ------------------
  258|    127|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|       |
  260|    104|	if (datalen > SC_MAX_APDU_DATA_SIZE) {
  ------------------
  |  |   35|    104|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (260:6): [True: 32, False: 72]
  ------------------
  261|     32|		p2 = data[0];
  262|     32|		++data;
  263|     32|		--datalen;
  264|     32|	}
  265|       |
  266|    104|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, p1, p2);
  ------------------
  |  |  294|    104|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  267|    104|	apdu.data = data;
  268|    104|	apdu.datalen = apdu.lc = datalen;
  269|    104|	apdu.resp = resp;
  270|    104|	apdu.resplen = sizeof(resp);
  271|    104|	apdu.le = sizeof(resp);
  272|       |
  273|    104|	r = sc_transmit_apdu(card, &apdu);
  274|    104|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|    104|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    104|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    104|	int _ret = (r); \
  |  |  |  |  178|    104|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11, False: 93]
  |  |  |  |  ------------------
  |  |  |  |  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|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 93]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  275|     93|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  276|     93|	LOG_TEST_GOTO_ERR(card->ctx, r, "PSO failed");
  ------------------
  |  |  184|     93|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     93|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     93|	int _ret = (r); \
  |  |  |  |  178|     93|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 55, False: 38]
  |  |  |  |  ------------------
  |  |  |  |  179|     55|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     55|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     55|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     55|		goto err; \
  |  |  |  |  182|     55|	} \
  |  |  |  |  183|     93|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 38]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  277|       |
  278|     38|	if (apdu.resplen > outlen) {
  ------------------
  |  Branch (278:6): [True: 0, False: 38]
  ------------------
  279|      0|		r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  280|      0|		goto err;
  281|      0|	}
  282|     38|	memcpy(out, resp, apdu.resplen);
  283|     38|	r = (int)apdu.resplen;
  284|       |
  285|    104|err:
  286|    104|	sc_mem_clear(resp, sizeof(resp));
  287|    104|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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: 83, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  156|     83|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     66|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 66, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  157|     83|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     83|	} 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|    104|	return _ret; \
  |  |  |  |  163|    104|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  288|    104|}
card-srbeid.c:srbeid_decipher:
  307|     76|{
  308|     76|	int r = srbeid_pso(card, 0x80, crgram, crgram_len, out, outlen);
  309|       |
  310|     76|	if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|     76|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (310:6): [True: 4, False: 72]
  ------------------
  311|      4|		r = srbeid_pso(card, 0x9E, crgram, crgram_len, out, outlen);
  312|     76|	return r;
  313|     76|}

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

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

sc_check_sw:
   44|   561k|{
   45|   561k|	if (card == NULL)
  ------------------
  |  Branch (45:6): [True: 0, False: 561k]
  ------------------
   46|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   47|   561k|	if (card->ops->check_sw == NULL)
  ------------------
  |  Branch (47:6): [True: 0, False: 561k]
  ------------------
   48|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
   49|   561k|	return card->ops->check_sw(card, sw1, sw2);
   50|   561k|}
sc_format_apdu:
   54|   623k|{
   55|   623k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (55:6): [True: 0, False: 623k]
  |  Branch (55:22): [True: 0, False: 623k]
  ------------------
   56|      0|		return;
   57|      0|	}
   58|   623k|	memset(apdu, 0, sizeof(*apdu));
   59|   623k|	apdu->cla = (u8) card->cla;
   60|   623k|	apdu->cse = cse;
   61|   623k|	apdu->ins = (u8) ins;
   62|   623k|	apdu->p1 = (u8) p1;
   63|   623k|	apdu->p2 = (u8) p2;
   64|   623k|}
sc_format_apdu_cse_lc_le:
   67|  10.8k|{
   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|  10.8k|	if (!apdu)
  ------------------
  |  Branch (72:6): [True: 0, False: 10.8k]
  ------------------
   73|      0|		return;
   74|  10.8k|	if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
  ------------------
  |  |   35|  21.6k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (74:6): [True: 265, False: 10.5k]
  ------------------
   75|  10.5k|			|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|  10.5k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (75:7): [True: 662, False: 9.87k]
  ------------------
   76|       |		/* extended length  or data chaining and/or get response */
   77|    927|		if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
  ------------------
  |  |   38|    927|#define SC_MAX_EXT_APDU_DATA_SIZE		0xFFFF
  ------------------
  |  Branch (77:7): [True: 927, False: 0]
  ------------------
   78|    927|			apdu->lc = apdu->datalen;
   79|    927|		if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
  ------------------
  |  |   39|    927|#define SC_MAX_EXT_APDU_RESP_SIZE		(0xFFFF+1)
  ------------------
  |  Branch (79:7): [True: 927, False: 0]
  ------------------
   80|    927|			apdu->le = apdu->resplen;
   81|    927|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (81:7): [True: 927, False: 0]
  |  Branch (81:24): [True: 359, False: 568]
  ------------------
   82|    359|			apdu->cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    359|#define SC_APDU_CASE_2			0x22
  ------------------
   83|    927|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (83:7): [True: 0, False: 927]
  |  Branch (83:25): [True: 0, False: 0]
  ------------------
   84|      0|			apdu->cse = SC_APDU_CASE_3;
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
   85|    927|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (85:7): [True: 927, False: 0]
  |  Branch (85:24): [True: 568, False: 359]
  ------------------
   86|    568|			apdu->cse = SC_APDU_CASE_4;
  ------------------
  |  |  303|    568|#define SC_APDU_CASE_4			0x24
  ------------------
   87|  9.87k|	} else {
   88|       |		/* short length */
   89|  9.87k|		if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
  ------------------
  |  |   35|  9.87k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (89:7): [True: 9.87k, False: 0]
  ------------------
   90|  9.87k|			apdu->lc = apdu->datalen;
   91|  9.87k|		if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
  ------------------
  |  |   36|  9.87k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (91:7): [True: 9.87k, False: 0]
  ------------------
   92|  9.87k|			apdu->le = apdu->resplen;
   93|  9.87k|		if (!apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (93:7): [True: 3.12k, False: 6.74k]
  |  Branch (93:25): [True: 4, False: 3.12k]
  ------------------
   94|      4|			apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      4|#define SC_APDU_CASE_1			0x01
  ------------------
   95|  9.87k|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (95:7): [True: 6.74k, False: 3.12k]
  |  Branch (95:24): [True: 3.50k, False: 3.23k]
  ------------------
   96|  3.50k|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  3.50k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   97|  9.87k|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (97:7): [True: 3.12k, False: 6.74k]
  |  Branch (97:25): [True: 3.12k, False: 4]
  ------------------
   98|  3.12k|			apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  3.12k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
   99|  9.87k|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (99:7): [True: 6.74k, False: 3.12k]
  |  Branch (99:24): [True: 3.23k, False: 3.50k]
  ------------------
  100|  3.23k|			apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  3.23k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  101|  9.87k|	}
  102|  10.8k|}
sc_format_apdu_ex:
  108|  10.8k|{
  109|  10.8k|	if (!apdu) {
  ------------------
  |  Branch (109:6): [True: 0, False: 10.8k]
  ------------------
  110|      0|		return;
  111|      0|	}
  112|       |
  113|  10.8k|	memset(apdu, 0, sizeof(*apdu));
  114|  10.8k|	apdu->cla = cla;
  115|  10.8k|	apdu->ins = ins;
  116|  10.8k|	apdu->p1 = p1;
  117|  10.8k|	apdu->p2 = p2;
  118|  10.8k|	apdu->resp = resp;
  119|  10.8k|	apdu->resplen = resplen;
  120|  10.8k|	apdu->data = data;
  121|  10.8k|	apdu->datalen = datalen;
  122|  10.8k|	sc_format_apdu_cse_lc_le(apdu);
  123|  10.8k|}
sc_get_max_recv_size:
  187|   476k|{
  188|   476k|	size_t max_recv_size;
  189|   476k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (189:6): [True: 0, False: 476k]
  |  Branch (189:22): [True: 0, False: 476k]
  ------------------
  190|      0|		return 0;
  191|      0|	}
  192|   476k|	max_recv_size = card->max_recv_size;
  193|       |
  194|       |	/* initialize max_recv_size to a meaningful value */
  195|   476k|	if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  547|   476k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (195:6): [True: 51.4k, False: 425k]
  ------------------
  196|  51.4k|		if (!max_recv_size)
  ------------------
  |  Branch (196:7): [True: 2.41k, False: 49.0k]
  ------------------
  197|  2.41k|			max_recv_size = 65536;
  198|   425k|	} else {
  199|   425k|		if (!max_recv_size)
  ------------------
  |  Branch (199:7): [True: 166k, False: 258k]
  ------------------
  200|   166k|			max_recv_size = 256;
  201|   425k|	}
  202|       |
  203|       |	/*  Override card limitations with reader limitations. */
  204|   476k|	if (card->reader->max_recv_size != 0
  ------------------
  |  Branch (204:6): [True: 8.79k, False: 467k]
  ------------------
  205|  8.79k|			&& (card->reader->max_recv_size < max_recv_size))
  ------------------
  |  Branch (205:7): [True: 0, False: 8.79k]
  ------------------
  206|      0|		max_recv_size = card->reader->max_recv_size;
  207|       |
  208|   476k|	return max_recv_size;
  209|   476k|}
sc_get_max_send_size:
  212|  67.4k|{
  213|  67.4k|	size_t max_send_size;
  214|       |
  215|  67.4k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (215:6): [True: 0, False: 67.4k]
  |  Branch (215:22): [True: 0, False: 67.4k]
  ------------------
  216|      0|		return 0;
  217|      0|	}
  218|       |
  219|  67.4k|	max_send_size = card->max_send_size;
  220|       |
  221|       |	/* initialize max_send_size to a meaningful value */
  222|  67.4k|	if (card->caps & SC_CARD_CAP_APDU_EXT
  ------------------
  |  |  547|   134k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (222:6): [True: 30.1k, False: 37.3k]
  ------------------
  223|  30.1k|			&& card->reader->active_protocol != SC_PROTO_T0) {
  ------------------
  |  |  352|  30.1k|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (223:7): [True: 30.1k, False: 0]
  ------------------
  224|  30.1k|		if (!max_send_size)
  ------------------
  |  Branch (224:7): [True: 1.67k, False: 28.4k]
  ------------------
  225|  1.67k|			max_send_size = 65535;
  226|  37.3k|	} else {
  227|  37.3k|		if (!max_send_size)
  ------------------
  |  Branch (227:7): [True: 11.4k, False: 25.8k]
  ------------------
  228|  11.4k|			max_send_size = 255;
  229|  37.3k|	}
  230|       |
  231|       |	/*  Override card limitations with reader limitations. */
  232|  67.4k|	if (card->reader->max_send_size != 0
  ------------------
  |  Branch (232:6): [True: 3, False: 67.4k]
  ------------------
  233|      3|			&& (card->reader->max_send_size < max_send_size))
  ------------------
  |  Branch (233:7): [True: 0, False: 3]
  ------------------
  234|      0|		max_send_size = card->reader->max_send_size;
  235|       |
  236|  67.4k|	return max_send_size;
  237|  67.4k|}
sc_connect_card:
  240|  16.1k|{
  241|  16.1k|	sc_card_t *card;
  242|  16.1k|	sc_context_t *ctx;
  243|  16.1k|	struct sc_card_driver *driver;
  244|  16.1k|	int i, r = 0, idx, connected = 0;
  245|       |
  246|  16.1k|	if (card_out == NULL || reader == NULL)
  ------------------
  |  Branch (246:6): [True: 0, False: 16.1k]
  |  Branch (246:26): [True: 0, False: 16.1k]
  ------------------
  247|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  248|  16.1k|	ctx = reader->ctx;
  249|  16.1k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  16.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  16.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  16.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16.1k]
  |  |  ------------------
  ------------------
  250|  16.1k|	if (reader->ops->connect == NULL)
  ------------------
  |  Branch (250:6): [True: 0, False: 16.1k]
  ------------------
  251|  16.1k|		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.1k|	card = sc_card_new(ctx);
  254|  16.1k|	if (card == NULL)
  ------------------
  |  Branch (254:6): [True: 0, False: 16.1k]
  ------------------
  255|  16.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  256|  16.1k|	r = reader->ops->connect(reader);
  257|  16.1k|	if (r)
  ------------------
  |  Branch (257:6): [True: 0, False: 16.1k]
  ------------------
  258|      0|		goto err;
  259|       |
  260|  16.1k|	connected = 1;
  261|  16.1k|	card->reader = reader;
  262|  16.1k|	card->ctx = ctx;
  263|       |
  264|  16.1k|	if (reader->flags & SC_READER_ENABLE_ESCAPE)
  ------------------
  |  |  372|  16.1k|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (264:6): [True: 0, False: 16.1k]
  ------------------
  265|      0|		sc_detect_escape_cmds(reader);
  266|       |
  267|  16.1k|	memcpy(&card->atr, &reader->atr, sizeof(card->atr));
  268|  16.1k|	memcpy(&card->uid, &reader->uid, sizeof(card->uid));
  269|       |
  270|  16.1k|	_sc_parse_atr(reader);
  271|       |
  272|       |	/* See if the ATR matches any ATR specified in the config file */
  273|  16.1k|	if ((driver = ctx->forced_driver) == NULL) {
  ------------------
  |  Branch (273:6): [True: 16.1k, False: 0]
  ------------------
  274|  16.1k|		sc_log(ctx, "matching configured ATRs");
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
  275|   757k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (275:15): [True: 741k, False: 16.1k]
  ------------------
  276|   741k|			driver = ctx->card_drivers[i];
  277|       |
  278|   741k|			if (driver->atr_map == NULL ||
  ------------------
  |  Branch (278:8): [True: 741k, False: 0]
  ------------------
  279|   741k|			    !strcmp(driver->short_name, "default")) {
  ------------------
  |  Branch (279:8): [True: 0, False: 0]
  ------------------
  280|   741k|				driver = NULL;
  281|   741k|				continue;
  282|   741k|			}
  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.1k|	}
  298|       |
  299|  16.1k|	if (driver != NULL) {
  ------------------
  |  Branch (299:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	else {
  317|  16.1k|		sc_card_t uninitialized = *card;
  318|  16.1k|		sc_log(ctx, "matching built-in ATRs");
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
  319|   396k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (319:15): [True: 394k, False: 2.38k]
  ------------------
  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|   394k|			*card = uninitialized;
  332|       |
  333|   394k|			struct sc_card_driver *drv = ctx->card_drivers[i];
  334|   394k|			const struct sc_card_operations *ops = drv->ops;
  335|       |
  336|   394k|			sc_log(ctx, "trying driver '%s'", drv->short_name);
  ------------------
  |  |   71|   394k|#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|   394k|			if (ops == NULL || ops->match_card == NULL)   {
  ------------------
  |  Branch (337:8): [True: 0, False: 394k]
  |  Branch (337:23): [True: 0, False: 394k]
  ------------------
  338|      0|				continue;
  339|      0|			}
  340|   394k|			else if (!(ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER)
  ------------------
  |  |  860|   394k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  |  Branch (340:13): [True: 394k, False: 0]
  ------------------
  341|   394k|				   	&& !strcmp("default", drv->short_name))   {
  ------------------
  |  Branch (341:12): [True: 2.38k, False: 391k]
  ------------------
  342|  2.38k|				sc_log(ctx , "ignore 'default' card driver");
  ------------------
  |  |   71|  2.38k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  343|  2.38k|				continue;
  344|  2.38k|			}
  345|       |
  346|       |			/* Needed if match_card() needs to talk with the card (e.g. card-muscle) */
  347|   391k|			*card->ops = *ops;
  348|   391k|			if (ops->match_card(card) != 1)
  ------------------
  |  Branch (348:8): [True: 377k, False: 14.6k]
  ------------------
  349|   377k|				continue;
  350|  14.6k|			sc_log(ctx, "matched: %s", drv->name);
  ------------------
  |  |   71|  14.6k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  351|  14.6k|			memcpy(card->ops, ops, sizeof(struct sc_card_operations));
  352|  14.6k|			card->driver = drv;
  353|  14.6k|			r = ops->init(card);
  354|  14.6k|			if (r) {
  ------------------
  |  Branch (354:8): [True: 1.63k, False: 13.0k]
  ------------------
  355|  1.63k|				sc_log(ctx, "driver '%s' init() failed: %s", drv->name, sc_strerror(r));
  ------------------
  |  |   71|  1.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  356|  1.63k|				if (r == SC_ERROR_INVALID_CARD) {
  ------------------
  |  |   60|  1.63k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (356:9): [True: 933, False: 697]
  ------------------
  357|    933|					card->driver = NULL;
  358|    933|					continue;
  359|    933|				}
  360|    697|				goto err;
  361|  1.63k|			}
  362|  13.0k|			break;
  363|  14.6k|		}
  364|  16.1k|	}
  365|  15.4k|	if (card->driver == NULL) {
  ------------------
  |  Branch (365:6): [True: 2.38k, False: 13.0k]
  ------------------
  366|  2.38k|		sc_log(ctx, "unable to find driver for inserted card");
  ------------------
  |  |   71|  2.38k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  367|  2.38k|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  2.38k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  368|  2.38k|		goto err;
  369|  2.38k|	}
  370|  13.0k|	if (card->name == NULL)
  ------------------
  |  Branch (370:6): [True: 2.89k, False: 10.1k]
  ------------------
  371|  2.89k|		card->name = card->driver->name;
  372|       |
  373|       |	/* initialize max_send_size/max_recv_size to a meaningful value */
  374|  13.0k|	card->max_recv_size = sc_get_max_recv_size(card);
  375|  13.0k|	card->max_send_size = sc_get_max_send_size(card);
  376|       |
  377|  13.0k|	sc_log(ctx, "card info name:'%s', type:%i, flags:0x%lX, max_send/recv_size:%zu/%zu",
  ------------------
  |  |   71|  13.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  378|  13.0k|			card->name, card->type, card->flags, card->max_send_size, card->max_recv_size);
  379|       |
  380|  13.0k|#ifdef ENABLE_SM
  381|       |	/* Check, if secure messaging module present. */
  382|  13.0k|	r = sc_card_sm_check(card);
  383|  13.0k|	if (r)   {
  ------------------
  |  Branch (383:6): [True: 0, False: 13.0k]
  ------------------
  384|      0|		sc_log(ctx, "cannot load secure messaging module");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  385|      0|		goto err;
  386|      0|	}
  387|  13.0k|#endif
  388|  13.0k|	*card_out = card;
  389|       |
  390|  13.0k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13.0k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|  3.08k|err:
  392|  3.08k|	if (connected)
  ------------------
  |  Branch (392:6): [True: 3.08k, False: 0]
  ------------------
  393|  3.08k|		reader->ops->disconnect(reader);
  394|  3.08k|	if (card != NULL)
  ------------------
  |  Branch (394:6): [True: 3.08k, False: 0]
  ------------------
  395|  3.08k|		sc_card_free(card);
  396|  3.08k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  3.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.08k|	int _ret = r; \
  |  |  |  |  155|  3.08k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.08k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.08k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.08k|	return _ret; \
  |  |  |  |  163|  3.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  397|  3.08k|}
sc_disconnect_card:
  400|  16.1k|{
  401|  16.1k|	sc_context_t *ctx;
  402|       |
  403|  16.1k|	if (!card)
  ------------------
  |  Branch (403:6): [True: 3.08k, False: 13.0k]
  ------------------
  404|  3.08k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  3.08k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  405|       |
  406|  13.0k|	ctx = card->ctx;
  407|  13.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  408|       |
  409|  13.0k|	if (card->ops->finish) {
  ------------------
  |  Branch (409:6): [True: 12.2k, False: 785]
  ------------------
  410|  12.2k|		int r = card->ops->finish(card);
  411|  12.2k|		if (r)
  ------------------
  |  Branch (411:7): [True: 404, False: 11.8k]
  ------------------
  412|    404|			sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  413|  12.2k|	}
  414|       |
  415|  13.0k|	if (card->reader->ops->disconnect) {
  ------------------
  |  Branch (415:6): [True: 13.0k, False: 0]
  ------------------
  416|  13.0k|		int r = card->reader->ops->disconnect(card->reader);
  417|  13.0k|		if (r)
  ------------------
  |  Branch (417:7): [True: 0, False: 13.0k]
  ------------------
  418|      0|			sc_log(ctx, "disconnect() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  419|  13.0k|	}
  420|       |
  421|  13.0k|#ifdef ENABLE_SM
  422|       |	/* release SM related resources */
  423|  13.0k|	sc_card_sm_unload(card);
  424|  13.0k|#endif
  425|       |
  426|  13.0k|	sc_card_free(card);
  427|  13.0k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13.0k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  428|  13.0k|}
sc_lock:
  455|   780k|{
  456|   780k|	int r = 0, r2 = 0;
  457|   780k|	int was_reset = 0;
  458|   780k|	int reader_lock_obtained  = 0;
  459|       |
  460|   780k|	if (card == NULL)
  ------------------
  |  Branch (460:6): [True: 0, False: 780k]
  ------------------
  461|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  462|       |
  463|   780k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   780k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   780k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   780k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   780k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 780k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  464|       |
  465|   780k|	r = sc_mutex_lock(card->ctx, card->mutex);
  466|   780k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   780k|#define SC_SUCCESS				0
  ------------------
  |  Branch (466:6): [True: 0, False: 780k]
  ------------------
  467|      0|		return r;
  468|   780k|	if (card->lock_count == 0) {
  ------------------
  |  Branch (468:6): [True: 291k, False: 488k]
  ------------------
  469|   291k|		if (card->reader->ops->lock != NULL) {
  ------------------
  |  Branch (469:7): [True: 291k, False: 0]
  ------------------
  470|   291k|			r = card->reader->ops->lock(card->reader);
  471|   291k|			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   583k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   291k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (471:11): [True: 0, False: 291k]
  |  Branch (471:39): [True: 0, False: 291k]
  ------------------
  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|   291k|			if (r == 0)
  ------------------
  |  Branch (476:8): [True: 291k, False: 0]
  ------------------
  477|   291k|				reader_lock_obtained = 1;
  478|   291k|		}
  479|   291k|	}
  480|   780k|	if (r == 0)
  ------------------
  |  Branch (480:6): [True: 780k, False: 0]
  ------------------
  481|   780k|		card->lock_count++;
  482|       |
  483|   780k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  484|   780k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   780k|#define SC_SUCCESS				0
  ------------------
  |  Branch (484:6): [True: 0, False: 780k]
  ------------------
  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|   780k|	if (r == 0 && was_reset > 0) {
  ------------------
  |  Branch (489:6): [True: 780k, False: 0]
  |  Branch (489:16): [True: 0, False: 780k]
  ------------------
  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|   780k|	if (r == 0 && reader_lock_obtained == 1  && card->ops->card_reader_lock_obtained) {
  ------------------
  |  Branch (497:6): [True: 780k, False: 0]
  |  Branch (497:16): [True: 291k, False: 488k]
  |  Branch (497:46): [True: 82.8k, False: 208k]
  ------------------
  498|  82.8k|		if (SC_SUCCESS != card->ops->card_reader_lock_obtained(card, was_reset))
  ------------------
  |  |   28|  82.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (498:7): [True: 7.15k, False: 75.6k]
  ------------------
  499|  7.15k|			sc_log(card->ctx, "card_reader_lock_obtained failed");
  ------------------
  |  |   71|  7.15k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  500|  82.8k|	}
  501|       |
  502|   780k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   780k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   780k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   780k|	int _ret = r; \
  |  |  |  |  155|   780k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 780k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   780k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 780k]
  |  |  |  |  ------------------
  |  |  |  |  157|   780k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   780k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   780k|	return _ret; \
  |  |  |  |  163|   780k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  503|   780k|}
sc_unlock:
  506|   780k|{
  507|   780k|	int r, r2;
  508|       |
  509|   780k|	if (!card)
  ------------------
  |  Branch (509:6): [True: 0, False: 780k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|       |
  512|   780k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   780k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   780k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   780k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   780k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 780k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|       |
  514|   780k|	r = sc_mutex_lock(card->ctx, card->mutex);
  515|   780k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   780k|#define SC_SUCCESS				0
  ------------------
  |  Branch (515:6): [True: 0, False: 780k]
  ------------------
  516|   780k|		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|   780k|	if (card->lock_count < 1) {
  ------------------
  |  Branch (518:6): [True: 0, False: 780k]
  ------------------
  519|      0|		sc_mutex_unlock(card->ctx, card->mutex);
  520|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  521|      0|	}
  522|   780k|	if (--card->lock_count == 0) {
  ------------------
  |  Branch (522:6): [True: 291k, False: 488k]
  ------------------
  523|       |		/* release reader lock */
  524|   291k|		if (card->reader->ops->unlock != NULL)
  ------------------
  |  Branch (524:7): [True: 291k, False: 0]
  ------------------
  525|   291k|			r = card->reader->ops->unlock(card->reader);
  526|   291k|	}
  527|   780k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  528|   780k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   780k|#define SC_SUCCESS				0
  ------------------
  |  Branch (528:6): [True: 0, False: 780k]
  ------------------
  529|      0|		sc_log(card->ctx, "unable to release lock");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  530|      0|		r = (r == SC_SUCCESS) ? r2 : r;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (530:7): [True: 0, False: 0]
  ------------------
  531|      0|	}
  532|       |
  533|   780k|	return r;
  534|   780k|}
sc_read_binary:
  604|  11.7k|{
  605|  11.7k|	size_t max_le = sc_get_max_recv_size(card);
  606|  11.7k|	size_t todo = count;
  607|  11.7k|	int r;
  608|       |
  609|  11.7k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (609:6): [True: 0, False: 11.7k]
  |  Branch (609:22): [True: 0, False: 11.7k]
  |  Branch (609:43): [True: 0, False: 11.7k]
  ------------------
  610|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  611|      0|	}
  612|  11.7k|	sc_log(card->ctx, "called; %zu bytes at index %d", count, idx);
  ------------------
  |  |   71|  11.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  613|  11.7k|	if (count == 0)
  ------------------
  |  Branch (613:6): [True: 441, False: 11.2k]
  ------------------
  614|  11.7k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    441|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    441|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    441|	int _ret = r; \
  |  |  |  |  155|    441|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 441, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    441|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 441]
  |  |  |  |  ------------------
  |  |  |  |  157|    441|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    441|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    441|	return _ret; \
  |  |  |  |  163|    441|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|       |
  616|  11.2k|#ifdef ENABLE_SM
  617|  11.2k|	if (card->sm_ctx.ops.read_binary)   {
  ------------------
  |  Branch (617:6): [True: 284, False: 11.0k]
  ------------------
  618|    284|		r = card->sm_ctx.ops.read_binary(card, idx, buf, count);
  619|    284|		if (r)
  ------------------
  |  Branch (619:7): [True: 222, False: 62]
  ------------------
  620|    284|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    222|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    222|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    222|	int _ret = r; \
  |  |  |  |  155|    222|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 222, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    222|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    222|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 222, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    222|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    222|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    222|	return _ret; \
  |  |  |  |  163|    222|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|    284|	}
  622|  11.0k|#endif
  623|       |
  624|  11.0k|	if (card->ops->read_binary == NULL)
  ------------------
  |  Branch (624:6): [True: 0, False: 11.0k]
  ------------------
  625|  11.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  626|       |
  627|       |	/* lock the card now to avoid deselection of the file */
  628|  11.0k|	r = sc_lock(card);
  629|  11.0k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  11.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  11.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  11.0k|	int _ret = (r); \
  |  |  |  |  168|  11.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 11.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|  11.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|       |
  631|  38.7k|	while (todo > 0) {
  ------------------
  |  Branch (631:9): [True: 34.0k, False: 4.78k]
  ------------------
  632|  34.0k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   69|  34.0k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 12.0k, False: 21.9k]
  |  |  ------------------
  ------------------
  633|       |
  634|  34.0k|		r = card->ops->read_binary(card, idx, buf, chunk, flags);
  635|  34.0k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  32.1k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (635:7): [True: 1.86k, False: 32.1k]
  |  Branch (635:17): [True: 138, False: 32.0k]
  ------------------
  636|  1.99k|			break;
  637|  32.0k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (637:7): [True: 4.28k, False: 27.7k]
  |  Branch (637:16): [True: 2.40k, False: 1.87k]
  ------------------
  638|       |			/* the last command failed, but previous ones succeeded.
  639|       |			 * Let's just return what we've successfully read. */
  640|  2.40k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  2.40k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  641|  2.40k|			break;
  642|  2.40k|		}
  643|  29.5k|		if (r < 0) {
  ------------------
  |  Branch (643:7): [True: 1.87k, False: 27.7k]
  ------------------
  644|  1.87k|			sc_unlock(card);
  645|  1.87k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.87k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.87k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.87k|	int _ret = r; \
  |  |  |  |  155|  1.87k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.87k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.87k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.87k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.87k|	return _ret; \
  |  |  |  |  163|  1.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  646|  1.87k|		}
  647|  27.7k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (647:7): [True: 0, False: 27.7k]
  |  Branch (647:40): [True: 0, False: 27.7k]
  ------------------
  648|       |			/* `idx + r` or `todo - r` would overflow */
  649|      0|			sc_unlock(card);
  650|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OFFSET_TOO_LARGE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  651|      0|		}
  652|       |
  653|  27.7k|		todo -= (size_t) r;
  654|  27.7k|		buf  += (size_t) r;
  655|  27.7k|		idx  += (size_t) r;
  656|  27.7k|	}
  657|       |
  658|  9.18k|	sc_unlock(card);
  659|       |
  660|  9.18k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  9.18k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.18k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.18k|	int _ret = r; \
  |  |  |  |  155|  9.18k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 997, False: 8.18k]
  |  |  |  |  ------------------
  |  |  |  |  156|    997|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 997]
  |  |  |  |  ------------------
  |  |  |  |  157|    997|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.18k|	} else { \
  |  |  |  |  159|  8.18k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  8.18k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  8.18k|	} \
  |  |  |  |  162|  9.18k|	return _ret; \
  |  |  |  |  163|  9.18k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  661|  9.18k|}
sc_select_file:
  810|   109k|{
  811|   109k|	int r;
  812|   109k|	char pbuf[SC_MAX_PATH_STRING_SIZE];
  813|       |
  814|   109k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (814:6): [True: 0, False: 109k]
  |  Branch (814:22): [True: 0, False: 109k]
  ------------------
  815|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  816|      0|	}
  817|       |
  818|   109k|	r = sc_path_print(pbuf, sizeof(pbuf), in_path);
  819|   109k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   109k|#define SC_SUCCESS				0
  ------------------
  |  Branch (819:6): [True: 653, False: 108k]
  ------------------
  820|    653|		pbuf[0] = '\0';
  821|       |
  822|       |	/* FIXME We should be a bit less strict and let the upper layers do
  823|       |	 * the initialization (including reuse of existing file objects). We
  824|       |	 * implemented this here because we are lazy. */
  825|   109k|	if (file != NULL)
  ------------------
  |  Branch (825:6): [True: 54.1k, False: 55.1k]
  ------------------
  826|  54.1k|		*file = NULL;
  827|       |
  828|   109k|	sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
  ------------------
  |  |   71|   109k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  829|   109k|	if (in_path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|   109k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (829:6): [True: 0, False: 109k]
  ------------------
  830|   109k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  831|       |
  832|   109k|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|   109k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (832:6): [True: 78.9k, False: 30.2k]
  ------------------
  833|       |		/* Perform a sanity check */
  834|  78.9k|		size_t i;
  835|       |
  836|  78.9k|		if ((in_path->len & 1) != 0)
  ------------------
  |  Branch (836:7): [True: 125, False: 78.8k]
  ------------------
  837|  78.9k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    125|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    125|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    125|	int _ret = r; \
  |  |  |  |  155|    125|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 125, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    125|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    125|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 125, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    125|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    125|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    125|	return _ret; \
  |  |  |  |  163|    125|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  838|       |
  839|   237k|		for (i = 0; i < in_path->len/2; i++) {
  ------------------
  |  Branch (839:15): [True: 158k, False: 78.8k]
  ------------------
  840|   158k|			u8 p1 = in_path->value[2*i],
  841|   158k|			   p2 = in_path->value[2*i+1];
  842|       |
  843|   158k|			if ((p1 == 0x3F && p2 == 0x00) && i != 0)
  ------------------
  |  Branch (843:9): [True: 54.2k, False: 104k]
  |  Branch (843:23): [True: 54.1k, False: 144]
  |  Branch (843:38): [True: 41, False: 54.0k]
  ------------------
  844|   158k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  845|   158k|		}
  846|  78.8k|	}
  847|   109k|	if (card->ops->select_file == NULL)
  ------------------
  |  Branch (847:6): [True: 0, False: 109k]
  ------------------
  848|   109k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  849|   109k|	r = card->ops->select_file(card, in_path, file);
  850|   109k|	LOG_TEST_RET(card->ctx, r, "'SELECT' error");
  ------------------
  |  |  174|   109k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   109k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   109k|	int _ret = (r); \
  |  |  |  |  168|   109k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 80.4k, False: 28.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|  80.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|  80.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  80.4k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  80.4k|		return _ret; \
  |  |  |  |  172|  80.4k|	} \
  |  |  |  |  173|   109k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|       |
  852|  28.6k|	if (file) {
  ------------------
  |  Branch (852:6): [True: 15.8k, False: 12.7k]
  ------------------
  853|  15.8k|		if (*file)
  ------------------
  |  Branch (853:7): [True: 15.7k, False: 113]
  ------------------
  854|       |			/* Remember file path */
  855|  15.7k|			(*file)->path = *in_path;
  856|    113|		else
  857|       |			/* FIXME We should be a bit less strict and let the upper layers do
  858|       |			 * the error checking. We implemented this here because we are
  859|       |			 * lazy.  */
  860|    113|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    113|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  861|  15.8k|	}
  862|       |
  863|  28.6k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  28.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  28.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  28.6k|	int _ret = r; \
  |  |  |  |  155|  28.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  28.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|    113|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 113, False: 28.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|  28.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  28.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|  28.6k|	return _ret; \
  |  |  |  |  163|  28.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  864|  28.6k|}
sc_get_data:
  868|  6.05k|{
  869|  6.05k|	int	r;
  870|       |
  871|  6.05k|	sc_log(card->ctx, "called, tag=%04x", tag);
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  872|  6.05k|	if (card->ops->get_data == NULL)
  ------------------
  |  Branch (872:6): [True: 0, False: 6.05k]
  ------------------
  873|  6.05k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  874|  6.05k|	r = card->ops->get_data(card, tag, buf, len);
  875|       |
  876|  6.05k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.05k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.05k|	int _ret = r; \
  |  |  |  |  155|  6.05k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.19k, False: 1.85k]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  3.31k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.31k, False: 878]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.19k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.19k|	} else { \
  |  |  |  |  159|  1.85k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.85k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.85k|	} \
  |  |  |  |  162|  6.05k|	return _ret; \
  |  |  |  |  163|  6.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  877|  6.05k|}
sc_get_challenge:
  893|     19|{
  894|     19|	int r;
  895|       |
  896|     19|	if (len == 0)
  ------------------
  |  Branch (896:6): [True: 0, False: 19]
  ------------------
  897|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  898|       |
  899|     19|	if (card == NULL || rnd == NULL) {
  ------------------
  |  Branch (899:6): [True: 0, False: 19]
  |  Branch (899:22): [True: 0, False: 19]
  ------------------
  900|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  901|      0|	}
  902|       |
  903|     19|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     19|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     19|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     19|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     19|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  904|       |
  905|     19|	if (card->ops == NULL || card->ops->get_challenge == NULL)
  ------------------
  |  Branch (905:6): [True: 0, False: 19]
  |  Branch (905:27): [True: 0, False: 19]
  ------------------
  906|     19|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  907|       |
  908|     19|	r = sc_lock(card);
  909|     19|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     19|#define SC_SUCCESS				0
  ------------------
  |  Branch (909:6): [True: 0, False: 19]
  ------------------
  910|     19|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  911|       |
  912|     44|	while (len > 0) {
  ------------------
  |  Branch (912:9): [True: 37, False: 7]
  ------------------
  913|     37|		r = card->ops->get_challenge(card, rnd, len);
  914|     37|		if (r == 0)
  ------------------
  |  Branch (914:7): [True: 1, False: 36]
  ------------------
  915|      1|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  916|     37|		if (r < 0) {
  ------------------
  |  Branch (916:7): [True: 12, False: 25]
  ------------------
  917|     12|			sc_unlock(card);
  918|     12|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     12|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  919|     12|		}
  920|       |
  921|     25|		rnd += (size_t) r;
  922|     25|		len -= (size_t) r;
  923|     25|	}
  924|       |
  925|      7|	sc_unlock(card);
  926|       |
  927|      7|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  928|      7|}
sc_read_record:
  932|   181k|{
  933|   181k|	size_t max_le = sc_get_max_recv_size(card);
  934|   181k|	size_t todo = count;
  935|   181k|	int r;
  936|       |
  937|   181k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (937:6): [True: 0, False: 181k]
  |  Branch (937:22): [True: 0, False: 181k]
  |  Branch (937:43): [True: 0, False: 181k]
  ------------------
  938|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  939|      0|	}
  940|   181k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   181k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   181k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   181k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   181k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 181k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  941|   181k|	if (count == 0)
  ------------------
  |  Branch (941:6): [True: 161k, False: 20.3k]
  ------------------
  942|   181k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|   161k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   161k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   161k|	int _ret = r; \
  |  |  |  |  155|   161k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 161k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   161k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 161k]
  |  |  |  |  ------------------
  |  |  |  |  157|   161k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   161k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   161k|	return _ret; \
  |  |  |  |  163|   161k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  943|       |
  944|  20.3k|	if (card->ops->read_record == NULL)
  ------------------
  |  Branch (944:6): [True: 18, False: 20.3k]
  ------------------
  945|  20.3k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  946|       |
  947|       |	/* lock the card now to avoid deselection of the file */
  948|  20.3k|	r = sc_lock(card);
  949|  20.3k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  20.3k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  20.3k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  20.3k|	int _ret = (r); \
  |  |  |  |  168|  20.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 20.3k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  20.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 20.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  950|       |
  951|  38.0k|	while (todo > 0) {
  ------------------
  |  Branch (951:9): [True: 36.8k, False: 1.19k]
  ------------------
  952|  36.8k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   69|  36.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 28.0k, False: 8.76k]
  |  |  ------------------
  ------------------
  953|       |
  954|  36.8k|		r = card->ops->read_record(card, rec_nr, idx, buf, chunk, flags);
  955|  36.8k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  33.9k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (955:7): [True: 2.92k, False: 33.9k]
  |  Branch (955:17): [True: 354, False: 33.5k]
  ------------------
  956|  3.28k|			break;
  957|  33.5k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (957:7): [True: 15.8k, False: 17.7k]
  |  Branch (957:16): [True: 14.5k, False: 1.25k]
  ------------------
  958|       |			/* the last command failed, but previous ones succeeded.
  959|       |			 * Let's just return what we've successfully read. */
  960|  14.5k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   71|  14.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__
  |  |  ------------------
  ------------------
  961|  14.5k|			break;
  962|  14.5k|		}
  963|  18.9k|		if (r < 0) {
  ------------------
  |  Branch (963:7): [True: 1.25k, False: 17.7k]
  ------------------
  964|  1.25k|			sc_unlock(card);
  965|  1.25k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.25k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.25k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.25k|	int _ret = r; \
  |  |  |  |  155|  1.25k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.25k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.25k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.25k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.25k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.25k|	return _ret; \
  |  |  |  |  163|  1.25k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  966|  1.25k|		}
  967|  17.7k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (967:7): [True: 0, False: 17.7k]
  |  Branch (967:40): [True: 0, False: 17.7k]
  ------------------
  968|       |			/* `idx + r` or `todo - r` would overflow */
  969|      0|			sc_unlock(card);
  970|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OFFSET_TOO_LARGE);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  971|      0|		}
  972|       |
  973|  17.7k|		todo -= (size_t) r;
  974|  17.7k|		buf  += (size_t) r;
  975|  17.7k|		idx  += (size_t) r;
  976|  17.7k|	}
  977|       |
  978|  19.0k|	sc_unlock(card);
  979|       |
  980|  19.0k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  19.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  19.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  19.0k|	int _ret = r; \
  |  |  |  |  155|  19.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.92k, False: 16.1k]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.92k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.92k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.92k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.1k|	} else { \
  |  |  |  |  159|  16.1k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  16.1k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  16.1k|	} \
  |  |  |  |  162|  19.0k|	return _ret; \
  |  |  |  |  163|  19.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  981|  19.0k|}
sc_card_ctl:
 1091|   198k|{
 1092|   198k|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|   198k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1093|       |
 1094|   198k|	if (card == NULL) {
  ------------------
  |  Branch (1094:6): [True: 0, False: 198k]
  ------------------
 1095|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1096|      0|	}
 1097|   198k|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called with cmd=%lu\n", cmd);
  ------------------
  |  |   70|   198k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1098|       |
 1099|   198k|	if (card->ops->card_ctl != NULL)
  ------------------
  |  Branch (1099:6): [True: 196k, False: 1.83k]
  ------------------
 1100|   196k|		r = card->ops->card_ctl(card, cmd, args);
 1101|       |
 1102|       |	/* suppress "not supported" error messages */
 1103|   198k|	if (r == SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|   198k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (1103:6): [True: 30.0k, False: 168k]
  ------------------
 1104|  30.0k|		sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
  ------------------
  |  |   71|  30.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__
  |  |  ------------------
  ------------------
 1105|  30.0k|		return r;
 1106|  30.0k|	}
 1107|   168k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   168k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   168k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   168k|	int _ret = r; \
  |  |  |  |  155|   168k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 129k, False: 38.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|   129k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  48.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 48.0k, False: 81.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|   129k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   129k|	} else { \
  |  |  |  |  159|  38.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  38.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  38.4k|	} \
  |  |  |  |  162|   168k|	return _ret; \
  |  |  |  |  163|   168k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1108|   168k|}
_sc_card_add_algorithm:
 1111|  51.8k|{
 1112|  51.8k|	sc_algorithm_info_t *p;
 1113|       |
 1114|  51.8k|	if (info == NULL) {
  ------------------
  |  Branch (1114:6): [True: 0, False: 51.8k]
  ------------------
 1115|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1116|      0|	}
 1117|  51.8k|	p = (sc_algorithm_info_t *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info));
 1118|  51.8k|	if (!p) {
  ------------------
  |  Branch (1118:6): [True: 0, False: 51.8k]
  ------------------
 1119|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1120|      0|	}
 1121|  51.8k|	card->algorithms = p;
 1122|  51.8k|	p += card->algorithm_count;
 1123|  51.8k|	card->algorithm_count++;
 1124|  51.8k|	*p = *info;
 1125|  51.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  51.8k|#define SC_SUCCESS				0
  ------------------
 1126|  51.8k|}
_sc_card_add_symmetric_alg:
 1130|    103|{
 1131|    103|	sc_algorithm_info_t info;
 1132|       |
 1133|    103|	memset(&info, 0, sizeof(info));
 1134|    103|	info.algorithm = algorithm;
 1135|    103|	info.key_length = key_length;
 1136|    103|	info.flags = flags;
 1137|       |
 1138|    103|	return _sc_card_add_algorithm(card, &info);
 1139|    103|}
_sc_card_add_ec_alg:
 1176|  7.56k|{
 1177|  7.56k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1178|  7.56k|		curve_oid, SC_ALGORITHM_EC);
  ------------------
  |  |   70|  7.56k|#define SC_ALGORITHM_EC		2
  ------------------
 1179|  7.56k|}
_sc_card_add_eddsa_alg:
 1184|    264|{
 1185|       |	/* For simplicity, share the ec union with the curve information */
 1186|    264|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1187|    264|		curve_oid, SC_ALGORITHM_EDDSA);
  ------------------
  |  |   72|    264|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1188|    264|}
_sc_card_add_xeddsa_alg:
 1193|    264|{
 1194|       |	/* For simplicity, share the ec union with the curve information */
 1195|    264|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1196|    264|		curve_oid, SC_ALGORITHM_XEDDSA);
  ------------------
  |  |   73|    264|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1197|    264|}
sc_card_find_alg:
 1201|  87.4k|{
 1202|  87.4k|	int i;
 1203|       |
 1204|   346k|	for (i = 0; i < card->algorithm_count; i++) {
  ------------------
  |  Branch (1204:14): [True: 322k, False: 23.3k]
  ------------------
 1205|   322k|		sc_algorithm_info_t *info = &card->algorithms[i];
 1206|       |
 1207|   322k|		if (param && (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   70|  2.27k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1207:7): [True: 1.13k, False: 321k]
  |  Branch (1207:17): [True: 222, False: 917]
  ------------------
 1208|    917|			info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|  2.05k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1208:4): [True: 222, False: 695]
  ------------------
 1209|    695|			info->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   73|    695|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1209:4): [True: 222, False: 473]
  ------------------
 1210|    666|			if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id))
  ------------------
  |  Branch (1210:8): [True: 0, False: 666]
  ------------------
 1211|      0|				return info;
 1212|   322k|		} else if (info->algorithm != algorithm) {
  ------------------
  |  Branch (1212:14): [True: 91.3k, False: 230k]
  ------------------
 1213|  91.3k|			continue;
 1214|   230k|		} else if (info->key_length == key_length)
  ------------------
  |  Branch (1214:14): [True: 64.1k, False: 166k]
  ------------------
 1215|  64.1k|			return info;
 1216|   322k|	}
 1217|  23.3k|	return NULL;
 1218|  87.4k|}
sc_card_find_ec_alg:
 1222|  7.44k|{
 1223|  7.44k|	return sc_card_find_alg(card, SC_ALGORITHM_EC, key_length, curve_name);
  ------------------
  |  |   70|  7.44k|#define SC_ALGORITHM_EC		2
  ------------------
 1224|  7.44k|}
sc_card_find_eddsa_alg:
 1228|    160|{
 1229|    160|	return sc_card_find_alg(card, SC_ALGORITHM_EDDSA, key_length, curve_name);
  ------------------
  |  |   72|    160|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1230|    160|}
_sc_card_add_rsa_alg:
 1240|  43.5k|{
 1241|  43.5k|	sc_algorithm_info_t info;
 1242|       |
 1243|  43.5k|	memset(&info, 0, sizeof(info));
 1244|  43.5k|	info.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|  43.5k|#define SC_ALGORITHM_RSA		0
  ------------------
 1245|  43.5k|	info.key_length = key_length;
 1246|  43.5k|	info.flags = flags;
 1247|       |	/* disable particular PKCS1 v1.5 padding type if also RAW is supported on card */
 1248|  43.5k|	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  43.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  43.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  43.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  102|  43.5k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  43.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  109|  43.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  110|  43.5k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  102|  43.5k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (1248:6): [True: 8.19k, False: 35.3k]
  ------------------
 1249|  8.19k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  109|  8.19k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1249:7): [True: 0, False: 8.19k]
  ------------------
 1250|      0|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  109|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
 1251|  8.19k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  110|  8.19k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1251:7): [True: 8.19k, False: 0]
  ------------------
 1252|  8.19k|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  8.19k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 1253|  8.19k|	}
 1254|  43.5k|	info.u._rsa.exponent = exponent;
 1255|       |
 1256|  43.5k|	return _sc_card_add_algorithm(card, &info);
 1257|  43.5k|}
sc_card_find_rsa_alg:
 1260|  79.8k|{
 1261|  79.8k|	return sc_card_find_alg(card, SC_ALGORITHM_RSA, key_length, NULL);
  ------------------
  |  |   69|  79.8k|#define SC_ALGORITHM_RSA		0
  ------------------
 1262|  79.8k|}
_sc_match_atr:
 1333|   336k|{
 1334|   336k|	int res;
 1335|       |
 1336|   336k|	if (card == NULL)
  ------------------
  |  Branch (1336:6): [True: 0, False: 336k]
  ------------------
 1337|      0|		return -1;
 1338|   336k|	res = match_atr_table(card->ctx, table, &card->atr);
 1339|   336k|	if (res < 0)
  ------------------
  |  Branch (1339:6): [True: 325k, False: 11.1k]
  ------------------
 1340|   325k|		return res;
 1341|  11.1k|	if (type_out != NULL)
  ------------------
  |  Branch (1341:6): [True: 10.8k, False: 278]
  ------------------
 1342|  10.8k|		*type_out = table[res].type;
 1343|  11.1k|	return res;
 1344|   336k|}
_sc_match_atr_block:
 1347|  13.0k|{
 1348|  13.0k|	struct sc_card_driver *drv;
 1349|  13.0k|	struct sc_atr_table *table;
 1350|  13.0k|	int res;
 1351|       |
 1352|  13.0k|	if (ctx == NULL)
  ------------------
  |  Branch (1352:6): [True: 0, False: 13.0k]
  ------------------
 1353|      0|		return NULL;
 1354|  13.0k|	if (driver) {
  ------------------
  |  Branch (1354:6): [True: 13.0k, False: 0]
  ------------------
 1355|  13.0k|		drv = driver;
 1356|  13.0k|		table = drv->atr_map;
 1357|  13.0k|		res = match_atr_table(ctx, table, atr);
 1358|  13.0k|		if (res < 0)
  ------------------
  |  Branch (1358:7): [True: 13.0k, False: 0]
  ------------------
 1359|  13.0k|			return NULL;
 1360|      0|		return table[res].card_atr;
 1361|  13.0k|	} else {
 1362|      0|		unsigned int i;
 1363|       |
 1364|      0|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (1364:15): [True: 0, False: 0]
  ------------------
 1365|      0|			drv = ctx->card_drivers[i];
 1366|      0|			table = drv->atr_map;
 1367|      0|			res = match_atr_table(ctx, table, atr);
 1368|      0|			if (res < 0)
  ------------------
  |  Branch (1368:8): [True: 0, False: 0]
  ------------------
 1369|      0|				continue;
 1370|      0|			return table[res].card_atr;
 1371|      0|		}
 1372|      0|	}
 1373|      0|	return NULL;
 1374|  13.0k|}
sc_get_conf_block:
 1445|  46.3k|{
 1446|  46.3k|	int i;
 1447|  46.3k|	scconf_block *conf_block = NULL;
 1448|       |
 1449|  92.6k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (1449:14): [True: 46.3k, False: 46.3k]
  ------------------
 1450|  46.3k|		scconf_block **blocks;
 1451|       |
 1452|  46.3k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], name1, name2);
 1453|  46.3k|		if (blocks != NULL) {
  ------------------
  |  Branch (1453:7): [True: 46.3k, False: 0]
  ------------------
 1454|  46.3k|			conf_block = blocks[0];
 1455|  46.3k|			free(blocks);
 1456|  46.3k|		}
 1457|  46.3k|		if (conf_block != NULL && priority)
  ------------------
  |  Branch (1457:7): [True: 0, False: 46.3k]
  |  Branch (1457:29): [True: 0, False: 0]
  ------------------
 1458|      0|			break;
 1459|  46.3k|	}
 1460|  46.3k|	return conf_block;
 1461|  46.3k|}
sc_clear_ec_params:
 1465|  8.09k|{
 1466|  8.09k|	if (ecp) {
  ------------------
  |  Branch (1466:6): [True: 8.09k, False: 0]
  ------------------
 1467|  8.09k|		free(ecp->named_curve);
 1468|  8.09k|		free(ecp->der.value);
 1469|  8.09k|		memset(ecp, 0, sizeof(struct sc_ec_parameters));
 1470|  8.09k|	}
 1471|  8.09k|	return;
 1472|  8.09k|}
card.c:sc_card_new:
  126|  16.1k|{
  127|  16.1k|	sc_card_t *card;
  128|       |
  129|  16.1k|	if (ctx == NULL)
  ------------------
  |  Branch (129:6): [True: 0, False: 16.1k]
  ------------------
  130|      0|		return NULL;
  131|       |
  132|  16.1k|	card = calloc(1, sizeof(struct sc_card));
  133|  16.1k|	if (card == NULL)
  ------------------
  |  Branch (133:6): [True: 0, False: 16.1k]
  ------------------
  134|      0|		return NULL;
  135|  16.1k|	card->ops = malloc(sizeof(struct sc_card_operations));
  136|  16.1k|	if (card->ops == NULL) {
  ------------------
  |  Branch (136:6): [True: 0, False: 16.1k]
  ------------------
  137|      0|		free(card);
  138|      0|		return NULL;
  139|      0|	}
  140|       |
  141|  16.1k|	card->ctx = ctx;
  142|  16.1k|	if (sc_mutex_create(ctx, &card->mutex) != SC_SUCCESS) {
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (142:6): [True: 0, False: 16.1k]
  ------------------
  143|      0|		free(card->ops);
  144|      0|		free(card);
  145|      0|		return NULL;
  146|      0|	}
  147|       |
  148|  16.1k|	card->type = -1;
  149|  16.1k|	card->app_count = -1;
  150|       |
  151|  16.1k|	return card;
  152|  16.1k|}
card.c:sc_card_free:
  155|  16.1k|{
  156|  16.1k|	sc_free_apps(card);
  157|  16.1k|	sc_free_ef_atr(card);
  158|       |
  159|  16.1k|	free(card->ops);
  160|       |
  161|  16.1k|	if (card->algorithms != NULL)   {
  ------------------
  |  Branch (161:6): [True: 12.2k, False: 3.88k]
  ------------------
  162|  12.2k|		int i;
  163|  64.0k|		for (i=0; i<card->algorithm_count; i++)   {
  ------------------
  |  Branch (163:13): [True: 51.8k, False: 12.2k]
  ------------------
  164|  51.8k|			struct sc_algorithm_info *info = (card->algorithms + i);
  165|  51.8k|			if (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   70|   103k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (165:8): [True: 7.56k, False: 44.2k]
  ------------------
  166|  44.2k|					info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   72|  96.0k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (166:6): [True: 264, False: 43.9k]
  ------------------
  167|  43.9k|					info->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   73|  43.9k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (167:6): [True: 264, False: 43.7k]
  ------------------
  168|  8.09k|				sc_clear_ec_params(&info->u._ec.params);
  169|  8.09k|			}
  170|  51.8k|		}
  171|  12.2k|		free(card->algorithms);
  172|       |
  173|  12.2k|		card->algorithms = NULL;
  174|  12.2k|		card->algorithm_count = 0;
  175|  12.2k|	}
  176|       |
  177|  16.1k|	if (card->mutex != NULL) {
  ------------------
  |  Branch (177:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	sc_mem_clear(card, sizeof(*card));
  183|  16.1k|	free(card);
  184|  16.1k|}
card.c:_sc_card_add_ec_alg_int:
 1146|  8.09k|{
 1147|  8.09k|	sc_algorithm_info_t info;
 1148|  8.09k|	int r;
 1149|       |
 1150|  8.09k|	memset(&info, 0, sizeof(info));
 1151|  8.09k|	sc_init_oid(&info.u._ec.params.id);
 1152|       |
 1153|  8.09k|	info.algorithm = algorithm;
 1154|  8.09k|	info.key_length = key_length;
 1155|  8.09k|	info.flags = flags;
 1156|       |
 1157|  8.09k|	info.u._ec.ext_flags = ext_flags;
 1158|  8.09k|	if (curve_oid) {
  ------------------
  |  Branch (1158:6): [True: 3.41k, False: 4.67k]
  ------------------
 1159|  3.41k|		info.u._ec.params.id = *curve_oid;
 1160|  3.41k|		r = sc_encode_oid(card->ctx, &info.u._ec.params.id, &info.u._ec.params.der.value, &info.u._ec.params.der.len);
 1161|  3.41k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_encode_oid failed");
  ------------------
  |  |  184|  3.41k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  3.41k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  3.41k|	int _ret = (r); \
  |  |  |  |  178|  3.41k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 3.41k]
  |  |  |  |  ------------------
  |  |  |  |  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.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3.41k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1162|  3.41k|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &info.u._ec.params);
 1163|  3.41k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_pkcs15_fix_ec_parameters failed");
  ------------------
  |  |  184|  3.41k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  3.41k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  3.41k|	int _ret = (r); \
  |  |  |  |  178|  3.41k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 3.41k]
  |  |  |  |  ------------------
  |  |  |  |  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.41k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 3.41k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|  3.41k|	}
 1165|       |
 1166|  8.09k|	r = _sc_card_add_algorithm(card, &info);
 1167|  8.09k|	return r;
 1168|      0|err:
 1169|      0|	sc_clear_ec_params(&info.u._ec.params);
 1170|      0|	return r;
 1171|  8.09k|}
card.c:match_atr_table:
 1270|   349k|{
 1271|   349k|	u8 *card_atr_bin;
 1272|   349k|	size_t card_atr_bin_len;
 1273|   349k|	char card_atr_hex[3 * SC_MAX_ATR_SIZE];
 1274|   349k|	size_t card_atr_hex_len;
 1275|   349k|	unsigned int i = 0;
 1276|       |
 1277|   349k|	if (ctx == NULL || table == NULL || atr == NULL)
  ------------------
  |  Branch (1277:6): [True: 0, False: 349k]
  |  Branch (1277:21): [True: 13.0k, False: 336k]
  |  Branch (1277:38): [True: 0, False: 336k]
  ------------------
 1278|  13.0k|		return -1;
 1279|   336k|	card_atr_bin = atr->value;
 1280|   336k|	card_atr_bin_len = atr->len;
 1281|   336k|	sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
 1282|   336k|	card_atr_hex_len = strlen(card_atr_hex);
 1283|       |
 1284|   336k|	sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR     : %s", card_atr_hex);
  ------------------
  |  |   70|   336k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1285|       |
 1286|  2.87M|	for (i = 0; table[i].atr != NULL; i++) {
  ------------------
  |  Branch (1286:14): [True: 2.55M, False: 325k]
  ------------------
 1287|  2.55M|		const char *tatr = table[i].atr;
 1288|  2.55M|		const char *matr = table[i].atrmask;
 1289|  2.55M|		size_t tatr_len = strlen(tatr);
 1290|  2.55M|		u8 mbin[SC_MAX_ATR_SIZE], tbin[SC_MAX_ATR_SIZE];
 1291|  2.55M|		size_t mbin_len, tbin_len, s, matr_len;
 1292|  2.55M|		size_t fix_hex_len = card_atr_hex_len;
 1293|  2.55M|		size_t fix_bin_len = card_atr_bin_len;
 1294|       |
 1295|  2.55M|		sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR try : %s", tatr);
  ------------------
  |  |   70|  2.55M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1296|       |
 1297|  2.55M|		if (tatr_len != fix_hex_len) {
  ------------------
  |  Branch (1297:7): [True: 2.45M, False: 95.9k]
  ------------------
 1298|  2.45M|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ignored - wrong length");
  ------------------
  |  |   70|  2.45M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1299|  2.45M|			continue;
 1300|  2.45M|		}
 1301|  95.9k|		if (matr != NULL) {
  ------------------
  |  Branch (1301:7): [True: 22.6k, False: 73.3k]
  ------------------
 1302|  22.6k|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR mask: %s", matr);
  ------------------
  |  |   70|  22.6k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1303|       |
 1304|  22.6k|			matr_len = strlen(matr);
 1305|  22.6k|			if (tatr_len != matr_len)
  ------------------
  |  Branch (1305:8): [True: 0, False: 22.6k]
  ------------------
 1306|      0|				continue;
 1307|  22.6k|			tbin_len = sizeof(tbin);
 1308|  22.6k|			sc_hex_to_bin(tatr, tbin, &tbin_len);
 1309|  22.6k|			mbin_len = sizeof(mbin);
 1310|  22.6k|			sc_hex_to_bin(matr, mbin, &mbin_len);
 1311|  22.6k|			if (mbin_len != fix_bin_len) {
  ------------------
  |  Branch (1311:8): [True: 0, False: 22.6k]
  ------------------
 1312|      0|				sc_debug(ctx, SC_LOG_DEBUG_MATCH, "length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1313|      0|				continue;
 1314|      0|			}
 1315|   432k|			for (s = 0; s < tbin_len; s++) {
  ------------------
  |  Branch (1315:16): [True: 410k, False: 22.6k]
  ------------------
 1316|       |				/* reduce tatr with mask */
 1317|   410k|				tbin[s] = (tbin[s] & mbin[s]);
 1318|       |				/* create copy of card_atr_bin masked) */
 1319|   410k|				mbin[s] = (card_atr_bin[s] & mbin[s]);
 1320|   410k|			}
 1321|  22.6k|			if (memcmp(tbin, mbin, tbin_len) != 0)
  ------------------
  |  Branch (1321:8): [True: 18.4k, False: 4.14k]
  ------------------
 1322|  18.4k|				continue;
 1323|  73.3k|		} else {
 1324|  73.3k|			if (strncasecmp(tatr, card_atr_hex, tatr_len) != 0)
  ------------------
  |  Branch (1324:8): [True: 66.3k, False: 6.96k]
  ------------------
 1325|  66.3k|				continue;
 1326|  73.3k|		}
 1327|  11.1k|		return i;
 1328|  95.9k|	}
 1329|   325k|	return -1;
 1330|   336k|}
card.c:sc_card_sm_unload:
 1511|  13.0k|{
 1512|  13.0k|	if (card->sm_ctx.module.ops.module_cleanup)
  ------------------
  |  Branch (1512:6): [True: 0, False: 13.0k]
  ------------------
 1513|      0|		card->sm_ctx.module.ops.module_cleanup(card->ctx);
 1514|       |
 1515|  13.0k|	if (card->sm_ctx.module.handle)
  ------------------
  |  Branch (1515:6): [True: 0, False: 13.0k]
  ------------------
 1516|      0|		sc_dlclose(card->sm_ctx.module.handle);
 1517|       |	card->sm_ctx.module.handle = NULL;
 1518|  13.0k|	return 0;
 1519|  13.0k|}
card.c:sc_card_sm_check:
 1614|  13.0k|{
 1615|  13.0k|	const char *sm = NULL, *module_name = NULL, *module_path = NULL, *module_data = NULL, *sm_mode = NULL;
 1616|  13.0k|	struct sc_context *ctx = card->ctx;
 1617|  13.0k|	scconf_block *atrblock = NULL, *sm_conf_block = NULL;
 1618|  13.0k|	int rv, ii;
 1619|       |#ifdef _WIN32
 1620|       |	char temp_path[PATH_MAX];
 1621|       |	size_t temp_len = PATH_MAX - 1;
 1622|       |	char expanded_val[PATH_MAX];
 1623|       |	DWORD expanded_len = PATH_MAX;
 1624|       |#endif
 1625|       |
 1626|  13.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1627|       |
 1628|       |	/* get the name of card specific SM configuration section */
 1629|  13.0k|	atrblock = _sc_match_atr_block(ctx, card->driver, &card->atr);
 1630|  13.0k|	if (atrblock == NULL)
  ------------------
  |  Branch (1630:6): [True: 13.0k, False: 0]
  ------------------
 1631|  13.0k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 13.0k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1632|      0|	sm = scconf_get_str(atrblock, "secure_messaging", NULL);
 1633|      0|	if (!sm)
  ------------------
  |  Branch (1633:6): [True: 0, False: 0]
  ------------------
 1634|      0|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|       |
 1636|       |	/* get SM configuration section by the name */
 1637|      0|	sc_log(ctx, "secure_messaging configuration block '%s'", sm);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1638|      0|        for (ii = 0; ctx->conf_blocks[ii]; ii++) {
  ------------------
  |  Branch (1638:22): [True: 0, False: 0]
  ------------------
 1639|      0|		scconf_block **blocks;
 1640|       |
 1641|      0|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[ii], "secure_messaging", sm);
 1642|      0|		if (blocks) {
  ------------------
  |  Branch (1642:7): [True: 0, False: 0]
  ------------------
 1643|      0|			sm_conf_block = blocks[0];
 1644|      0|			free(blocks);
 1645|      0|		}
 1646|      0|		if (sm_conf_block != NULL)
  ------------------
  |  Branch (1646:7): [True: 0, False: 0]
  ------------------
 1647|      0|			break;
 1648|      0|	}
 1649|       |
 1650|      0|	if (!sm_conf_block)
  ------------------
  |  Branch (1650:6): [True: 0, False: 0]
  ------------------
 1651|      0|		LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "SM configuration block not preset");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1652|       |
 1653|       |	/* check if an external SM module has to be used */
 1654|       |#ifdef _WIN32
 1655|       |	rv = sc_ctx_win32_get_config_value(NULL, "SmDir", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
 1656|       |			temp_path, &temp_len);
 1657|       |	if (rv == SC_SUCCESS) {
 1658|       |		temp_path[temp_len] = '\0';
 1659|       |		module_path = temp_path;
 1660|       |	}
 1661|       |	expanded_len = ExpandEnvironmentStringsA(module_path, expanded_val, expanded_len);
 1662|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1663|       |		module_path = expanded_val;
 1664|       |#else
 1665|      0|	module_path = scconf_get_str(sm_conf_block, "module_path", DEFAULT_SM_MODULE_PATH);
 1666|      0|#endif
 1667|      0|	module_name = scconf_get_str(sm_conf_block, "module_name", DEFAULT_SM_MODULE);
 1668|      0|	sc_log(ctx, "SM module '%s' in  '%s'", module_name, module_path);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1669|      0|	if (!module_name)
  ------------------
  |  Branch (1669:6): [True: 0, False: 0]
  ------------------
 1670|      0|		LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_CONFIGURATION, "Invalid SM configuration: module not defined");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1671|       |
 1672|      0|	rv = sc_card_sm_load(card, module_path, module_name);
 1673|      0|	LOG_TEST_RET(ctx, rv, "Failed to load SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1674|       |
 1675|      0|	strlcpy(card->sm_ctx.module.filename, module_name, sizeof(card->sm_ctx.module.filename));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1676|      0|	strlcpy(card->sm_ctx.config_section, sm, sizeof(card->sm_ctx.config_section));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1677|       |
 1678|       |	/* allocate resources for the external SM module */
 1679|      0|	if (card->sm_ctx.module.ops.module_init)   {
  ------------------
  |  Branch (1679:6): [True: 0, False: 0]
  ------------------
 1680|      0|		module_data = scconf_get_str(sm_conf_block, "module_data", NULL);
 1681|       |
 1682|      0|		rv = card->sm_ctx.module.ops.module_init(ctx, module_data);
 1683|      0|		LOG_TEST_RET(ctx, rv, "Cannot initialize SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1684|      0|	}
 1685|       |
 1686|       |	/* initialize SM session in the case of 'APDU TRANSMIT' SM mode */
 1687|      0|	sm_mode = scconf_get_str(sm_conf_block, "mode", NULL);
 1688|      0|	if (sm_mode && !strcasecmp("Transmit", sm_mode))   {
  ------------------
  |  Branch (1688:6): [True: 0, False: 0]
  |  Branch (1688:17): [True: 0, False: 0]
  ------------------
 1689|      0|		if (!card->sm_ctx.ops.open || !card->sm_ctx.ops.get_sm_apdu || !card->sm_ctx.ops.free_sm_apdu)
  ------------------
  |  Branch (1689:7): [True: 0, False: 0]
  |  Branch (1689:33): [True: 0, False: 0]
  |  Branch (1689:66): [True: 0, False: 0]
  ------------------
 1690|      0|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "'Transmit' SM asked but not supported by card driver");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1691|       |
 1692|      0|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1693|      0|		rv = card->sm_ctx.ops.open(card);
 1694|      0|		LOG_TEST_RET(ctx, rv, "Cannot initialize SM");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1695|      0|	}
 1696|       |
 1697|      0|	sc_log(ctx, "SM mode:%X", card->sm_ctx.sm_mode);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1698|      0|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, rv);
  ------------------
  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|      0|	int _ret = r; \
  |  |  155|      0|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  ------------------
  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  ------------------
  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|      0|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|      0|	return _ret; \
  |  |  163|      0|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1699|      0|}

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

_sc_delete_reader:
   85|  16.1k|{
   86|  16.1k|	if (reader == NULL) {
  ------------------
  |  Branch (86:6): [True: 0, False: 16.1k]
  ------------------
   87|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   88|      0|	}
   89|  16.1k|	if (reader->ops->release)
  ------------------
  |  Branch (89:6): [True: 16.1k, False: 0]
  ------------------
   90|  16.1k|			reader->ops->release(reader);
   91|  16.1k|	free(reader->name);
   92|  16.1k|	free(reader->vendor);
   93|  16.1k|	list_delete(&ctx->readers, reader);
   94|  16.1k|	free(reader);
   95|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
   96|  16.1k|}
sc_ctx_detect_readers:
  785|  16.1k|{
  786|  16.1k|	int r = 0;
  787|  16.1k|	const struct sc_reader_driver *drv = ctx->reader_driver;
  788|       |
  789|  16.1k|	sc_mutex_lock(ctx, ctx->mutex);
  790|       |
  791|  16.1k|	if (drv->ops->detect_readers != NULL)
  ------------------
  |  Branch (791:6): [True: 0, False: 16.1k]
  ------------------
  792|      0|		r = drv->ops->detect_readers(ctx);
  793|       |
  794|  16.1k|	sc_mutex_unlock(ctx, ctx->mutex);
  795|       |
  796|  16.1k|	return r;
  797|  16.1k|}
sc_ctx_get_reader:
  800|  16.1k|{
  801|  16.1k|	return list_get_at(&ctx->readers, i);
  802|  16.1k|}
sc_establish_context:
  820|  16.1k|{
  821|  16.1k|	sc_context_param_t ctx_param;
  822|       |
  823|  16.1k|	memset(&ctx_param, 0, sizeof(sc_context_param_t));
  824|  16.1k|	ctx_param.ver      = 0;
  825|  16.1k|	ctx_param.app_name = app_name;
  826|  16.1k|	return sc_context_create(ctx_out, &ctx_param);
  827|  16.1k|}
sc_context_create:
  949|  16.1k|{
  950|  16.1k|	sc_context_t		*ctx;
  951|  16.1k|	struct _sc_ctx_options	opts;
  952|  16.1k|	int			r;
  953|  16.1k|	char			*driver;
  954|       |
  955|  16.1k|	if (ctx_out == NULL || parm == NULL)
  ------------------
  |  Branch (955:6): [True: 0, False: 16.1k]
  |  Branch (955:25): [True: 0, False: 16.1k]
  ------------------
  956|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  957|       |
  958|  16.1k|	ctx = calloc(1, sizeof(sc_context_t));
  959|  16.1k|	if (ctx == NULL)
  ------------------
  |  Branch (959:6): [True: 0, False: 16.1k]
  ------------------
  960|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  961|  16.1k|	memset(&opts, 0, sizeof(opts));
  962|       |
  963|       |	/* set the application name if set in the parameter options */
  964|  16.1k|	if (parm->app_name != NULL)
  ------------------
  |  Branch (964:6): [True: 16.1k, False: 0]
  ------------------
  965|  16.1k|		ctx->app_name = strdup(parm->app_name);
  966|      0|	else
  967|      0|		ctx->app_name = strdup("default");
  968|  16.1k|	if (ctx->app_name == NULL) {
  ------------------
  |  Branch (968:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	ctx->exe_path = get_exe_path();
  974|  16.1k|	if (ctx->exe_path == NULL) {
  ------------------
  |  Branch (974:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	ctx->flags = parm->flags;
  980|  16.1k|	set_defaults(ctx, &opts);
  981|       |
  982|  16.1k|	if (0 != list_init(&ctx->readers)) {
  ------------------
  |  Branch (982:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	list_attributes_seeker(&ctx->readers, reader_list_seeker);
  988|       |	/* set thread context and create mutex object (if specified) */
  989|  16.1k|	if (parm->thread_ctx != NULL)
  ------------------
  |  Branch (989:6): [True: 0, False: 16.1k]
  ------------------
  990|      0|		ctx->thread_ctx = parm->thread_ctx;
  991|  16.1k|	r = sc_mutex_create(ctx, &ctx->mutex);
  992|  16.1k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (992:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	process_config_file(ctx, &opts);
 1005|       |
 1006|       |	/* overwrite with caller's parameters if explicitly given */
 1007|  16.1k|	if (parm->debug) {
  ------------------
  |  Branch (1007:6): [True: 0, False: 16.1k]
  ------------------
 1008|      0|		ctx->debug = parm->debug;
 1009|      0|	}
 1010|  16.1k|	if (parm->debug_file) {
  ------------------
  |  Branch (1010:6): [True: 0, False: 16.1k]
  ------------------
 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.1k|	sc_log(ctx, "==================================="); /* first thing in the log */
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 1017|  16.1k|	sc_log(ctx, "OpenSC version: %s", sc_get_version());
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 1018|  16.1k|	sc_log(ctx, "Configured for %s (%s)", ctx->app_name, ctx->exe_path);
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
 1019|       |
 1020|  16.1k|#ifdef USE_OPENSSL3_LIBCTX
 1021|  16.1k|	r = sc_openssl3_init(ctx);
 1022|  16.1k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1022:6): [True: 0, False: 16.1k]
  ------------------
 1023|      0|		del_drvs(&opts);
 1024|      0|		sc_release_context(ctx);
 1025|      0|		return r;
 1026|      0|	}
 1027|  16.1k|#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|  16.1k|	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.1k|	r = ctx->reader_driver->ops->init(ctx);
 1042|  16.1k|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1042:6): [True: 0, False: 16.1k]
  ------------------
 1043|      0|		del_drvs(&opts);
 1044|      0|		sc_release_context(ctx);
 1045|      0|		return r;
 1046|      0|	}
 1047|       |
 1048|  16.1k|	driver = getenv("OPENSC_DRIVER");
 1049|  16.1k|	if (driver) {
  ------------------
  |  Branch (1049:6): [True: 0, False: 16.1k]
  ------------------
 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.1k|	load_card_drivers(ctx, &opts);
 1057|  16.1k|	load_card_atrs(ctx);
 1058|       |
 1059|  16.1k|	del_drvs(&opts);
 1060|  16.1k|	sc_ctx_detect_readers(ctx);
 1061|  16.1k|	*ctx_out = ctx;
 1062|       |
 1063|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
 1064|  16.1k|}
sc_release_context:
 1097|  16.1k|{
 1098|  16.1k|	unsigned int i;
 1099|       |
 1100|  16.1k|	if (ctx == NULL) {
  ------------------
  |  Branch (1100:6): [True: 0, False: 16.1k]
  ------------------
 1101|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1102|      0|	}
 1103|  16.1k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  16.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  16.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  16.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 16.1k]
  |  |  ------------------
  ------------------
 1104|  32.2k|	while (list_size(&ctx->readers)) {
  ------------------
  |  Branch (1104:9): [True: 16.1k, False: 16.1k]
  ------------------
 1105|  16.1k|		sc_reader_t *rdr = (sc_reader_t *) list_get_at(&ctx->readers, 0);
 1106|  16.1k|		_sc_delete_reader(ctx, rdr);
 1107|  16.1k|	}
 1108|       |
 1109|  16.1k|	if (ctx->reader_driver != NULL && ctx->reader_driver->ops->finish != NULL)
  ------------------
  |  Branch (1109:6): [True: 16.1k, False: 0]
  |  Branch (1109:36): [True: 0, False: 16.1k]
  ------------------
 1110|      0|		ctx->reader_driver->ops->finish(ctx);
 1111|       |
 1112|   757k|	for (i = 0; ctx->card_drivers[i]; i++) {
  ------------------
  |  Branch (1112:14): [True: 741k, False: 16.1k]
  ------------------
 1113|   741k|		struct sc_card_driver *drv = ctx->card_drivers[i];
 1114|       |
 1115|   741k|		if (drv->atr_map)
  ------------------
  |  Branch (1115:7): [True: 0, False: 741k]
  ------------------
 1116|      0|			_sc_free_atr(ctx, drv);
 1117|   741k|		if (drv->dll)
  ------------------
  |  Branch (1117:7): [True: 0, False: 741k]
  ------------------
 1118|      0|			sc_dlclose(drv->dll);
 1119|   741k|	}
 1120|  16.1k|#ifdef USE_OPENSSL3_LIBCTX
 1121|  16.1k|	sc_openssl3_deinit(ctx);
 1122|  16.1k|#endif
 1123|  16.1k|	if (ctx->preferred_language != NULL)
  ------------------
  |  Branch (1123:6): [True: 0, False: 16.1k]
  ------------------
 1124|      0|		free(ctx->preferred_language);
 1125|  16.1k|	if (ctx->mutex != NULL) {
  ------------------
  |  Branch (1125:6): [True: 0, False: 16.1k]
  ------------------
 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.1k|	if (ctx->conf != NULL)
  ------------------
  |  Branch (1132:6): [True: 16.1k, False: 0]
  ------------------
 1133|  16.1k|		scconf_free(ctx->conf);
 1134|  16.1k|	if (ctx->debug_file && (ctx->debug_file != stdout && ctx->debug_file != stderr))
  ------------------
  |  Branch (1134:6): [True: 16.1k, False: 0]
  |  Branch (1134:26): [True: 16.1k, False: 0]
  |  Branch (1134:55): [True: 0, False: 16.1k]
  ------------------
 1135|      0|		fclose(ctx->debug_file);
 1136|  16.1k|	free(ctx->debug_filename);
 1137|  16.1k|	free(ctx->app_name);
 1138|  16.1k|	free(ctx->exe_path);
 1139|  16.1k|	list_destroy(&ctx->readers);
 1140|  16.1k|	sc_mem_clear(ctx, sizeof(*ctx));
 1141|  16.1k|	free(ctx);
 1142|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
 1143|  16.1k|}
sc_get_cache_dir:
 1170|  3.80k|{
 1171|  3.80k|	char *homedir;
 1172|  3.80k|	const char *cache_dir;
 1173|  3.80k|        scconf_block *conf_block = NULL;
 1174|       |#ifdef _WIN32
 1175|       |	char temp_path[PATH_MAX];
 1176|       |#endif
 1177|  3.80k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1178|  3.80k|	cache_dir = scconf_get_str(conf_block, "file_cache_dir", NULL);
 1179|  3.80k|	if (cache_dir != NULL) {
  ------------------
  |  Branch (1179:6): [True: 0, False: 3.80k]
  ------------------
 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|  3.80k|#ifndef _WIN32
 1185|       |#ifdef __APPLE__
 1186|       |	cache_dir = getenv("Caches");
 1187|       |#else
 1188|  3.80k|	cache_dir = getenv("XDG_CACHE_HOME");
 1189|  3.80k|#endif
 1190|  3.80k|	if (cache_dir != NULL && cache_dir[0] != '\0') {
  ------------------
  |  Branch (1190:6): [True: 0, False: 3.80k]
  |  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|  3.80k|	cache_dir = ".cache/opensc";
 1195|  3.80k|	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|  3.80k|	if (homedir == NULL || homedir[0] == '\0')
  ------------------
  |  Branch (1206:6): [True: 0, False: 3.80k]
  |  Branch (1206:25): [True: 0, False: 3.80k]
  ------------------
 1207|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1208|  3.80k|	if (snprintf(buf, bufsize, "%s/%s", homedir, cache_dir) < 0)
  ------------------
  |  Branch (1208:6): [True: 0, False: 3.80k]
  ------------------
 1209|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1210|  3.80k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.80k|#define SC_SUCCESS				0
  ------------------
 1211|  3.80k|}
sc_make_cache_dir:
 1214|      1|{
 1215|      1|	char dirname[PATH_MAX], *sp;
 1216|      1|	int    r, mkdir_checker;
 1217|      1|	size_t j, namelen;
 1218|       |
 1219|      1|	if ((r = sc_get_cache_dir(ctx, dirname, sizeof(dirname))) < 0)
  ------------------
  |  Branch (1219:6): [True: 0, False: 1]
  ------------------
 1220|      0|		return r;
 1221|      1|	namelen = strlen(dirname);
 1222|       |
 1223|      1|	while (1) {
  ------------------
  |  Branch (1223:9): [True: 1, Folded]
  ------------------
 1224|       |#ifdef _WIN32
 1225|       |		mkdir_checker = mkdir(dirname) >= 0;
 1226|       |#else
 1227|      1|		mkdir_checker = mkdir(dirname, 0700) >= 0;
 1228|      1|#endif
 1229|      1|		if (mkdir_checker)
  ------------------
  |  Branch (1229:7): [True: 1, False: 0]
  ------------------
 1230|      1|			break;
 1231|       |
 1232|      0|		if (errno != ENOENT || (sp = strrchr(dirname, '/')) == NULL
  ------------------
  |  Branch (1232:7): [True: 0, False: 0]
  |  Branch (1232:26): [True: 0, False: 0]
  ------------------
 1233|      0|				|| sp == dirname)
  ------------------
  |  Branch (1233:8): [True: 0, False: 0]
  ------------------
 1234|      0|			goto failed;
 1235|      0|		*sp = '\0';
 1236|      0|	}
 1237|       |
 1238|       |	/* We may have stripped one or more path components from
 1239|       |	 * the directory name. Restore them */
 1240|      1|	while (1) {
  ------------------
  |  Branch (1240:9): [True: 1, Folded]
  ------------------
 1241|      1|		j = strlen(dirname);
 1242|      1|		if (j >= namelen)
  ------------------
  |  Branch (1242:7): [True: 1, False: 0]
  ------------------
 1243|      1|			break;
 1244|      0|		dirname[j] = '/';
 1245|       |#ifdef _WIN32
 1246|       |		mkdir_checker = mkdir(dirname) < 0;
 1247|       |#else
 1248|      0|		mkdir_checker = mkdir(dirname, 0700) < 0;
 1249|      0|#endif
 1250|      0|		if (mkdir_checker)
  ------------------
  |  Branch (1250:7): [True: 0, False: 0]
  ------------------
 1251|      0|			goto failed;
 1252|      0|	}
 1253|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1254|       |
 1255|       |	/* for lack of a better return code */
 1256|      0|failed:
 1257|      0|	sc_log(ctx, "failed to create cache directory");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1258|      0|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1259|      1|}
ctx.c:load_card_atrs:
  633|  16.1k|{
  634|  16.1k|	struct sc_card_driver *driver;
  635|  16.1k|	scconf_block **blocks;
  636|  16.1k|	int i, j, k;
  637|       |
  638|  32.2k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (638:14): [True: 16.1k, False: 16.1k]
  ------------------
  639|  16.1k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], "card_atr", NULL);
  640|  16.1k|		if (!blocks)
  ------------------
  |  Branch (640:7): [True: 0, False: 16.1k]
  ------------------
  641|      0|			continue;
  642|  16.1k|		for (j = 0; blocks[j] != NULL; j++) {
  ------------------
  |  Branch (642:15): [True: 0, False: 16.1k]
  ------------------
  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.1k|		free(blocks);
  704|  16.1k|	}
  705|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  706|  16.1k|}
ctx.c:get_exe_path:
  914|  16.1k|{
  915|       |	/* Find the executable's path which runs this code.
  916|       |	 * See https://github.com/gpakosz/whereami/ for
  917|       |	 * potentially more platforms */
  918|  16.1k|	char exe_path[PATH_MAX] = "unknown executable path";
  919|  16.1k|	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.1k|	if (NULL != realpath("/proc/self/exe", exe_path))
  ------------------
  |  Branch (928:6): [True: 16.1k, False: 0]
  ------------------
  929|  16.1k|		path_found = 1;
  930|  16.1k|#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.1k|	(void) path_found;
  943|  16.1k|#endif
  944|       |
  945|  16.1k|	return strdup(exe_path);
  946|  16.1k|}
ctx.c:set_defaults:
  325|  16.1k|{
  326|  16.1k|	ctx->debug = 0;
  327|  16.1k|	if (ctx->debug_file && (ctx->debug_file != stderr && ctx->debug_file != stdout))
  ------------------
  |  Branch (327:6): [True: 0, False: 16.1k]
  |  Branch (327:26): [True: 0, False: 0]
  |  Branch (327:55): [True: 0, False: 0]
  ------------------
  328|      0|		fclose(ctx->debug_file);
  329|  16.1k|	ctx->debug_file = stderr;
  330|  16.1k|	ctx->flags = 0;
  331|       |	ctx->forced_driver = NULL;
  332|  16.1k|	add_internal_drvs(opts);
  333|  16.1k|}
ctx.c:add_internal_drvs:
  299|  32.2k|{
  300|  32.2k|	const struct _sc_driver_entry *lst;
  301|  32.2k|	int i;
  302|       |
  303|  32.2k|	lst = internal_card_drivers;
  304|  32.2k|	i = 0;
  305|  1.35M|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (305:9): [True: 1.32M, False: 32.2k]
  ------------------
  306|  1.32M|		add_drv(opts, lst[i].name);
  307|  1.32M|		i++;
  308|  1.32M|	}
  309|  32.2k|}
ctx.c:add_drv:
  281|  1.40M|{
  282|  1.40M|	struct _sc_driver_entry *lst;
  283|  1.40M|	int *cp, max, i;
  284|       |
  285|  1.40M|	lst = opts->cdrv;
  286|  1.40M|	cp = &opts->ccount;
  287|  1.40M|	max = SC_MAX_CARD_DRIVERS;
  ------------------
  |  |   31|  1.40M|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  288|  1.40M|	if (*cp == max) /* No space for more drivers... */
  ------------------
  |  Branch (288:6): [True: 0, False: 1.40M]
  ------------------
  289|      0|		return;
  290|  31.3M|	for (i = 0; i < *cp; i++)
  ------------------
  |  Branch (290:14): [True: 29.9M, False: 1.40M]
  ------------------
  291|  29.9M|		if (strcmp(name, lst[i].name) == 0)
  ------------------
  |  Branch (291:7): [True: 0, False: 29.9M]
  ------------------
  292|      0|			return;
  293|  1.40M|	lst[*cp].name = strdup(name);
  294|       |
  295|  1.40M|	*cp = *cp + 1;
  296|  1.40M|}
ctx.c:del_drvs:
  267|  32.2k|{
  268|  32.2k|	struct _sc_driver_entry *lst;
  269|  32.2k|	int *cp, i;
  270|       |
  271|  32.2k|	lst = opts->cdrv;
  272|  32.2k|	cp = &opts->ccount;
  273|       |
  274|  1.43M|	for (i = 0; i < *cp; i++) {
  ------------------
  |  Branch (274:14): [True: 1.40M, False: 32.2k]
  ------------------
  275|  1.40M|		free((void *)lst[i].name);
  276|  1.40M|	}
  277|  32.2k|	*cp = 0;
  278|  32.2k|}
ctx.c:process_config_file:
  709|  16.1k|{
  710|  16.1k|	int i, r, count = 0;
  711|  16.1k|	scconf_block **blocks;
  712|  16.1k|	const char *conf_path = NULL;
  713|  16.1k|	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.1k|	debug = getenv("OPENSC_DEBUG");
  721|  16.1k|	if (debug)
  ------------------
  |  Branch (721:6): [True: 0, False: 16.1k]
  ------------------
  722|      0|		ctx->debug = atoi(debug);
  723|       |
  724|  16.1k|	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.1k|	conf_path = getenv("OPENSC_CONF");
  737|  16.1k|	if (!conf_path)
  ------------------
  |  Branch (737:6): [True: 16.1k, False: 0]
  ------------------
  738|  16.1k|		conf_path = OPENSC_CONF_PATH;
  739|  16.1k|#endif
  740|  16.1k|	ctx->conf = scconf_new(conf_path);
  741|  16.1k|	if (ctx->conf == NULL)
  ------------------
  |  Branch (741:6): [True: 0, False: 16.1k]
  ------------------
  742|      0|		return;
  743|  16.1k|	r = scconf_parse(ctx->conf);
  744|  16.1k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  745|  16.1k|#ifdef OPENSC_CONFIG_STRING
  746|       |	/* Parse the string if config file didn't exist */
  747|  16.1k|	if (r < 0)
  ------------------
  |  Branch (747:6): [True: 16.1k, False: 0]
  ------------------
  748|  16.1k|		r = scconf_parse_string(ctx->conf, OPENSC_CONFIG_STRING);
  ------------------
  |  |  744|  16.1k|#define OPENSC_CONFIG_STRING "app default { card_drivers = old, internal; }"
  ------------------
  749|  16.1k|#endif
  750|  16.1k|	if (r < 1) {
  ------------------
  |  Branch (750:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	sc_log(ctx, "Used configuration file '%s'", conf_path);
  ------------------
  |  |   71|  16.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__
  |  |  ------------------
  ------------------
  764|  16.1k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->exe_path);
  765|  16.1k|	if (blocks && blocks[0])
  ------------------
  |  Branch (765:6): [True: 16.1k, False: 0]
  |  Branch (765:16): [True: 0, False: 16.1k]
  ------------------
  766|      0|		ctx->conf_blocks[count++] = blocks[0];
  767|  16.1k|	free(blocks);
  768|  16.1k|	blocks = scconf_find_blocks(ctx->conf, NULL, "app", ctx->app_name);
  769|  16.1k|	if (blocks && blocks[0])
  ------------------
  |  Branch (769:6): [True: 16.1k, False: 0]
  |  Branch (769:16): [True: 0, False: 16.1k]
  ------------------
  770|      0|		ctx->conf_blocks[count++] = blocks[0];
  771|  16.1k|	free(blocks);
  772|  16.1k|	if (strcmp(ctx->app_name, "default") != 0) {
  ------------------
  |  Branch (772:6): [True: 16.1k, False: 0]
  ------------------
  773|  16.1k|		blocks = scconf_find_blocks(ctx->conf, NULL, "app", "default");
  774|  16.1k|		if (blocks && blocks[0])
  ------------------
  |  Branch (774:7): [True: 16.1k, False: 0]
  |  Branch (774:17): [True: 16.1k, False: 0]
  ------------------
  775|  16.1k|			ctx->conf_blocks[count++] = blocks[0];
  776|  16.1k|		free(blocks);
  777|  16.1k|	}
  778|       |	/* Above we add 3 blocks at most, but conf_blocks has 4 elements,
  779|       |	 * so at least one is NULL */
  780|  32.2k|	for (i = count - 1; i >= 0; i--)
  ------------------
  |  Branch (780:22): [True: 16.1k, False: 16.1k]
  ------------------
  781|  16.1k|		load_parameters(ctx, ctx->conf_blocks[i], opts);
  782|  16.1k|}
ctx.c:load_parameters:
  388|  16.1k|{
  389|  16.1k|	int err = 0;
  390|  16.1k|	const scconf_list *list;
  391|  16.1k|	const char *val;
  392|  16.1k|	int debug;
  393|  16.1k|	const char *disable_hw_pkcs1_padding;
  394|       |#ifdef _WIN32
  395|       |	char expanded_val[PATH_MAX];
  396|       |	DWORD expanded_len;
  397|       |#endif
  398|       |
  399|  16.1k|	debug = scconf_get_int(block, "debug", ctx->debug);
  400|  16.1k|	if (debug > ctx->debug)
  ------------------
  |  Branch (400:6): [True: 0, False: 16.1k]
  ------------------
  401|      0|		ctx->debug = debug;
  402|       |
  403|  16.1k|	val = scconf_get_str(block, "debug_file", NULL);
  404|  16.1k|	if (val)   {
  ------------------
  |  Branch (404:6): [True: 0, False: 16.1k]
  ------------------
  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.1k|	else if (ctx->debug && !ctx->debug_file)   {
  ------------------
  |  Branch (413:11): [True: 0, False: 16.1k]
  |  Branch (413:25): [True: 0, False: 0]
  ------------------
  414|      0|		sc_ctx_log_to_file(ctx, NULL);
  415|      0|	}
  416|       |
  417|  16.1k|	if (scconf_get_bool (block, "disable_popups",
  ------------------
  |  Branch (417:6): [True: 0, False: 16.1k]
  ------------------
  418|  16.1k|				ctx->flags & SC_CTX_FLAG_DISABLE_POPUPS))
  ------------------
  |  |  861|  16.1k|#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.1k|	if (scconf_get_bool (block, "disable_colors",
  ------------------
  |  Branch (421:6): [True: 0, False: 16.1k]
  ------------------
  422|  16.1k|				ctx->flags & SC_CTX_FLAG_DISABLE_COLORS))
  ------------------
  |  |  862|  16.1k|#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.1k|	if (scconf_get_bool (block, "enable_default_driver",
  ------------------
  |  Branch (425:6): [True: 0, False: 16.1k]
  ------------------
  426|  16.1k|				ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER))
  ------------------
  |  |  860|  16.1k|#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.1k|	list = scconf_find_list(block, "card_drivers");
  430|  16.1k|	set_drivers(opts, list);
  431|       |
  432|       |	/* Disable PKCS#1 v1.5 type 2 (for decryption) depadding on card by default */
  433|  16.1k|	disable_hw_pkcs1_padding = "decipher";
  434|  16.1k|	ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  16.1k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  435|  16.1k|	disable_hw_pkcs1_padding = scconf_get_str(block, "disable_hw_pkcs1_padding", disable_hw_pkcs1_padding);
  436|  16.1k|	if (0 == strcmp(disable_hw_pkcs1_padding, "no")) {
  ------------------
  |  Branch (436:6): [True: 0, False: 16.1k]
  ------------------
  437|      0|		ctx->disable_hw_pkcs1_padding = 0;
  438|  16.1k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "sign")) {
  ------------------
  |  Branch (438:13): [True: 0, False: 16.1k]
  ------------------
  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.1k|	} else if (0 == strcmp(disable_hw_pkcs1_padding, "decipher")) {
  ------------------
  |  Branch (440:13): [True: 16.1k, False: 0]
  ------------------
  441|  16.1k|		ctx->disable_hw_pkcs1_padding = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  110|  16.1k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  442|  16.1k|	} 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|  16.1k|#ifdef USE_OPENSSL3_LIBCTX
  447|  16.1k|	val = scconf_get_str(block, "openssl_config", NULL);
  448|  16.1k|	if (val != NULL) {
  ------------------
  |  Branch (448:6): [True: 0, False: 16.1k]
  ------------------
  449|      0|		ctx->openssl_config = strdup(val);
  450|      0|	}
  451|  16.1k|#endif
  452|       |
  453|  16.1k|	return err;
  454|  16.1k|}
ctx.c:sc_openssl3_init:
  849|  16.1k|{
  850|  16.1k|	ctx->ossl3ctx = calloc(1, sizeof(ossl3ctx_t));
  851|  16.1k|	if (ctx->ossl3ctx == NULL) {
  ------------------
  |  Branch (851:6): [True: 0, False: 16.1k]
  ------------------
  852|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  853|      0|	}
  854|       |
  855|  16.1k|	ctx->ossl3ctx->libctx = OSSL_LIB_CTX_new();
  856|  16.1k|	if (ctx->ossl3ctx->libctx == NULL) {
  ------------------
  |  Branch (856:6): [True: 0, False: 16.1k]
  ------------------
  857|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  858|      0|	}
  859|       |
  860|  16.1k|	if (ctx->openssl_config != NULL) {
  ------------------
  |  Branch (860:6): [True: 0, False: 16.1k]
  ------------------
  861|      0|		if (access(ctx->openssl_config, R_OK) != 0) {
  ------------------
  |  Branch (861:7): [True: 0, False: 0]
  ------------------
  862|      0|			sc_log(ctx, "Warning: provided OpenSSL configuration file '%s' is not readable",
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  863|      0|					ctx->openssl_config);
  864|      0|		} else {
  865|       |			/*
  866|       |			 * Load OpenSC specific openssl config file to configure FIPS module
  867|       |			 * (or whatever else the user needs).
  868|       |			 * We assume that this config file will automatically activate the FIPS
  869|       |			 * and base providers so we don't need to explicitly load them here.
  870|       |			 */
  871|      0|			if (!OSSL_LIB_CTX_load_config(ctx->ossl3ctx->libctx, ctx->openssl_config)) {
  ------------------
  |  Branch (871:8): [True: 0, False: 0]
  ------------------
  872|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  873|      0|			}
  874|      0|		}
  875|  16.1k|	} else {
  876|       |		/* We do not have configuration file specified: load the default
  877|       |		 * and legacy providers */
  878|  16.1k|		const char *defprov_name = "default";
  879|  16.1k|		if (FIPS_mode()) {
  ------------------
  |  |   66|  16.1k|#define FIPS_mode()                             EVP_default_properties_is_fips_enabled(NULL)
  |  |  ------------------
  |  |  |  Branch (66:49): [True: 0, False: 16.1k]
  |  |  ------------------
  ------------------
  880|      0|			defprov_name = "fips";
  881|      0|		}
  882|  16.1k|		ctx->ossl3ctx->defprov = OSSL_PROVIDER_load(ctx->ossl3ctx->libctx, defprov_name);
  883|  16.1k|		if (ctx->ossl3ctx->defprov == NULL) {
  ------------------
  |  Branch (883:7): [True: 0, False: 16.1k]
  ------------------
  884|      0|			OSSL_LIB_CTX_free(ctx->ossl3ctx->libctx);
  885|      0|			free(ctx->ossl3ctx);
  886|      0|			ctx->ossl3ctx = NULL;
  887|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  888|      0|		}
  889|       |		/* yes, legacy -- smart cards depend on several legacy algorithms */
  890|  16.1k|		ctx->ossl3ctx->legacyprov = OSSL_PROVIDER_load(ctx->ossl3ctx->libctx, "legacy");
  891|  16.1k|		if (ctx->ossl3ctx->legacyprov == NULL) {
  ------------------
  |  Branch (891:7): [True: 0, False: 16.1k]
  ------------------
  892|      0|			sc_log(ctx, "Failed to load OpenSSL Legacy 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__
  |  |  ------------------
  ------------------
  893|      0|		}
  894|  16.1k|	}
  895|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  896|  16.1k|}
ctx.c:set_drivers:
  371|  16.1k|{
  372|  16.1k|	const char *s_internal = "internal", *s_old = "old";
  373|  16.1k|	if (list != NULL)
  ------------------
  |  Branch (373:6): [True: 16.1k, False: 0]
  ------------------
  374|  16.1k|		del_drvs(opts);
  375|  48.3k|	while (list != NULL) {
  ------------------
  |  Branch (375:9): [True: 32.2k, False: 16.1k]
  ------------------
  376|  32.2k|		if (strcmp(list->data, s_internal) == 0)
  ------------------
  |  Branch (376:7): [True: 16.1k, False: 16.1k]
  ------------------
  377|  16.1k|			add_internal_drvs(opts);
  378|  16.1k|		else if (strcmp(list->data, s_old) == 0)
  ------------------
  |  Branch (378:12): [True: 16.1k, False: 0]
  ------------------
  379|  16.1k|			add_old_drvs(opts);
  380|      0|		else
  381|      0|			add_drv(opts, list->data);
  382|  32.2k|		list = list->next;
  383|  32.2k|	}
  384|  16.1k|}
ctx.c:add_old_drvs:
  312|  16.1k|{
  313|  16.1k|	const struct _sc_driver_entry *lst;
  314|  16.1k|	int i;
  315|       |
  316|  16.1k|	lst = old_card_drivers;
  317|  16.1k|	i = 0;
  318|  96.7k|	while (lst[i].name != NULL) {
  ------------------
  |  Branch (318:9): [True: 80.6k, False: 16.1k]
  ------------------
  319|  80.6k|		add_drv(opts, lst[i].name);
  320|  80.6k|		i++;
  321|  80.6k|	}
  322|  16.1k|}
ctx.c:load_card_drivers:
  567|  16.1k|{
  568|  16.1k|	const struct _sc_driver_entry *ent;
  569|  16.1k|	int drv_count;
  570|  16.1k|	int i;
  571|       |
  572|  16.1k|	for (drv_count = 0; ctx->card_drivers[drv_count] != NULL; drv_count++)
  ------------------
  |  Branch (572:22): [True: 0, False: 16.1k]
  ------------------
  573|      0|		;
  574|       |
  575|   757k|	for (i = 0; i < opts->ccount; i++) {
  ------------------
  |  Branch (575:14): [True: 741k, False: 16.1k]
  ------------------
  576|   741k|		struct sc_card_driver *(*func)(void) = NULL;
  577|   741k|		struct sc_card_driver *(**tfunc)(void) = &func;
  578|   741k|		void *dll = NULL;
  579|   741k|		int  j;
  580|       |
  581|   741k|		if (drv_count >= SC_MAX_CARD_DRIVERS - 1)   {
  ------------------
  |  |   31|   741k|#define SC_MAX_CARD_DRIVERS		48
  ------------------
  |  Branch (581:7): [True: 0, False: 741k]
  ------------------
  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|   741k|		ent = &opts->cdrv[i];
  587|  17.2M|		for (j = 0; internal_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (587:15): [True: 17.1M, False: 80.6k]
  ------------------
  588|  17.1M|			if (strcmp(ent->name, internal_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (588:8): [True: 661k, False: 16.5M]
  ------------------
  589|   661k|				func = (struct sc_card_driver *(*)(void)) internal_card_drivers[j].func;
  590|   661k|				break;
  591|   661k|			}
  592|  17.1M|		}
  593|   741k|		if (func == NULL) {
  ------------------
  |  Branch (593:7): [True: 80.6k, False: 661k]
  ------------------
  594|   241k|			for (j = 0; old_card_drivers[j].name != NULL; j++) {
  ------------------
  |  Branch (594:16): [True: 241k, False: 0]
  ------------------
  595|   241k|				if (strcmp(ent->name, old_card_drivers[j].name) == 0) {
  ------------------
  |  Branch (595:9): [True: 80.6k, False: 161k]
  ------------------
  596|  80.6k|					func = (struct sc_card_driver *(*)(void)) old_card_drivers[j].func;
  597|  80.6k|					break;
  598|  80.6k|				}
  599|   241k|			}
  600|  80.6k|		}
  601|       |		/* if not initialized assume external module */
  602|   741k|		if (func == NULL)
  ------------------
  |  Branch (602:7): [True: 0, False: 741k]
  ------------------
  603|      0|			*(void **)(tfunc) = load_dynamic_driver(ctx, &dll, ent->name);
  604|       |		/* if still null, assume driver not found */
  605|   741k|		if (func == NULL) {
  ------------------
  |  Branch (605:7): [True: 0, False: 741k]
  ------------------
  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|   741k|		ctx->card_drivers[drv_count] = func();
  613|   741k|		if (ctx->card_drivers[drv_count] == NULL) {
  ------------------
  |  Branch (613:7): [True: 0, False: 741k]
  ------------------
  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|   741k|		ctx->card_drivers[drv_count]->dll = dll;
  619|   741k|		ctx->card_drivers[drv_count]->atr_map = NULL;
  620|   741k|		ctx->card_drivers[drv_count]->natrs = 0;
  621|       |
  622|   741k|		load_card_driver_options(ctx, ctx->card_drivers[drv_count]);
  623|       |
  624|       |		/* Ensure that the list is always terminated by NULL */
  625|   741k|		ctx->card_drivers[drv_count + 1] = NULL;
  626|       |
  627|   741k|		drv_count++;
  628|   741k|	}
  629|  16.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  630|  16.1k|}
ctx.c:load_card_driver_options:
  546|   741k|{
  547|   741k|	scconf_block **blocks, *blk;
  548|   741k|	int i;
  549|       |
  550|  1.48M|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (550:14): [True: 741k, False: 741k]
  ------------------
  551|   741k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  552|   741k|				"card_driver", driver->short_name);
  553|   741k|		if (!blocks)
  ------------------
  |  Branch (553:7): [True: 0, False: 741k]
  ------------------
  554|      0|			continue;
  555|   741k|		blk = blocks[0];
  556|   741k|		free(blocks);
  557|       |
  558|   741k|		if (blk == NULL)
  ------------------
  |  Branch (558:7): [True: 741k, False: 0]
  ------------------
  559|   741k|			continue;
  560|       |
  561|       |		/* no options at the moment */
  562|   741k|	}
  563|   741k|	return SC_SUCCESS;
  ------------------
  |  |   28|   741k|#define SC_SUCCESS				0
  ------------------
  564|   741k|}
ctx.c:sc_openssl3_deinit:
  899|  16.1k|{
  900|  16.1k|	if (ctx->ossl3ctx == NULL)
  ------------------
  |  Branch (900:6): [True: 0, False: 16.1k]
  ------------------
  901|      0|		return;
  902|  16.1k|	if (ctx->ossl3ctx->legacyprov)
  ------------------
  |  Branch (902:6): [True: 16.1k, False: 0]
  ------------------
  903|  16.1k|		OSSL_PROVIDER_unload(ctx->ossl3ctx->legacyprov);
  904|  16.1k|	if (ctx->ossl3ctx->defprov)
  ------------------
  |  Branch (904:6): [True: 16.1k, False: 0]
  ------------------
  905|  16.1k|		OSSL_PROVIDER_unload(ctx->ossl3ctx->defprov);
  906|  16.1k|	if (ctx->ossl3ctx->libctx)
  ------------------
  |  Branch (906:6): [True: 16.1k, False: 0]
  ------------------
  907|  16.1k|		OSSL_LIB_CTX_free(ctx->ossl3ctx->libctx);
  908|  16.1k|	free(ctx->ossl3ctx);
  909|       |	ctx->ossl3ctx = NULL;
  910|  16.1k|}

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

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

sc_enum_apps:
  162|  11.4k|{
  163|  11.4k|	struct sc_context *ctx = card->ctx;
  164|  11.4k|	sc_path_t path;
  165|  11.4k|	int ef_structure;
  166|  11.4k|	size_t file_size, jj;
  167|  11.4k|	int r, ii, idx;
  168|  11.4k|	struct sc_file *ef_dir = NULL;
  169|       |
  170|  11.4k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  11.4k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.4k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.4k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  171|       |
  172|  11.4k|	sc_free_apps(card);
  173|  11.4k|	card->app_count = 0;
  174|       |
  175|  11.4k|	sc_format_path("3F002F00", &path);
  176|  11.4k|	r = sc_select_file(card, &path, &ef_dir);
  177|  11.4k|	if (r < 0)
  ------------------
  |  Branch (177:6): [True: 9.05k, False: 2.39k]
  ------------------
  178|  9.05k|		sc_file_free(ef_dir);
  179|  11.4k|	LOG_TEST_RET(ctx, r, "Cannot select EF.DIR file");
  ------------------
  |  |  174|  11.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  11.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  11.4k|	int _ret = (r); \
  |  |  |  |  168|  11.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9.05k, False: 2.39k]
  |  |  |  |  ------------------
  |  |  |  |  169|  9.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|  9.05k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  9.05k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  9.05k|		return _ret; \
  |  |  |  |  172|  9.05k|	} \
  |  |  |  |  173|  11.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.39k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  180|       |
  181|  2.39k|	if (ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
  ------------------
  |  |  216|  2.39k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (181:6): [True: 1.38k, False: 1.00k]
  ------------------
  182|  1.38k|		sc_file_free(ef_dir);
  183|  1.38k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_CARD, "EF(DIR) is not a working EF.");
  ------------------
  |  |  174|  1.38k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.38k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.38k|	int _ret = (r); \
  |  |  |  |  168|  1.38k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.38k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.38k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.38k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.38k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.38k|		return _ret; \
  |  |  |  |  172|  1.38k|	} \
  |  |  |  |  173|  1.38k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  184|  1.38k|	}
  185|       |
  186|  1.00k|	ef_structure = ef_dir->ef_structure;
  187|  1.00k|	file_size = ef_dir->size;
  188|  1.00k|	sc_file_free(ef_dir);
  189|  1.00k|	if (ef_structure == SC_FILE_EF_TRANSPARENT) {
  ------------------
  |  |  221|  1.00k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (189:6): [True: 501, False: 503]
  ------------------
  190|    501|		u8 *buf = NULL, *p;
  191|    501|		size_t bufsize;
  192|       |
  193|    501|		if (file_size == 0)
  ------------------
  |  Branch (193:7): [True: 38, False: 463]
  ------------------
  194|    501|			LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 38]
  |  |  |  |  ------------------
  |  |  |  |  157|     38|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|    463|		if (file_size > MAX_FILE_SIZE)
  ------------------
  |  |  220|    463|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (195:7): [True: 22, False: 441]
  ------------------
  196|    463|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  197|       |
  198|    441|		buf = malloc(file_size);
  199|    441|		if (buf == NULL)
  ------------------
  |  Branch (199:7): [True: 0, False: 441]
  ------------------
  200|    441|			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|    441|		p = buf;
  202|    441|		r = sc_read_binary(card, 0, buf, file_size, 0);
  203|    441|		if (r < 0) {
  ------------------
  |  Branch (203:7): [True: 190, False: 251]
  ------------------
  204|    190|			free(buf);
  205|    190|			LOG_TEST_RET(ctx, r, "sc_read_binary() failed");
  ------------------
  |  |  174|    190|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    190|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    190|	int _ret = (r); \
  |  |  |  |  168|    190|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 190, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    190|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    190|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    190|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    190|		return _ret; \
  |  |  |  |  172|    190|	} \
  |  |  |  |  173|    190|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  206|    190|		}
  207|    251|		bufsize = r;
  208|    492|		while (bufsize > 0) {
  ------------------
  |  Branch (208:10): [True: 366, False: 126]
  ------------------
  209|    366|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    366|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (209:8): [True: 1, False: 365]
  ------------------
  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|    365|			r = parse_dir_record(card, &p, &bufsize, -1);
  214|    365|			if (r)
  ------------------
  |  Branch (214:8): [True: 124, False: 241]
  ------------------
  215|    124|				break;
  216|    365|		}
  217|    251|		if (buf)
  ------------------
  |  Branch (217:7): [True: 251, False: 0]
  ------------------
  218|    251|			free(buf);
  219|       |
  220|    251|	}
  221|    503|	else {	/* record structure */
  222|    503|		unsigned char buf[256], *p;
  223|    503|		unsigned int rec_nr;
  224|    503|		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.35k|		for (rec_nr = 1; rec_nr < 16; rec_nr++) {
  ------------------
  |  Branch (228:20): [True: 1.34k, False: 7]
  ------------------
  229|  1.34k|			r = sc_read_record(card, rec_nr, 0, buf, sizeof(buf), SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|  1.34k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  230|  1.34k|			if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|  1.34k|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (230:8): [True: 1, False: 1.34k]
  ------------------
  231|      1|				break;
  232|  1.34k|			LOG_TEST_RET(ctx, r, "read_record() failed");
  ------------------
  |  |  174|  1.34k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.34k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.34k|	int _ret = (r); \
  |  |  |  |  168|  1.34k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 494, False: 849]
  |  |  |  |  ------------------
  |  |  |  |  169|    494|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    494|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    494|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    494|		return _ret; \
  |  |  |  |  172|    494|	} \
  |  |  |  |  173|  1.34k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 849]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|       |
  234|    849|			if (card->app_count == SC_MAX_CARD_APPS) {
  ------------------
  |  |   33|    849|#define SC_MAX_CARD_APPS		8
  ------------------
  |  Branch (234:8): [True: 1, False: 848]
  ------------------
  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|    848|			rec_size = r;
  240|    848|			p = buf;
  241|    848|			parse_dir_record(card, &p, &rec_size, (int)rec_nr);
  242|    848|		}
  243|    503|	}
  244|       |
  245|       |	/* Move known PKCS#15 applications to the head of the list */
  246|    509|	for (ii=0, idx=0; ii<card->app_count; ii++)   {
  ------------------
  |  Branch (246:20): [True: 249, False: 260]
  ------------------
  247|  2.09k|		for (jj=0; jj < sizeof(apps)/sizeof(apps[0]); jj++) {
  ------------------
  |  Branch (247:14): [True: 1.86k, False: 224]
  ------------------
  248|  1.86k|			if (apps[jj].aid_len != card->app[ii]->aid.len)
  ------------------
  |  Branch (248:8): [True: 1.78k, False: 88]
  ------------------
  249|  1.78k|				continue;
  250|     88|			if (memcmp(apps[jj].aid, card->app[ii]->aid.value, apps[jj].aid_len))
  ------------------
  |  Branch (250:8): [True: 63, False: 25]
  ------------------
  251|     63|				continue;
  252|     25|			break;
  253|     88|		}
  254|       |
  255|    249|		if (ii != idx && jj < sizeof(apps)/sizeof(apps[0]))   {
  ------------------
  |  Branch (255:7): [True: 102, False: 147]
  |  Branch (255:20): [True: 18, False: 84]
  ------------------
  256|     18|			struct sc_app_info *tmp = card->app[idx];
  257|       |
  258|     18|			card->app[idx] = card->app[ii];
  259|     18|			card->app[ii] = tmp;
  260|     18|			idx++;
  261|     18|		}
  262|    249|	}
  263|       |
  264|    260|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    260|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    260|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    260|	int _ret = r; \
  |  |  |  |  155|    260|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 260, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    260|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 260]
  |  |  |  |  ------------------
  |  |  |  |  157|    260|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    260|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    260|	return _ret; \
  |  |  |  |  163|    260|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  265|    260|}
sc_free_apps:
  268|  27.5k|{
  269|  27.5k|	int	i;
  270|       |
  271|  28.0k|	for (i = 0; i < card->app_count; i++) {
  ------------------
  |  Branch (271:14): [True: 459, False: 27.5k]
  ------------------
  272|    459|		free(card->app[i]->label);
  273|    459|		free(card->app[i]->ddo.value);
  274|    459|		free(card->app[i]);
  275|    459|	}
  276|  27.5k|	card->app_count = -1;
  277|  27.5k|}
dir.c:parse_dir_record:
   64|  1.21k|{
   65|  1.21k|	struct sc_context *ctx = card->ctx;
   66|  1.21k|	struct sc_asn1_entry asn1_dirrecord[5], asn1_dir[2];
   67|  1.21k|	scconf_block *conf_block = NULL;
   68|  1.21k|	sc_app_info_t *app = NULL;
   69|  1.21k|	struct sc_aid aid;
   70|  1.21k|	u8 label[128], path[128], ddo[128];
   71|  1.21k|	size_t label_len = sizeof(label) - 1, path_len = sizeof(path), ddo_len = sizeof(ddo);
   72|  1.21k|	int r;
   73|       |
   74|  1.21k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.21k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.21k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.21k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.21k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.21k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   75|  1.21k|	aid.len = sizeof(aid.value);
   76|       |
   77|  1.21k|	memset(label, 0, sizeof(label));
   78|  1.21k|	sc_copy_asn1_entry(c_asn1_dirrecord, asn1_dirrecord);
   79|  1.21k|	sc_copy_asn1_entry(c_asn1_dir, asn1_dir);
   80|  1.21k|	sc_format_asn1_entry(asn1_dir + 0, asn1_dirrecord, NULL, 0);
   81|  1.21k|	sc_format_asn1_entry(asn1_dirrecord + 0, aid.value, &aid.len, 0);
   82|  1.21k|	sc_format_asn1_entry(asn1_dirrecord + 1, label, &label_len, 0);
   83|  1.21k|	sc_format_asn1_entry(asn1_dirrecord + 2, path, &path_len, 0);
   84|  1.21k|	sc_format_asn1_entry(asn1_dirrecord + 3, ddo, &ddo_len, 0);
   85|       |
   86|  1.21k|	r = sc_asn1_decode(ctx, asn1_dir, *buf, *buflen, (const u8 **) buf, buflen);
   87|  1.21k|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  1.21k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (87:6): [True: 50, False: 1.16k]
  ------------------
   88|  1.21k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|     50|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     50|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     50|	int _ret = r; \
  |  |  |  |  155|     50|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 50, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     50|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     50|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 50, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     50|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     50|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     50|	return _ret; \
  |  |  |  |  163|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|  1.16k|	LOG_TEST_RET(ctx, r, "EF(DIR) parsing failed");
  ------------------
  |  |  174|  1.16k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.16k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.16k|	int _ret = (r); \
  |  |  |  |  168|  1.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 694, False: 469]
  |  |  |  |  ------------------
  |  |  |  |  169|    694|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    694|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    694|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    694|		return _ret; \
  |  |  |  |  172|    694|	} \
  |  |  |  |  173|  1.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 469]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   90|       |
   91|    469|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
   92|    469|	if (conf_block)   {
  ------------------
  |  Branch (92:6): [True: 0, False: 469]
  ------------------
   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|    469|	app = calloc(1, sizeof(struct sc_app_info));
  111|    469|	if (app == NULL)
  ------------------
  |  Branch (111:6): [True: 0, False: 469]
  ------------------
  112|    469|		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|    469|	memcpy(&app->aid, &aid, sizeof(struct sc_aid));
  115|       |
  116|    469|	if (asn1_dirrecord[1].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  171|    469|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (116:6): [True: 38, False: 431]
  ------------------
  117|     38|		app->label = strdup((char *) label);
  118|    431|	else
  119|    431|		app->label = NULL;
  120|       |
  121|    469|	if (asn1_dirrecord[2].flags & SC_ASN1_PRESENT && path_len > 0) {
  ------------------
  |  |  171|    938|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (121:6): [True: 221, False: 248]
  |  Branch (121:51): [True: 202, False: 19]
  ------------------
  122|       |		/* application path present: ignore AID */
  123|    202|		if (path_len > SC_MAX_PATH_SIZE) {
  ------------------
  |  |   47|    202|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (123:7): [True: 10, False: 192]
  ------------------
  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|    192|		memcpy(app->path.value, path, path_len);
  129|    192|		app->path.len = path_len;
  130|    192|		app->path.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    192|#define SC_PATH_TYPE_PATH		2
  ------------------
  131|    192|	}
  132|    267|	else {
  133|       |		/* application path not present: use AID as application path */
  134|    267|		memcpy(app->path.value, aid.value, aid.len);
  135|    267|		app->path.len = aid.len;
  136|    267|		app->path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    267|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  137|    267|	}
  138|       |
  139|    459|	if (asn1_dirrecord[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|    459|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (139:6): [True: 47, False: 412]
  ------------------
  140|     47|		app->ddo.value = malloc(ddo_len);
  141|     47|		if (app->ddo.value == NULL) {
  ------------------
  |  Branch (141:7): [True: 0, False: 47]
  ------------------
  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|     47|		memcpy(app->ddo.value, ddo, ddo_len);
  147|     47|		app->ddo.len = ddo_len;
  148|    412|	} else {
  149|    412|		app->ddo.value = NULL;
  150|    412|		app->ddo.len = 0;
  151|    412|	}
  152|       |
  153|    459|	app->rec_nr = rec_nr;
  154|    459|	card->app[card->app_count] = app;
  155|    459|	card->app_count++;
  156|       |
  157|    459|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    459|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    459|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    459|	int _ret = r; \
  |  |  |  |  155|    459|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 459, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    459|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 459]
  |  |  |  |  ------------------
  |  |  |  |  157|    459|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    459|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    459|	return _ret; \
  |  |  |  |  163|    459|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|    459|}

sc_parse_ef_atr:
  134|  1.33k|{
  135|  1.33k|	struct sc_context *ctx = card->ctx;
  136|  1.33k|	struct sc_path path;
  137|  1.33k|	struct sc_file *file = NULL;
  138|  1.33k|	int rv;
  139|  1.33k|	unsigned char *buf = NULL;
  140|  1.33k|	size_t size;
  141|  1.33k|	size_t off = 0;
  142|       |
  143|  1.33k|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  144|       |
  145|  1.33k|	sc_format_path("3F002F01", &path);
  146|  1.33k|	rv = sc_select_file(card, &path, &file);
  147|  1.33k|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot select EF(ATR) file");
  ------------------
  |  |  184|  1.33k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.33k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.33k|	int _ret = (r); \
  |  |  |  |  178|  1.33k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 774, False: 556]
  |  |  |  |  ------------------
  |  |  |  |  179|    774|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    774|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    774|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    774|		goto err; \
  |  |  |  |  182|    774|	} \
  |  |  |  |  183|  1.33k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 556]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  148|       |
  149|    556|	if (file->size) {
  ------------------
  |  Branch (149:6): [True: 82, False: 474]
  ------------------
  150|     82|		size = file->size;
  151|    474|	} else {
  152|    474|		size = 1024;
  153|    474|	}
  154|    556|	buf = malloc(size);
  155|    556|	if (!buf) {
  ------------------
  |  Branch (155:6): [True: 0, False: 556]
  ------------------
  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|    556|	rv = sc_read_binary(card, 0, buf, size, 0);
  160|    556|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot read EF(ATR) file");
  ------------------
  |  |  184|    556|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    556|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    556|	int _ret = (r); \
  |  |  |  |  178|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 187, False: 369]
  |  |  |  |  ------------------
  |  |  |  |  179|    187|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    187|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    187|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    187|		goto err; \
  |  |  |  |  182|    187|	} \
  |  |  |  |  183|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 369]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|       |
  162|       |	/* Workaround: Some cards seem to have a buggy storage of the EF.ATR */
  163|    369|	if ((card->type == SC_CARD_TYPE_IASECC_CPX) ||
  ------------------
  |  Branch (163:6): [True: 122, False: 247]
  ------------------
  164|    247|	    (card->type == SC_CARD_TYPE_IASECC_CPXCL)) {
  ------------------
  |  Branch (164:6): [True: 35, False: 212]
  ------------------
  165|       |		/* Let's keep the first byte */
  166|    157|		if ((rv > 1) &&
  ------------------
  |  Branch (166:7): [True: 152, False: 5]
  ------------------
  167|    152|		    (buf[0] == ISO7816_II_CATEGORY_TLV))
  ------------------
  |  |   28|    152|#define ISO7816_II_CATEGORY_TLV		0x80
  ------------------
  |  Branch (167:7): [True: 3, False: 149]
  ------------------
  168|      3|			off++;
  169|    157|	}
  170|    369|	rv = sc_parse_ef_atr_content(card, buf + off, rv - off);
  171|    369|	LOG_TEST_GOTO_ERR(ctx, rv, "EF(ATR) parse error");
  ------------------
  |  |  184|    369|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    369|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    369|	int _ret = (r); \
  |  |  |  |  178|    369|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 16, False: 353]
  |  |  |  |  ------------------
  |  |  |  |  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|    369|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 353]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  172|       |
  173|    353|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    353|#define SC_SUCCESS				0
  ------------------
  174|       |
  175|  1.33k|err:
  176|  1.33k|	sc_file_free(file);
  177|  1.33k|	free(buf);
  178|  1.33k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|    977|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 977, False: 353]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  179|  1.33k|}
sc_free_ef_atr:
  182|  16.1k|{
  183|  16.1k|	if (card->ef_atr)
  ------------------
  |  Branch (183:6): [True: 849, False: 15.2k]
  ------------------
  184|    849|		free(card->ef_atr);
  185|       |	card->ef_atr = NULL;
  186|  16.1k|}
ef-atr.c:sc_parse_ef_atr_content:
   35|    369|{
   36|    369|	struct sc_context *ctx = card->ctx;
   37|    369|	const unsigned char *tag = NULL;
   38|    369|	size_t taglen;
   39|    369|	struct sc_ef_atr ef_atr;
   40|       |
   41|    369|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    369|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    369|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    369|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    369|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 369]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   42|       |
   43|    369|	memset(&ef_atr, 0, sizeof(struct sc_ef_atr));
   44|       |
   45|    369|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_CARD_SERVICE, &taglen);
  ------------------
  |  |   31|    369|#define ISO7816_TAG_II_CARD_SERVICE		0x43
  ------------------
   46|    369|	if (tag && taglen >= 1)   {
  ------------------
  |  Branch (46:6): [True: 3, False: 366]
  |  Branch (46:13): [True: 1, False: 2]
  ------------------
   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|    369|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_PRE_ISSUING, &taglen);
  ------------------
  |  |   34|    369|#define ISO7816_TAG_II_PRE_ISSUING		0x46
  ------------------
   52|    369|	if (tag) {
  ------------------
  |  Branch (52:6): [True: 115, False: 254]
  ------------------
   53|    115|		size_t len = taglen > sizeof(ef_atr.pre_issuing) ? sizeof(ef_atr.pre_issuing) : taglen;
  ------------------
  |  Branch (53:16): [True: 97, False: 18]
  ------------------
   54|       |
   55|    115|		memcpy(ef_atr.pre_issuing, tag, len);
   56|    115|		ef_atr.pre_issuing_len = len;
   57|       |
   58|    115|		sc_log(ctx, "EF.ATR: Pre-Issuing data '%s'", sc_dump_hex(ef_atr.pre_issuing, ef_atr.pre_issuing_len));
  ------------------
  |  |   71|    115|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   59|    115|	}
   60|       |
   61|    369|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_CARD_CAPABILITIES, &taglen);
  ------------------
  |  |   35|    369|#define ISO7816_TAG_II_CARD_CAPABILITIES	0x47
  ------------------
   62|    369|	if (tag && taglen >= 3) {
  ------------------
  |  Branch (62:6): [True: 4, False: 365]
  |  Branch (62:13): [True: 3, False: 1]
  ------------------
   63|      3|		ef_atr.df_selection =  *(tag + 0);
   64|      3|		ef_atr.unit_size = *(tag + 1);
   65|      3|		ef_atr.card_capabilities = *(tag + 2);
   66|      3|		sc_log(ctx, "EF.ATR: DF selection %X, unit_size %zX, card caps %X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   67|      3|				ef_atr.df_selection, ef_atr.unit_size, ef_atr.card_capabilities);
   68|      3|	}
   69|       |
   70|    369|	if (ef_atr.card_capabilities & ISO7816_CAP_EXTENDED_LENGTH_INFO) {
  ------------------
  |  |   45|    369|#define ISO7816_CAP_EXTENDED_LENGTH_INFO	0x20
  ------------------
  |  Branch (70:6): [True: 1, False: 368]
  ------------------
   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|    369|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_AID, &taglen);
  ------------------
  |  |   36|    369|#define ISO7816_TAG_II_AID			0x4F
  ------------------
   85|    369|	if (tag) {
  ------------------
  |  Branch (85:6): [True: 6, False: 363]
  ------------------
   86|      6|		if (taglen > sizeof(ef_atr.aid.value))
  ------------------
  |  Branch (86:7): [True: 1, False: 5]
  ------------------
   87|      6|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid MF AID size");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   88|      5|		memcpy(ef_atr.aid.value, tag, taglen);
   89|      5|		ef_atr.aid.len = taglen;
   90|      5|		sc_log(ctx, "EF.ATR: AID '%s'", sc_dump_hex(ef_atr.aid.value, 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__
  |  |  ------------------
  ------------------
   91|      5|	}
   92|       |
   93|       |	/* IAS/ECC specific issuer data: contains the max send/recv buffer sizes in plain and SM modes */
   94|    368|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_TAG_II_IO_BUFFER_SIZES, &taglen);
  ------------------
  |  |   48|    368|#define IASECC_TAG_II_IO_BUFFER_SIZES		0xE0
  ------------------
   95|    368|	if (tag) {
  ------------------
  |  Branch (95:6): [True: 181, False: 187]
  ------------------
   96|    181|		size_t len = taglen > sizeof(ef_atr.issuer_data) ? sizeof(ef_atr.issuer_data) : taglen;
  ------------------
  |  Branch (96:16): [True: 96, False: 85]
  ------------------
   97|       |
   98|    181|		memcpy(ef_atr.issuer_data, tag, len);
   99|    181|		ef_atr.issuer_data_len = len;
  100|       |
  101|    181|		sc_log(ctx, "EF.ATR: Issuer data '%s'", sc_dump_hex(ef_atr.issuer_data, ef_atr.issuer_data_len));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  102|    181|	}
  103|       |
  104|    368|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_ALLOCATION_SCHEME, &taglen);
  ------------------
  |  |   37|    368|#define ISO7816_TAG_II_ALLOCATION_SCHEME        0x78
  ------------------
  105|    368|	if (tag)   {
  ------------------
  |  Branch (105:6): [True: 34, False: 334]
  ------------------
  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);
  ------------------
  |  |  224|     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: 15, False: 16]
  ------------------
  111|     31|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ASN1_OBJECT);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  112|     31|		}
  113|     34|	}
  114|       |
  115|    353|	tag = sc_asn1_find_tag(ctx, buf, buflen, ISO7816_TAG_II_STATUS_SW, &taglen);
  ------------------
  |  |   39|    353|#define ISO7816_TAG_II_STATUS_SW		0x82
  ------------------
  116|    353|	if (tag && taglen == 2)   {
  ------------------
  |  Branch (116:6): [True: 4, False: 349]
  |  Branch (116:13): [True: 2, False: 2]
  ------------------
  117|      2|		ef_atr.status = *(tag + 0) * 0x100 + *(tag + 1);
  118|      2|		sc_log(ctx, "EF.ATR: status word 0x%X", ef_atr.status);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  119|      2|	}
  120|       |
  121|    353|	if (!card->ef_atr)
  ------------------
  |  Branch (121:6): [True: 347, False: 6]
  ------------------
  122|    347|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  123|       |
  124|    353|	if (!card->ef_atr)
  ------------------
  |  Branch (124:6): [True: 0, False: 353]
  ------------------
  125|    353|		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|    353|	memcpy(card->ef_atr, &ef_atr, sizeof(struct sc_ef_atr));
  128|       |
  129|    353|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    353|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    353|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    353|	int _ret = r; \
  |  |  |  |  155|    353|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 353, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    353|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 353]
  |  |  |  |  ------------------
  |  |  |  |  157|    353|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    353|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    353|	return _ret; \
  |  |  |  |  163|    353|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  130|    353|}

sc_parse_ef_gdo:
   99|  1.24k|{
  100|  1.24k|	struct sc_context *ctx;
  101|  1.24k|	struct sc_path path;
  102|  1.24k|	struct sc_file *file = NULL;
  103|  1.24k|	unsigned char *gdo = NULL;
  104|  1.24k|	size_t gdo_len = 0;
  105|  1.24k|	int r;
  106|       |
  107|  1.24k|	if (!card)
  ------------------
  |  Branch (107:6): [True: 0, False: 1.24k]
  ------------------
  108|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  109|       |
  110|  1.24k|	ctx = card->ctx;
  111|       |
  112|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  113|       |
  114|  1.24k|	sc_format_path("3F002F02", &path);
  115|  1.24k|	r = sc_select_file(card, &path, &file);
  116|  1.24k|	LOG_TEST_GOTO_ERR(ctx, r, "Cannot select EF(GDO) file");
  ------------------
  |  |  184|  1.24k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.24k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.24k|	int _ret = (r); \
  |  |  |  |  178|  1.24k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 672, False: 577]
  |  |  |  |  ------------------
  |  |  |  |  179|    672|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    672|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    672|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    672|		goto err; \
  |  |  |  |  182|    672|	} \
  |  |  |  |  183|  1.24k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 577]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  117|       |
  118|    577|	if (file && file->size) {
  ------------------
  |  Branch (118:6): [True: 577, False: 0]
  |  Branch (118:14): [True: 34, False: 543]
  ------------------
  119|     34|		gdo_len = file->size;
  120|    543|	} else {
  121|    543|		gdo_len = 64;
  122|    543|	}
  123|    577|	gdo = malloc(gdo_len);
  124|    577|	if (!gdo) {
  ------------------
  |  Branch (124:6): [True: 0, False: 577]
  ------------------
  125|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  126|      0|		goto err;
  127|      0|	}
  128|       |
  129|    577|	r = sc_read_binary(card, 0, gdo, gdo_len, 0);
  130|    577|	LOG_TEST_GOTO_ERR(ctx, r, "Cannot read EF(GDO) file");
  ------------------
  |  |  184|    577|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    577|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    577|	int _ret = (r); \
  |  |  |  |  178|    577|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11, False: 566]
  |  |  |  |  ------------------
  |  |  |  |  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|    577|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 566]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  131|       |
  132|    566|	r = sc_parse_ef_gdo_content(gdo, r, iccsn, iccsn_len, chn, chn_len);
  133|       |
  134|  1.24k|err:
  135|  1.24k|	sc_file_free(file);
  136|  1.24k|	free(gdo);
  137|       |
  138|  1.24k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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|    694|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 694, False: 555]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  139|  1.24k|}
ef-gdo.c:sc_parse_ef_gdo_content:
   33|    566|{
   34|    566|	int r = SC_SUCCESS, iccsn_found = 0, chn_found = 0;
  ------------------
  |  |   28|    566|#define SC_SUCCESS				0
  ------------------
   35|    566|	const unsigned char *p = gdo;
   36|    566|	size_t left = gdo_len;
   37|       |
   38|    566|	if (!gdo)
  ------------------
  |  Branch (38:6): [True: 0, False: 566]
  ------------------
   39|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   40|       |
   41|  1.53k|	while (left >= 2) {
  ------------------
  |  Branch (41:9): [True: 1.02k, False: 508]
  ------------------
   42|  1.02k|		unsigned int cla, tag;
   43|  1.02k|		size_t tag_len;
   44|       |
   45|  1.02k|		r = sc_asn1_read_tag(&p, left, &cla, &tag, &tag_len);
   46|  1.02k|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  1.02k|#define SC_SUCCESS				0
  ------------------
  |  Branch (46:7): [True: 45, False: 981]
  ------------------
   47|     45|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|     45|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (47:8): [True: 34, False: 11]
  ------------------
   48|       |				/* not enough data */
   49|     34|				r = SC_SUCCESS;
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
   50|     34|			}
   51|     45|			break;
   52|     45|		}
   53|    981|		if (p == NULL) {
  ------------------
  |  Branch (53:7): [True: 13, False: 968]
  ------------------
   54|       |			/* done parsing */
   55|     13|			break;
   56|     13|		}
   57|    968|		if (tag_len > (size_t)(gdo + gdo_len - p)) {
  ------------------
  |  Branch (57:7): [True: 0, False: 968]
  ------------------
   58|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
   59|      0|			break;
   60|      0|		}
   61|       |
   62|    968|		if (cla == SC_ASN1_TAG_APPLICATION) {
  ------------------
  |  |  210|    968|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (62:7): [True: 561, False: 407]
  ------------------
   63|    561|			switch (tag) {
  ------------------
  |  Branch (63:12): [True: 329, False: 232]
  ------------------
   64|    295|				case 0x1A:
  ------------------
  |  Branch (64:5): [True: 295, False: 266]
  ------------------
   65|    295|					iccsn_found = 1;
   66|    295|					if (iccsn && iccsn_len) {
  ------------------
  |  Branch (66:10): [True: 295, False: 0]
  |  Branch (66:19): [True: 295, False: 0]
  ------------------
   67|    295|						memcpy(iccsn, p, MIN(tag_len, *iccsn_len));
  ------------------
  |  |   69|    295|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 27, False: 268]
  |  |  ------------------
  ------------------
   68|    295|						*iccsn_len = MIN(tag_len, *iccsn_len);
  ------------------
  |  |   69|    295|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 27, False: 268]
  |  |  ------------------
  ------------------
   69|    295|					}
   70|    295|					break;
   71|     34|				case 0x1F20:
  ------------------
  |  Branch (71:5): [True: 34, False: 527]
  ------------------
   72|     34|					chn_found = 1;
   73|     34|					if (chn && chn_len) {
  ------------------
  |  Branch (73:10): [True: 0, False: 34]
  |  Branch (73:17): [True: 0, False: 0]
  ------------------
   74|      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]
  |  |  ------------------
  ------------------
   75|      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]
  |  |  ------------------
  ------------------
   76|      0|					}
   77|     34|					break;
   78|    561|			}
   79|    561|		}
   80|       |
   81|    968|		p += tag_len;
   82|    968|		left = gdo_len - (p - gdo);
   83|    968|	}
   84|       |
   85|    566|	if (!iccsn_found && iccsn_len)
  ------------------
  |  Branch (85:6): [True: 532, False: 34]
  |  Branch (85:22): [True: 532, False: 0]
  ------------------
   86|    532|		*iccsn_len = 0;
   87|    566|	if (!chn_found && chn_len)
  ------------------
  |  Branch (87:6): [True: 560, False: 6]
  |  Branch (87:20): [True: 0, False: 560]
  ------------------
   88|      0|		*chn_len = 0;
   89|       |
   90|    566|	return r;
   91|    566|}

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|			"Incorrect SM data objects"};
  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;
  ------------------
  |  |  131|  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.87M, False: 2.75M]
  ------------------
  156|  2.87M|		return no_errors;
  157|  2.75M|	error_index = error < 0 ? (unsigned)(-(long long int)error) : (unsigned)error;
  ------------------
  |  Branch (157:16): [True: 2.75M, False: 0]
  ------------------
  158|       |
  159|  2.75M|	if (error_index >= misc_base) {
  ------------------
  |  Branch (159:6): [True: 369, False: 2.75M]
  ------------------
  160|    369|		errors = misc_errors;
  161|    369|		count = DIM(misc_errors);
  ------------------
  |  |   29|    369|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  162|    369|		err_base = misc_base;
  163|  2.75M|	} else if (error_index >= sm_base) {
  ------------------
  |  Branch (163:13): [True: 550, False: 2.75M]
  ------------------
  164|    550|		errors = sm_errors;
  165|    550|		count = DIM(sm_errors);
  ------------------
  |  |   29|    550|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  166|    550|		err_base = sm_base;
  167|  2.75M|	} else if (error_index >= p15i_base) {
  ------------------
  |  Branch (167:13): [True: 1.65k, False: 2.75M]
  ------------------
  168|  1.65k|		errors = p15i_errors;
  169|  1.65k|		count = DIM(p15i_errors);
  ------------------
  |  |   29|  1.65k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  170|  1.65k|		err_base = p15i_base;
  171|  2.75M|	} else if (error_index >= int_base) {
  ------------------
  |  Branch (171:13): [True: 637k, False: 2.11M]
  ------------------
  172|   637k|		errors = int_errors;
  173|   637k|		count = DIM(int_errors);
  ------------------
  |  |   29|   637k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  174|   637k|		err_base = int_base;
  175|  2.11M|	} else if (error_index >= arg_base) {
  ------------------
  |  Branch (175:13): [True: 62.9k, False: 2.05M]
  ------------------
  176|  62.9k|		errors = arg_errors;
  177|  62.9k|		count = DIM(arg_errors);
  ------------------
  |  |   29|  62.9k|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  178|  62.9k|		err_base = arg_base;
  179|  2.05M|	} else if (error_index >= card_base) {
  ------------------
  |  Branch (179:13): [True: 2.05M, False: 2.95k]
  ------------------
  180|  2.05M|		errors = card_errors;
  181|  2.05M|		count = DIM(card_errors);
  ------------------
  |  |   29|  2.05M|#define DIM(v)		(sizeof(v)/(sizeof((v)[0])))
  ------------------
  182|  2.05M|		err_base = card_base;
  183|  2.05M|	} 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.75M|	error_index -= err_base;
  189|  2.75M|	if (error_index >= count)
  ------------------
  |  Branch (189:6): [True: 2.95k, False: 2.75M]
  ------------------
  190|  2.95k|		return misc_errors[0];
  191|  2.75M|	return errors[error_index];
  192|  2.75M|}

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

iasecc_docp_free_fields:
  150|    365|{
  151|    365|	if (!docp)
  ------------------
  |  Branch (151:6): [True: 0, False: 365]
  ------------------
  152|      0|		return;
  153|       |
  154|    365|	free(docp->tries_maximum.value);
  155|    365|	free(docp->tries_remaining.value);
  156|    365|	free(docp->usage_maximum.value);
  157|    365|	free(docp->usage_remaining.value);
  158|    365|	free(docp->non_repudiation.value);
  159|    365|	free(docp->acls_contact.value);
  160|    365|	free(docp->acls_contactless.value);
  161|    365|	free(docp->size.value);
  162|    365|	free(docp->name.value);
  163|    365|	free(docp->issuer_data.value);
  164|    365|	docp->tries_maximum.value = NULL;
  165|    365|	docp->tries_remaining.value = NULL;
  166|    365|	docp->usage_maximum.value = NULL;
  167|    365|	docp->usage_remaining.value = NULL;
  168|    365|	docp->non_repudiation.value = NULL;
  169|    365|	docp->acls_contact.value = NULL;
  170|    365|	docp->acls_contactless.value = NULL;
  171|    365|	docp->size.value = NULL;
  172|    365|	docp->name.value = NULL;
  173|       |	docp->issuer_data.value = NULL;
  174|    365|}
iasecc_sdo_free_fields:
  178|    334|{
  179|    334|	if (sdo == NULL) {
  ------------------
  |  Branch (179:6): [True: 0, False: 334]
  ------------------
  180|      0|		return;
  181|      0|	}
  182|       |
  183|    334|	iasecc_docp_free_fields(&sdo->docp);
  184|       |
  185|    334|	if (sdo->sdo_class == IASECC_SDO_CLASS_RSA_PUBLIC)   {
  ------------------
  |  |  101|    334|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (185:6): [True: 0, False: 334]
  ------------------
  186|      0|		free(sdo->data.pub_key.n.value);
  187|      0|		free(sdo->data.pub_key.e.value);
  188|      0|		free(sdo->data.pub_key.compulsory.value);
  189|      0|		free(sdo->data.pub_key.chr.value);
  190|      0|		free(sdo->data.pub_key.cha.value);
  191|      0|		sdo->data.pub_key.n.value = NULL;
  192|      0|		sdo->data.pub_key.e.value = NULL;
  193|      0|		sdo->data.pub_key.compulsory.value = NULL;
  194|      0|		sdo->data.pub_key.chr.value = NULL;
  195|      0|		sdo->data.pub_key.cha.value = NULL;
  196|      0|	}
  197|    334|	else if (sdo->sdo_class == IASECC_SDO_CLASS_RSA_PRIVATE)   {
  ------------------
  |  |  100|    334|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (197:11): [True: 0, False: 334]
  ------------------
  198|      0|		free(sdo->data.prv_key.p.value);
  199|      0|		free(sdo->data.prv_key.q.value);
  200|      0|		free(sdo->data.prv_key.iqmp.value);
  201|      0|		free(sdo->data.prv_key.dmp1.value);
  202|      0|		free(sdo->data.prv_key.dmq1.value);
  203|      0|		free(sdo->data.prv_key.compulsory.value);
  204|      0|		sdo->data.prv_key.p.value = NULL;
  205|      0|		sdo->data.prv_key.q.value = NULL;
  206|      0|		sdo->data.prv_key.iqmp.value = NULL;
  207|      0|		sdo->data.prv_key.dmp1.value = NULL;
  208|      0|		sdo->data.prv_key.dmq1.value = NULL;
  209|      0|		sdo->data.prv_key.compulsory.value = NULL;
  210|      0|	}
  211|    334|	else if (sdo->sdo_class == IASECC_SDO_CLASS_CHV)   {
  ------------------
  |  |   98|    334|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (211:11): [True: 329, False: 5]
  ------------------
  212|    329|		free(sdo->data.chv.size_max.value);
  213|    329|		free(sdo->data.chv.size_min.value);
  214|    329|		free(sdo->data.chv.value.value);
  215|    329|		sdo->data.chv.size_max.value = NULL;
  216|    329|		sdo->data.chv.size_min.value = NULL;
  217|    329|		sdo->data.chv.value.value = NULL;
  218|    329|	}
  219|      5|	else if (sdo->sdo_class == IASECC_SDO_CLASS_KEYSET)   {
  ------------------
  |  |   99|      5|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (219:11): [True: 0, False: 5]
  ------------------
  220|      0|		free(sdo->data.keyset.mac.value);
  221|      0|		free(sdo->data.keyset.enc.value);
  222|      0|		free(sdo->data.keyset.compulsory.value);
  223|      0|		sdo->data.keyset.mac.value = NULL;
  224|      0|		sdo->data.keyset.enc.value = NULL;
  225|       |		sdo->data.keyset.compulsory.value = NULL;
  226|      0|	}
  227|    334|}
iasecc_se_get_crt:
  294|     36|{
  295|     36|	struct sc_context *ctx = card->ctx;
  296|     36|	int ii;
  297|       |
  298|     36|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     36|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     36|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     36|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     36|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|     36|	if (!se || !crt)
  ------------------
  |  Branch (299:6): [True: 0, False: 36]
  |  Branch (299:13): [True: 0, False: 36]
  ------------------
  300|     36|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|     36|	sc_log(ctx, "CRT search template: %X:%X:%X, refs %X:%X:...",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  302|     36|			crt->tag, crt->algo, crt->usage, crt->refs[0], crt->refs[1]);
  303|       |
  304|    386|	for (ii=0; ii<SC_MAX_CRTS_IN_SE && se->crts[ii].tag; ii++)   {
  ------------------
  |  |   50|    772|#define SC_MAX_CRTS_IN_SE		12
  ------------------
  |  Branch (304:13): [True: 363, False: 23]
  |  Branch (304:37): [True: 350, False: 13]
  ------------------
  305|    350|		if (crt->tag != se->crts[ii].tag)
  ------------------
  |  Branch (305:7): [True: 344, False: 6]
  ------------------
  306|    344|			continue;
  307|      6|		if (crt->algo && crt->algo != se->crts[ii].algo)
  ------------------
  |  Branch (307:7): [True: 0, False: 6]
  |  Branch (307:20): [True: 0, False: 0]
  ------------------
  308|      0|			continue;
  309|      6|		if (crt->usage && crt->usage != se->crts[ii].usage)
  ------------------
  |  Branch (309:7): [True: 6, False: 0]
  |  Branch (309:21): [True: 6, False: 0]
  ------------------
  310|      6|			continue;
  311|      0|		if (crt->refs[0] && crt->refs[0] != se->crts[ii].refs[0])
  ------------------
  |  Branch (311:7): [True: 0, False: 0]
  |  Branch (311:23): [True: 0, False: 0]
  ------------------
  312|      0|			continue;
  313|       |
  314|      0|		memcpy(crt, &se->crts[ii], sizeof(*crt));
  315|       |
  316|      0|		sc_log(ctx, "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__
  |  |  ------------------
  ------------------
  317|      0|				se->crts[ii].refs[0], se->crts[ii].refs[1]);
  318|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|      0|	}
  320|       |
  321|     36|	sc_log(ctx, "CRT is not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  322|     36|	return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|     36|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  323|     36|}
iasecc_se_parse:
  357|    156|{
  358|    156|	struct sc_context *ctx = card->ctx;
  359|    156|	size_t size, offs;
  360|    156|	int size_size;
  361|    156|	int rv;
  362|       |
  363|    156|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    156|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    156|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    156|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    156|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 156]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  364|    156|	sc_log(ctx, "data_len %zu", data_len);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  365|       |
  366|    156|	if (data_len < 1)
  ------------------
  |  Branch (366:6): [True: 10, False: 146]
  ------------------
  367|    156|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  368|       |
  369|    146|	if (*data == IASECC_SDO_TEMPLATE_TAG)   {
  ------------------
  |  |   29|    146|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
  |  Branch (369:6): [True: 30, False: 116]
  ------------------
  370|     30|		size_size = iasecc_parse_size(data + 1, data_len - 1, &size);
  371|     30|		LOG_TEST_RET(ctx, size_size, "parse error: invalid size data of IASECC_SDO_TEMPLATE");
  ------------------
  |  |  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: 3, False: 27]
  |  |  |  |  ------------------
  |  |  |  |  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|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|       |
  373|     27|		if (data_len < size + size_size + 1)
  ------------------
  |  Branch (373:7): [True: 3, False: 24]
  ------------------
  374|     27|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  375|       |
  376|     24|		data += size_size + 1;
  377|     24|		data_len = size;
  378|     24|		sc_log(ctx, "IASECC_SDO_TEMPLATE: size %zu, size_size %d", size, size_size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  379|       |
  380|     24|		if (data_len < 3)
  ------------------
  |  Branch (380:7): [True: 7, False: 17]
  ------------------
  381|     24|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|     17|		if (*data != IASECC_SDO_TAG_HEADER)
  ------------------
  |  |   27|     17|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
  |  Branch (383:7): [True: 8, False: 9]
  ------------------
  384|     17|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  385|       |
  386|      9|		if ((*(data + 1) & 0x7F) != IASECC_SDO_CLASS_SE)
  ------------------
  |  |  102|      9|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (386:7): [True: 5, False: 4]
  ------------------
  387|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  388|       |
  389|      4|		size_size = iasecc_parse_size(data + 3, data_len - 3, &size);
  390|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|       |
  392|      3|		if (data_len != size + size_size + 3)
  ------------------
  |  Branch (392:7): [True: 1, False: 2]
  ------------------
  393|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|       |
  395|      2|		data += 3 + size_size;
  396|      2|		data_len = size;
  397|      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__
  |  |  ------------------
  ------------------
  398|      2|	}
  399|       |
  400|    118|	if (*data != IASECC_SDO_CLASS_SE)   {
  ------------------
  |  |  102|    118|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (400:6): [True: 11, False: 107]
  ------------------
  401|     11|		sc_log(ctx, "Invalid SE tag 0x%X; data length %zu", *data, data_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__
  |  |  ------------------
  ------------------
  402|     11|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  403|     11|	}
  404|       |
  405|    107|	size_size = iasecc_parse_size(data + 1, data_len - 1, &size);
  406|    107|	LOG_TEST_RET(ctx, size_size, "parse error: invalid size data");
  ------------------
  |  |  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: 7, False: 100]
  |  |  |  |  ------------------
  |  |  |  |  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|    107|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 100]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  407|       |
  408|    100|	if (data_len != size + size_size + 1)
  ------------------
  |  Branch (408:6): [True: 13, False: 87]
  ------------------
  409|    100|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: invalid SE data size");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  410|       |
  411|     87|	offs = 1 + size_size;
  412|    881|	for (; offs < data_len;)   {
  ------------------
  |  Branch (412:9): [True: 850, False: 31]
  ------------------
  413|    850|		rv = iasecc_crt_parse(card, data + offs, data_len - offs, se);
  414|    850|		LOG_TEST_RET(ctx, rv, "parse error: invalid SE data");
  ------------------
  |  |  174|    850|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    850|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    850|	int _ret = (r); \
  |  |  |  |  168|    850|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 56, False: 794]
  |  |  |  |  ------------------
  |  |  |  |  169|     56|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     56|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     56|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     56|		return _ret; \
  |  |  |  |  172|     56|	} \
  |  |  |  |  173|    850|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 794]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  415|       |
  416|    794|		offs += rv;
  417|    794|	}
  418|       |
  419|     31|	if (offs != data_len)
  ------------------
  |  Branch (419:6): [True: 0, False: 31]
  ------------------
  420|     31|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  421|       |
  422|     31|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  423|     31|}
iasecc_sdo_parse:
  795|    185|{
  796|    185|	struct sc_context *ctx = card->ctx;
  797|    185|	size_t size, offs;
  798|    185|	int size_size;
  799|    185|	int rv;
  800|       |
  801|    185|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  802|       |
  803|    185|	if (data == NULL || data_len < 2)
  ------------------
  |  Branch (803:6): [True: 0, False: 185]
  |  Branch (803:22): [True: 2, False: 183]
  ------------------
  804|    185|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  805|       |
  806|    183|	if (*data == IASECC_SDO_TEMPLATE_TAG)   {
  ------------------
  |  |   29|    183|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
  |  Branch (806:6): [True: 29, False: 154]
  ------------------
  807|     29|		size_size = iasecc_parse_size(data + 1, data_len - 1, &size);
  808|     29|		LOG_TEST_RET(ctx, size_size, "parse error: invalid size data of IASECC_SDO_TEMPLATE");
  ------------------
  |  |  174|     29|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     29|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     29|	int _ret = (r); \
  |  |  |  |  168|     29|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|     29|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|       |
  810|     26|		if (data_len < (size_t)(size_size + 1)) {
  ------------------
  |  Branch (810:7): [True: 0, False: 26]
  ------------------
  811|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  812|      0|		}
  813|     26|		data += size_size + 1;
  814|     26|		data_len -= (size_size + 1);
  815|     26|		if (size > data_len) {
  ------------------
  |  Branch (815:7): [True: 24, False: 2]
  ------------------
  816|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  817|     24|		}
  818|      2|		data_len = size;
  819|      2|		sc_log(ctx, "IASECC_SDO_TEMPLATE: 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__
  |  |  ------------------
  ------------------
  820|      2|	}
  821|       |
  822|    156|	if (data_len < 4 || *data != IASECC_SDO_TAG_HEADER)
  ------------------
  |  |   27|    154|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
  |  Branch (822:6): [True: 2, False: 154]
  |  Branch (822:22): [True: 3, False: 151]
  ------------------
  823|    156|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  824|       |
  825|    151|	if (sdo->sdo_class != (*(data + 1) & 0x7F))
  ------------------
  |  Branch (825:6): [True: 1, False: 150]
  ------------------
  826|    151|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|       |
  828|    150|	if (sdo->sdo_ref != (*(data + 2) & 0x3F))
  ------------------
  |  Branch (828:6): [True: 1, False: 149]
  ------------------
  829|    150|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  830|       |
  831|    149|	size_size = iasecc_parse_size(data + 3, data_len - 3, &size);
  832|    149|	LOG_TEST_RET(ctx, size_size, "parse error: invalid size data");
  ------------------
  |  |  174|    149|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    149|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    149|	int _ret = (r); \
  |  |  |  |  168|    149|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 147]
  |  |  |  |  ------------------
  |  |  |  |  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|    149|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 147]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  833|       |
  834|    147|	if (data_len != size + size_size + 3)
  ------------------
  |  Branch (834:6): [True: 12, False: 135]
  ------------------
  835|    147|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: invalid SDO data size");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  836|       |
  837|    135|	sc_log(ctx, "sz %zu, sz_size %d", size, size_size);
  ------------------
  |  |   71|    135|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  838|       |
  839|    135|	offs = 3 + size_size;
  840|    333|	for (; offs < data_len;)   {
  ------------------
  |  Branch (840:9): [True: 331, False: 2]
  ------------------
  841|    331|		rv = iasecc_sdo_parse_data(card, data + offs, data_len - offs, sdo);
  842|    331|		if (rv < 0) {
  ------------------
  |  Branch (842:7): [True: 133, False: 198]
  ------------------
  843|    133|			iasecc_sdo_free_fields(card, sdo);
  844|    133|			LOG_TEST_RET(ctx, rv, "parse error: invalid SDO data");
  ------------------
  |  |  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: 133, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    133|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    133|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    133|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    133|		return _ret; \
  |  |  |  |  172|    133|	} \
  |  |  |  |  173|    133|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  845|    133|		}
  846|       |
  847|    198|		offs += rv;
  848|    198|	}
  849|       |
  850|      2|	if (offs != data_len) {
  ------------------
  |  Branch (850:6): [True: 0, False: 2]
  ------------------
  851|      0|		iasecc_sdo_free_fields(card, sdo);
  852|      0|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  853|      0|	}
  854|       |
  855|      2|	sc_log(ctx, "docp.acls_contact.size %zu, docp.size.size %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  856|      2|			sdo->docp.acls_contact.size, sdo->docp.size.size);
  857|       |
  858|      2|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|      2|}
iasecc_docp_copy:
 1384|     36|{
 1385|     36|	int rv;
 1386|       |
 1387|     36|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     36|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     36|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     36|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     36|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1388|     36|	if (!in || !out)
  ------------------
  |  Branch (1388:6): [True: 0, False: 36]
  |  Branch (1388:13): [True: 0, False: 36]
  ------------------
 1389|     36|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1390|       |
 1391|     36|	memset(out, 0, sizeof(struct iasecc_sdo_docp));
 1392|       |
 1393|     36|	rv = iasecc_tlv_copy(ctx, &in->name, &out->name);
 1394|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1395|       |
 1396|     36|	rv = iasecc_tlv_copy(ctx, &in->tries_maximum, &out->tries_maximum);
 1397|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1398|       |
 1399|     36|	rv = iasecc_tlv_copy(ctx, &in->tries_remaining, &out->tries_remaining);
 1400|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1401|       |
 1402|     36|	rv = iasecc_tlv_copy(ctx, &in->usage_maximum, &out->usage_maximum);
 1403|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1404|       |
 1405|     36|	rv = iasecc_tlv_copy(ctx, &in->usage_remaining, &out->usage_remaining);
 1406|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1407|       |
 1408|     36|	rv = iasecc_tlv_copy(ctx, &in->non_repudiation, &out->non_repudiation);
 1409|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1410|       |
 1411|     36|	rv = iasecc_tlv_copy(ctx, &in->size, &out->size);
 1412|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1413|       |
 1414|     36|	rv = iasecc_tlv_copy(ctx, &in->acls_contact, &out->acls_contact);
 1415|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1416|       |
 1417|     36|	rv = iasecc_tlv_copy(ctx, &in->acls_contactless, &out->acls_contactless);
 1418|     36|	LOG_TEST_RET(ctx, rv, "TLV copy error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1419|       |
 1420|     36|	out->amb = in->amb;
 1421|     36|	memcpy(out->scbs, in->scbs, sizeof(out->scbs));
 1422|       |
 1423|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1424|     36|}
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: 11, False: 22]
  ------------------
   55|     33|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   56|       |
   57|     22|	docp->amb = *(acls->value + 0);
   58|     22|	memset(docp->scbs, 0xFF, sizeof(docp->scbs));
   59|    161|	for (ii=0, offs = 1; ii<7; ii++, mask >>= 1)
  ------------------
  |  Branch (59:23): [True: 142, False: 19]
  ------------------
   60|    142|		if (mask & docp->amb) {
  ------------------
  |  Branch (60:7): [True: 45, False: 97]
  ------------------
   61|     45|			if (offs >= acls->size) {
  ------------------
  |  Branch (61:8): [True: 3, False: 42]
  ------------------
   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|     42|			docp->scbs[ii] = *(acls->value + offs++);
   65|     42|		}
   66|       |
   67|     19|	sc_log(ctx, "SCBs %02X:%02X:%02X:%02X:%02X:%02X:%02X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
   68|     19|			docp->scbs[0],docp->scbs[1],docp->scbs[2],docp->scbs[3],
   69|     19|			docp->scbs[4],docp->scbs[5],docp->scbs[6]);
   70|     19|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     19|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     19|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     19|	int _ret = r; \
  |  |  |  |  155|     19|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  157|     19|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     19|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     19|	return _ret; \
  |  |  |  |  163|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   71|     19|}
iasecc-sdo.c:iasecc_crt_parse:
  240|    850|{
  241|    850|	struct sc_context *ctx = card->ctx;
  242|    850|	struct sc_crt crt;
  243|    850|	int ii, offs, len, parsed_len = -1;
  244|       |
  245|    850|	sc_log(ctx, "iasecc_crt_parse(0x%X) called", *data);
  ------------------
  |  |   71|    850|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  246|       |
  247|    850|	if (data_len < 2)
  ------------------
  |  Branch (247:6): [True: 2, False: 848]
  ------------------
  248|    850|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  249|       |
  250|    848|	memset(&crt, 0, sizeof(crt));
  251|    848|	crt.tag = *(data + 0);
  252|    848|	len = *(data + 1);
  253|       |
  254|    968|	for(offs = 2; offs < len + 2; offs += 3)   {
  ------------------
  |  Branch (254:16): [True: 164, False: 804]
  ------------------
  255|    164|		if ((size_t) offs + 2 >= data_len)
  ------------------
  |  Branch (255:7): [True: 13, False: 151]
  ------------------
  256|    164|			LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     13|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     13|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     13|	int _ret = r; \
  |  |  |  |  155|     13|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     13|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     13|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     13|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     13|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|    151|		sc_log(ctx, "iasecc_crt_parse(0x%X) CRT %X -> %X", *data, *(data + offs), *(data + offs + 2));
  ------------------
  |  |   71|    151|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|    151|		if (*(data + offs) == IASECC_CRT_TAG_USAGE)   {
  ------------------
  |  |  111|    151|#define IASECC_CRT_TAG_USAGE		0x95
  ------------------
  |  Branch (258:7): [True: 66, False: 85]
  ------------------
  259|     66|			crt.usage = *(data + offs + 2);
  260|     66|		}
  261|     85|		else if (*(data + offs) == IASECC_CRT_TAG_REFERENCE)   {
  ------------------
  |  |  112|     85|#define IASECC_CRT_TAG_REFERENCE	0x83
  ------------------
  |  Branch (261:12): [True: 51, False: 34]
  ------------------
  262|     51|			int nn_refs = sizeof(crt.refs) / sizeof(crt.refs[0]);
  263|       |
  264|    152|			for (ii=0; ii<nn_refs && crt.refs[ii]; ii++)
  ------------------
  |  Branch (264:15): [True: 151, False: 1]
  |  Branch (264:29): [True: 101, False: 50]
  ------------------
  265|    101|				;
  266|     51|			if (ii == nn_refs)
  ------------------
  |  Branch (266:8): [True: 1, False: 50]
  ------------------
  267|     51|				LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  268|       |
  269|     50|			crt.refs[ii] = *(data + offs + 2);
  270|     50|		}
  271|     34|		else if (*(data + offs) == IASECC_CRT_TAG_ALGO)   {
  ------------------
  |  |  113|     34|#define IASECC_CRT_TAG_ALGO		0x80
  ------------------
  |  Branch (271:12): [True: 4, False: 30]
  ------------------
  272|      4|			crt.algo = *(data + offs + 2);
  273|      4|		}
  274|     30|		else   {
  275|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  276|     30|		}
  277|    151|	}
  278|       |
  279|  3.81k|	for (ii=0; ii<SC_MAX_CRTS_IN_SE; ii++)
  ------------------
  |  |   50|  3.81k|#define SC_MAX_CRTS_IN_SE		12
  ------------------
  |  Branch (279:13): [True: 3.80k, False: 10]
  ------------------
  280|  3.80k|		if (!se->crts[ii].tag)
  ------------------
  |  Branch (280:7): [True: 794, False: 3.01k]
  ------------------
  281|    794|			break;
  282|       |
  283|    804|	if (ii==SC_MAX_CRTS_IN_SE)
  ------------------
  |  |   50|    804|#define SC_MAX_CRTS_IN_SE		12
  ------------------
  |  Branch (283:6): [True: 10, False: 794]
  ------------------
  284|    804|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|    794|	memcpy(&se->crts[ii], &crt, sizeof(crt));
  287|    794|	parsed_len = len + 2;
  288|    794|	LOG_FUNC_RETURN(ctx, parsed_len);
  ------------------
  |  |  164|    794|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    794|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    794|	int _ret = r; \
  |  |  |  |  155|    794|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 794]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    794|	} else { \
  |  |  |  |  159|    794|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    794|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    794|	} \
  |  |  |  |  162|    794|	return _ret; \
  |  |  |  |  163|    794|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  289|    794|}
iasecc-sdo.c:iasecc_parse_size:
  428|  1.13k|{
  429|  1.13k|	if (data_len > 0 && *data < 0x80) {
  ------------------
  |  Branch (429:6): [True: 1.12k, False: 10]
  |  Branch (429:22): [True: 871, False: 250]
  ------------------
  430|    871|		*out = *data;
  431|    871|		return 1;
  432|    871|	}
  433|    260|	else if (data_len > 1 && *data == 0x81) {
  ------------------
  |  Branch (433:11): [True: 246, False: 14]
  |  Branch (433:27): [True: 171, False: 75]
  ------------------
  434|    171|		*out = *(data + 1);
  435|    171|		return 2;
  436|    171|	}
  437|     89|	else if (data_len > 2 && *data == 0x82) {
  ------------------
  |  Branch (437:11): [True: 72, False: 17]
  |  Branch (437:27): [True: 48, False: 24]
  ------------------
  438|     48|		*out = *(data + 1) * 0x100 + *(data + 2);
  439|     48|		return 3;
  440|     48|	}
  441|       |
  442|     41|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     41|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  443|  1.13k|}
iasecc-sdo.c:iasecc_sdo_parse_data:
  707|    331|{
  708|    331|	struct sc_context *ctx = card->ctx;
  709|    331|	struct iasecc_extended_tlv tlv;
  710|    331|	int tlv_size, rv;
  711|       |
  712|    331|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    331|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    331|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    331|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    331|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 331]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  713|    331|	sc_log(ctx, "class %X; ref %X", sdo->sdo_class, sdo->sdo_ref);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  714|       |
  715|    331|	tlv_size = iasecc_parse_get_tlv(card, data, data_len, &tlv);
  716|    331|	LOG_TEST_RET(ctx, tlv_size, "parse error: get TLV");
  ------------------
  |  |  174|    331|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    331|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    331|	int _ret = (r); \
  |  |  |  |  168|    331|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 314]
  |  |  |  |  ------------------
  |  |  |  |  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|    331|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 314]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  717|       |
  718|    314|	sc_log(ctx, "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__
  |  |  ------------------
  ------------------
  719|    314|	if (tlv.tag == IASECC_DOCP_TAG)   {
  ------------------
  |  |   31|    314|#define IASECC_DOCP_TAG				0xA0
  ------------------
  |  Branch (719:6): [True: 67, False: 247]
  ------------------
  720|     67|		sc_log(ctx, "parse IASECC_DOCP_TAG: 0x%X; size %zu",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  721|     67|				tlv.tag, tlv.size);
  722|     67|		rv = iasecc_parse_docp(card, tlv.value, tlv.size, sdo);
  723|     67|		sc_log(ctx, "parsed IASECC_DOCP_TAG rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  724|     67|		free(tlv.value);
  725|     67|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse DOCP");
  ------------------
  |  |  174|     67|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     67|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     67|	int _ret = (r); \
  |  |  |  |  168|     67|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 64, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  726|     67|	}
  727|    247|	else if (tlv.tag == IASECC_DOCP_TAG_NON_REPUDIATION)   {
  ------------------
  |  |   37|    247|#define IASECC_DOCP_TAG_NON_REPUDIATION 		0x9E
  ------------------
  |  Branch (727:11): [True: 79, False: 168]
  ------------------
  728|     79|		free(sdo->docp.non_repudiation.value);
  729|     79|		sdo->docp.non_repudiation = tlv;
  730|     79|	}
  731|    168|	else if (tlv.tag == IASECC_DOCP_TAG_USAGE_REMAINING)   {
  ------------------
  |  |   36|    168|#define IASECC_DOCP_TAG_USAGE_REMAINING		0x9D
  ------------------
  |  Branch (731:11): [True: 23, False: 145]
  ------------------
  732|     23|		free(sdo->docp.usage_remaining.value);
  733|     23|		sdo->docp.usage_remaining = tlv;
  734|     23|	}
  735|    145|	else if (tlv.tag == IASECC_DOCP_TAG_TRIES_MAXIMUM)   {
  ------------------
  |  |   33|    145|#define IASECC_DOCP_TAG_TRIES_MAXIMUM		0x9A
  ------------------
  |  Branch (735:11): [True: 20, False: 125]
  ------------------
  736|     20|		free(sdo->docp.tries_maximum.value);
  737|     20|		sdo->docp.tries_maximum = tlv;
  738|     20|	}
  739|    125|	else if (tlv.tag == IASECC_DOCP_TAG_TRIES_REMAINING)   {
  ------------------
  |  |   34|    125|#define IASECC_DOCP_TAG_TRIES_REMAINING		0x9B
  ------------------
  |  Branch (739:11): [True: 12, False: 113]
  ------------------
  740|     12|		free(sdo->docp.tries_remaining.value);
  741|     12|		sdo->docp.tries_remaining = tlv;
  742|     12|	}
  743|    113|	else if (tlv.tag == IASECC_SDO_CHV_TAG)   {
  ------------------
  |  |   63|    113|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (743:11): [True: 76, False: 37]
  ------------------
  744|     76|		if (sdo->sdo_class != IASECC_SDO_CLASS_CHV) {
  ------------------
  |  |   98|     76|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (744:7): [True: 0, False: 76]
  ------------------
  745|      0|			free(tlv.value);
  746|      0|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: IASECC_SDO_CHV_TAG tag in non User CHV SDO");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  747|      0|		}
  748|       |
  749|     76|		rv = iasecc_parse_chv(card, tlv.value, tlv.size, &sdo->data.chv);
  750|     76|		free(tlv.value);
  751|     76|		LOG_TEST_RET(ctx, rv, "parse error: cannot parse SDO CHV data");
  ------------------
  |  |  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: 15, False: 61]
  |  |  |  |  ------------------
  |  |  |  |  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|     76|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|     76|	}
  753|     37|	else if (tlv.tag == IASECC_SDO_PUBKEY_TAG)   {
  ------------------
  |  |   76|     37|#define IASECC_SDO_PUBKEY_TAG			0x7F49
  ------------------
  |  Branch (753:11): [True: 1, False: 36]
  ------------------
  754|      1|		if (sdo->sdo_class != IASECC_SDO_CLASS_RSA_PUBLIC) {
  ------------------
  |  |  101|      1|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (754:7): [True: 1, False: 0]
  ------------------
  755|      1|			free(tlv.value);
  756|      1|			LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "parse error: SDO_PUBLIC_KEY tag in non PUBLIC_KEY SDO");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  757|      1|		}
  758|       |
  759|      0|		rv = iasecc_parse_pubkey(card, tlv.value, tlv.size, &sdo->data.pub_key);
  760|      0|		free(tlv.value);
  761|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  762|      0|	}
  763|     36|	else if (tlv.tag == IASECC_SDO_PRVKEY_TAG)   {
  ------------------
  |  |   68|     36|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (763:11): [True: 1, False: 35]
  ------------------
  764|      1|		if (sdo->sdo_class != IASECC_SDO_CLASS_RSA_PRIVATE) {
  ------------------
  |  |  100|      1|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (764:7): [True: 1, False: 0]
  ------------------
  765|      1|			free(tlv.value);
  766|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  767|      1|		}
  768|       |
  769|      0|		rv = iasecc_parse_prvkey(card, tlv.value, tlv.size, &sdo->data.prv_key);
  770|      0|		free(tlv.value);
  771|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  772|      0|	}
  773|     35|	else if (tlv.tag == IASECC_SDO_KEYSET_TAG)   {
  ------------------
  |  |   83|     35|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
  |  Branch (773:11): [True: 1, False: 34]
  ------------------
  774|      1|		if (sdo->sdo_class != IASECC_SDO_CLASS_KEYSET) {
  ------------------
  |  |   99|      1|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (774:7): [True: 1, False: 0]
  ------------------
  775|      1|			free(tlv.value);
  776|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  777|      1|		}
  778|       |
  779|      0|		rv = iasecc_parse_keyset(card, tlv.value, tlv.size, &sdo->data.keyset);
  780|      0|		free(tlv.value);
  781|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  782|      0|	}
  783|     34|	else   {
  784|     34|		sc_log(ctx, "non supported tag 0x%X", tlv.tag);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  785|     34|		free(tlv.value);
  786|     34|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|     34|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     34|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     34|	int _ret = r; \
  |  |  |  |  155|     34|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     34|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     34|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     34|	return _ret; \
  |  |  |  |  163|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  787|     34|	}
  788|       |
  789|    198|	return tlv_size;
  790|    314|}
iasecc-sdo.c:iasecc_parse_get_tlv:
  448|    813|{
  449|    813|	struct sc_context *ctx = card->ctx;
  450|    813|	int size_len, tag_len;
  451|       |
  452|    813|	memset(tlv, 0, sizeof(*tlv));
  453|    813|	sc_log(ctx, "called for tag 0x%X", *data);
  ------------------
  |  |   71|    813|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  454|    813|	if (data_len < 1)
  ------------------
  |  Branch (454:6): [True: 0, False: 813]
  ------------------
  455|    813|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  456|    813|	if ((*data == 0x7F) || (*data == 0x5F))   {
  ------------------
  |  Branch (456:6): [True: 112, False: 701]
  |  Branch (456:25): [True: 4, False: 697]
  ------------------
  457|    116|		if (data_len < 2)
  ------------------
  |  Branch (457:7): [True: 1, False: 115]
  ------------------
  458|    116|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  459|    115|		tlv->tag = *data * 0x100 + *(data + 1);
  460|    115|		tag_len = 2;
  461|    115|	}
  462|    697|	else   {
  463|    697|		tlv->tag = *data;
  464|    697|		tag_len = 1;
  465|    697|	}
  466|       |
  467|    812|	sc_log(ctx, "tlv->tag 0x%X", tlv->tag);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  468|    812|	size_len = iasecc_parse_size(data + tag_len, data_len - tag_len, &tlv->size);
  469|    812|	LOG_TEST_RET(ctx, size_len, "parse error: invalid size data");
  ------------------
  |  |  174|    812|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    812|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    812|	int _ret = (r); \
  |  |  |  |  168|    812|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 25, False: 787]
  |  |  |  |  ------------------
  |  |  |  |  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|    812|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 787]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  470|    787|	if (tag_len + size_len + tlv->size > data_len) {
  ------------------
  |  Branch (470:6): [True: 14, False: 773]
  ------------------
  471|     14|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|     14|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     14|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     14|	int _ret = r; \
  |  |  |  |  155|     14|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     14|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     14|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 14, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     14|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     14|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     14|	return _ret; \
  |  |  |  |  163|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  472|     14|	}
  473|       |
  474|    773|	tlv->value = calloc(1, tlv->size);
  475|    773|	if (!tlv->value)
  ------------------
  |  Branch (475:6): [True: 0, False: 773]
  ------------------
  476|    773|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  477|    773|	memcpy(tlv->value, data + size_len + tag_len, tlv->size);
  478|       |
  479|    773|	tlv->on_card = 1;
  480|       |
  481|    773|	sc_log(ctx, "parsed %zu bytes", tag_len + size_len + tlv->size);
  ------------------
  |  |   71|    773|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  482|    773|	return (int)(tag_len + size_len + tlv->size);
  483|    773|}
iasecc-sdo.c:iasecc_parse_docp:
  634|     90|{
  635|     90|	struct sc_context *ctx = card->ctx;
  636|     90|	size_t offs = 0;
  637|     90|	int rv;
  638|       |
  639|     90|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     90|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     90|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     90|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     90|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 90]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|    233|	while(offs < data_len)   {
  ------------------
  |  Branch (640:8): [True: 200, False: 33]
  ------------------
  641|    200|		struct iasecc_extended_tlv tlv;
  642|       |
  643|    200|		rv = iasecc_parse_get_tlv(card, data + offs, data_len - offs, &tlv);
  644|    200|		LOG_TEST_RET(ctx, rv, "get and parse TLV 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: 20, False: 180]
  |  |  |  |  ------------------
  |  |  |  |  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|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 180]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  645|       |
  646|    180|		sc_log(ctx, "parse_get_tlv returned %i; tag %X; size %zu",
  ------------------
  |  |   71|    180|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  647|    180|				rv, tlv.tag, tlv.size);
  648|       |
  649|    180|		if (tlv.tag == IASECC_DOCP_TAG_ACLS)   {
  ------------------
  |  |   39|    180|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
  |  Branch (649:7): [True: 23, False: 157]
  ------------------
  650|     23|			int _rv = iasecc_parse_docp(card, tlv.value, tlv.size, sdo);
  651|     23|			free(tlv.value);
  652|     23|			LOG_TEST_RET(ctx, _rv, "parse error: cannot parse DOCP");
  ------------------
  |  |  174|     23|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     23|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     23|	int _ret = (r); \
  |  |  |  |  168|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  653|     23|		}
  654|    157|		else if (tlv.tag == IASECC_DOCP_TAG_ACLS_CONTACT)   {
  ------------------
  |  |   40|    157|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
  |  Branch (654:12): [True: 18, False: 139]
  ------------------
  655|     18|			free(sdo->docp.acls_contact.value);
  656|     18|			sdo->docp.acls_contact = tlv;
  657|     18|		}
  658|    139|		else if (tlv.tag == IASECC_DOCP_TAG_ACLS_CONTACTLESS)   {
  ------------------
  |  |   41|    139|#define IASECC_DOCP_TAG_ACLS_CONTACTLESS	0x9C
  ------------------
  |  Branch (658:12): [True: 16, False: 123]
  ------------------
  659|     16|			free(sdo->docp.acls_contactless.value);
  660|     16|			sdo->docp.acls_contactless = tlv;
  661|     16|		}
  662|    123|		else if (tlv.tag == IASECC_DOCP_TAG_SIZE)   {
  ------------------
  |  |   38|    123|#define IASECC_DOCP_TAG_SIZE			0x80
  ------------------
  |  Branch (662:12): [True: 10, False: 113]
  ------------------
  663|     10|			free(sdo->docp.size.value);
  664|     10|			sdo->docp.size = tlv;
  665|     10|		}
  666|    113|		else if (tlv.tag == IASECC_DOCP_TAG_NAME)   {
  ------------------
  |  |   32|    113|#define IASECC_DOCP_TAG_NAME			0x84
  ------------------
  |  Branch (666:12): [True: 16, False: 97]
  ------------------
  667|     16|			free(sdo->docp.name.value);
  668|     16|			sdo->docp.name = tlv;
  669|     16|		}
  670|     97|		else if (tlv.tag == IASECC_DOCP_TAG_ISSUER_DATA)   {
  ------------------
  |  |   43|     97|#define IASECC_DOCP_TAG_ISSUER_DATA		0x85
  ------------------
  |  Branch (670:12): [True: 20, False: 77]
  ------------------
  671|     20|			free(sdo->docp.issuer_data.value);
  672|     20|			sdo->docp.issuer_data = tlv;
  673|     20|		}
  674|     77|		else if (tlv.tag == IASECC_DOCP_TAG_NON_REPUDIATION)   {
  ------------------
  |  |   37|     77|#define IASECC_DOCP_TAG_NON_REPUDIATION 		0x9E
  ------------------
  |  Branch (674:12): [True: 10, False: 67]
  ------------------
  675|     10|			free(sdo->docp.non_repudiation.value);
  676|     10|			sdo->docp.non_repudiation = tlv;
  677|     10|		}
  678|     67|		else if (tlv.tag == IASECC_DOCP_TAG_USAGE_REMAINING)   {
  ------------------
  |  |   36|     67|#define IASECC_DOCP_TAG_USAGE_REMAINING		0x9D
  ------------------
  |  Branch (678:12): [True: 10, False: 57]
  ------------------
  679|     10|			free(sdo->docp.usage_remaining.value);
  680|     10|			sdo->docp.usage_remaining = tlv;
  681|     10|		}
  682|     57|		else if (tlv.tag == IASECC_DOCP_TAG_TRIES_MAXIMUM)   {
  ------------------
  |  |   33|     57|#define IASECC_DOCP_TAG_TRIES_MAXIMUM		0x9A
  ------------------
  |  Branch (682:12): [True: 8, False: 49]
  ------------------
  683|      8|			free(sdo->docp.tries_maximum.value);
  684|      8|			sdo->docp.tries_maximum = tlv;
  685|      8|		}
  686|     49|		else if (tlv.tag == IASECC_DOCP_TAG_TRIES_REMAINING)   {
  ------------------
  |  |   34|     49|#define IASECC_DOCP_TAG_TRIES_REMAINING		0x9B
  ------------------
  |  Branch (686:12): [True: 19, False: 30]
  ------------------
  687|     19|			free(sdo->docp.tries_remaining.value);
  688|     19|			sdo->docp.tries_remaining = tlv;
  689|     19|		}
  690|     30|		else   {
  691|     30|			free(tlv.value);
  692|     30|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  693|     30|		}
  694|       |
  695|    143|		offs += rv;
  696|    143|	}
  697|       |
  698|     33|	rv = iasecc_parse_acls(card, &sdo->docp, 0);
  699|     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: 14, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  700|       |
  701|     19|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     19|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     19|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     19|	int _ret = r; \
  |  |  |  |  155|     19|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 19, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     19|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  157|     19|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     19|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     19|	return _ret; \
  |  |  |  |  163|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  702|     19|}
iasecc-sdo.c:iasecc_parse_chv:
  488|     76|{
  489|     76|	struct sc_context *ctx = card->ctx;
  490|     76|	size_t offs = 0;
  491|     76|	int rv;
  492|       |
  493|     76|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     76|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     76|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     76|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     76|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 76]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  494|    343|	while(offs < data_len)   {
  ------------------
  |  Branch (494:8): [True: 282, False: 61]
  ------------------
  495|    282|		struct iasecc_extended_tlv tlv;
  496|       |
  497|    282|		rv = iasecc_parse_get_tlv(card, data + offs, data_len - offs, &tlv);
  498|    282|		LOG_TEST_RET(ctx, rv, "get and parse TLV error");
  ------------------
  |  |  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: 3, False: 279]
  |  |  |  |  ------------------
  |  |  |  |  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|    282|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 279]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  499|       |
  500|    279|		sc_log(ctx, "get and parse TLV returned %i; tag %X; size %zu",
  ------------------
  |  |   71|    279|#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|    279|				rv, tlv.tag, tlv.size);
  502|       |
  503|    279|		if (tlv.tag == IASECC_SDO_CHV_TAG_SIZE_MAX) {
  ------------------
  |  |   64|    279|#define IASECC_SDO_CHV_TAG_SIZE_MAX	0x80
  ------------------
  |  Branch (503:7): [True: 42, False: 237]
  ------------------
  504|     42|			free(chv->size_max.value);
  505|     42|			chv->size_max = tlv;
  506|    237|		} else if (tlv.tag == IASECC_SDO_CHV_TAG_SIZE_MIN) {
  ------------------
  |  |   65|    237|#define IASECC_SDO_CHV_TAG_SIZE_MIN	0x81
  ------------------
  |  Branch (506:14): [True: 116, False: 121]
  ------------------
  507|    116|			free(chv->size_min.value);
  508|    116|			chv->size_min = tlv;
  509|    121|		} else if (tlv.tag == IASECC_SDO_CHV_TAG_VALUE) {
  ------------------
  |  |   66|    121|#define IASECC_SDO_CHV_TAG_VALUE	0x82
  ------------------
  |  Branch (509:14): [True: 109, False: 12]
  ------------------
  510|    109|			free(chv->value.value);
  511|    109|			chv->value = tlv;
  512|    109|		} else {
  513|     12|			free(tlv.value);
  514|     12|			LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "parse error: non CHV SDO tag");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|     12|		}
  516|       |
  517|    267|		offs += rv;
  518|    267|	}
  519|       |
  520|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  521|     61|}
iasecc-sdo.c:iasecc_tlv_copy:
 1361|    324|{
 1362|    324|	if (!in || !out)
  ------------------
  |  Branch (1362:6): [True: 0, False: 324]
  |  Branch (1362:13): [True: 0, False: 324]
  ------------------
 1363|    324|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1364|       |
 1365|    324|	memset(out, 0, sizeof(struct iasecc_extended_tlv));
 1366|    324|	out->tag = in->tag;
 1367|    324|	out->parent_tag = in->parent_tag;
 1368|    324|	out->on_card = in->on_card;
 1369|    324|	if (in->value && in->size)   {
  ------------------
  |  Branch (1369:6): [True: 0, False: 324]
  |  Branch (1369:19): [True: 0, False: 0]
  ------------------
 1370|      0|		out->value = calloc(1, in->size);
 1371|      0|		if (!out->value)
  ------------------
  |  Branch (1371:7): [True: 0, False: 0]
  ------------------
 1372|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1373|       |
 1374|      0|		memcpy(out->value, in->value, in->size);
 1375|      0|		out->size = in->size;
 1376|      0|	}
 1377|       |
 1378|    324|	return SC_SUCCESS;
  ------------------
  |  |   28|    324|#define SC_SUCCESS				0
  ------------------
 1379|    324|}

iasecc_sm_initialize:
  270|    207|{
  271|    207|	struct sc_context *ctx = card->ctx;
  272|    207|#ifdef ENABLE_SM
  273|    207|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    207|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    207|	struct sc_remote_data rdata;
  276|    207|	int rv;
  277|       |
  278|    207|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    207|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    207|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    207|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    207|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    207|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    207|#define strlcpy _strlcpy
  ------------------
  281|    207|	sm_info->cmd = cmd;
  282|    207|	sm_info->serialnr = card->serialnr;
  283|    207|	sm_info->card_type = card->type;
  284|    207|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    207|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    207|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    207|	LOG_TEST_RET(ctx, rv, "MUTUAL AUTHENTICATION 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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, "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, "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, "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, "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;
  ------------------
  |  |  387|      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, "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, "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|    207|{
  587|    207|	struct sc_context *ctx = card->ctx;
  588|    207|#ifdef ENABLE_SM
  589|    207|	struct sm_info *sm_info = &card->sm_ctx.info;
  590|    207|	struct sc_remote_data rdata;
  591|    207|	struct iasecc_sm_cmd_update_binary cmd_data;
  592|    207|	int rv;
  593|       |
  594|    207|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    207|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    207|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    207|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    207|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 207]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  595|    207|	sc_log(ctx, "SM read binary: acl:%X, offs:%zu, count:%zu", se_num, offs, count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  596|       |
  597|    207|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    207|#define SM_CMD_FILE_READ		0x201
  ------------------
  598|    207|	LOG_TEST_RET(ctx, rv, "SM INITIALIZE 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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, "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, "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, "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|    207|{
  223|    207|	struct sc_context *ctx = card->ctx;
  224|    207|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    207|	struct iasecc_se_info se;
  226|    207|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    207|	struct sc_apdu apdu;
  228|    207|	unsigned char sbuf[0x100];
  229|    207|	int rv, offs;
  230|       |
  231|    207|	memset(&se, 0, sizeof(se));
  232|       |
  233|    207|	se.reference = se_num;
  234|    207|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    207|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    207|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    207|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    207|	rv = iasecc_se_get_info(card, &se);
  238|    207|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  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: 171, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  169|    171|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    171|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    171|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    171|		return _ret; \
  |  |  |  |  172|    171|	} \
  |  |  |  |  173|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  239|       |
  240|     36|	rv = iasecc_se_get_crt(card, &se, crt);
  241|     36|	sc_file_free(se.df);
  242|     36|	LOG_TEST_RET(ctx, rv, "Cannot get authentication CRT");
  ------------------
  |  |  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: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     36|} 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|  52.0k|{
   36|  52.0k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (36:6): [True: 0, False: 52.0k]
  |  Branch (36:22): [True: 0, False: 52.0k]
  ------------------
   37|      0|		return;
   38|      0|	}
   39|       |
   40|  52.0k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (40:6): [True: 813, False: 51.2k]
  ------------------
   41|       |		/* The lower layers will automatically do chaining */
   42|    813|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    813|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   43|    813|	}
   44|       |
   45|  52.0k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (45:6): [True: 2.77k, False: 49.2k]
  ------------------
   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.77k|		apdu->le = sc_get_max_recv_size(card);
   49|  2.77k|	}
   50|  52.0k|}
encode_do_data:
  176|  15.5k|{
  177|  15.5k|	unsigned char offset_buffer[2];
  178|  15.5k|	size_t offset_buffer_len = sizeof offset_buffer;
  179|  15.5k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  180|  15.5k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  181|       |
  182|  15.5k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (182:6): [True: 0, False: 15.5k]
  ------------------
  183|  15.5k|		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.5k|	offset_buffer[0] = (u8) (idx >> 8);
  185|  15.5k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  186|  15.5k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  187|       |
  188|  15.5k|	if (data && data_len) {
  ------------------
  |  Branch (188:6): [True: 0, False: 15.5k]
  |  Branch (188:14): [True: 0, False: 0]
  ------------------
  189|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  190|  15.5k|	} else {
  191|  15.5k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  192|  15.5k|	}
  193|       |
  194|  15.5k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  15.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  15.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  15.5k|	int _ret = (r); \
  |  |  |  |  168|  15.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 15.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|  15.5k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  196|  15.5k|			"sc_asn1_encode() failed");
  197|       |
  198|  15.5k|	return SC_SUCCESS;
  ------------------
  |  |   28|  15.5k|#define SC_SUCCESS				0
  ------------------
  199|  15.5k|}
decode_do_data:
  204|  13.5k|{
  205|  13.5k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  206|  13.5k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  207|       |
  208|  13.5k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  209|  13.5k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  210|       |
  211|  13.5k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  13.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.5k|	int _ret = (r); \
  |  |  |  |  168|  13.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.42k, False: 12.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.42k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.42k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.42k|		return _ret; \
  |  |  |  |  172|  1.42k|	} \
  |  |  |  |  173|  13.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  212|  12.1k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  213|  12.1k|			"sc_asn1_decode() failed");
  214|       |
  215|  12.1k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  171|  12.1k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (215:6): [True: 10.2k, False: 1.94k]
  ------------------
  216|  10.2k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  10.2k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  217|       |
  218|  1.94k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.94k|#define SC_SUCCESS				0
  ------------------
  219|  12.1k|}
iso7816_build_pin_apdu:
 1200|  8.50k|{
 1201|  8.50k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1202|  8.50k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  8.50k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1203|       |
 1204|  8.50k|	switch (data->pin_type) {
 1205|  8.50k|	case SC_AC_CHV:
  ------------------
  |  |  151|  8.50k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1205:2): [True: 8.50k, False: 0]
  ------------------
 1206|       |		/* fall through */
 1207|  8.50k|	case SC_AC_SESSION:
  ------------------
  |  |  159|  8.50k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1207:2): [True: 0, False: 8.50k]
  ------------------
 1208|  8.50k|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|  8.50k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1208:2): [True: 0, False: 8.50k]
  ------------------
 1209|  8.50k|		break;
 1210|      0|	default:
  ------------------
  |  Branch (1210:2): [True: 0, False: 8.50k]
  ------------------
 1211|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1212|  8.50k|	}
 1213|       |
 1214|  8.50k|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  422|  8.50k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1214:6): [True: 1.35k, False: 7.15k]
  ------------------
 1215|  1.35k|		pad = 1;
 1216|  8.50k|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  421|  8.50k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1216:6): [True: 0, False: 8.50k]
  ------------------
 1217|      0|		use_pin_pad = 1;
 1218|       |
 1219|  8.50k|	data->pin1.offset = 5;
 1220|       |
 1221|  8.50k|	switch (data->cmd) {
 1222|  1.02k|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|  1.02k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1222:2): [True: 1.02k, False: 7.48k]
  ------------------
 1223|  1.02k|		ins = 0x20;
 1224|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1225|  1.02k|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1225:7): [True: 0, False: 1.02k]
  |  Branch (1225:30): [True: 0, False: 0]
  ------------------
 1226|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1227|  1.02k|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1227:7): [True: 20, False: 1.00k]
  ------------------
 1228|     20|			return r;
 1229|  1.00k|		len = r;
 1230|  1.00k|		break;
 1231|    275|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|    275|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1231:2): [True: 275, False: 8.23k]
  ------------------
 1232|    275|		ins = 0x24;
 1233|    275|		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 (1233:7): [True: 267, False: 8]
  |  Branch (1233:31): [True: 0, False: 8]
  |  Branch (1233:46): [True: 0, False: 0]
  ------------------
 1234|    267|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1234:8): [True: 10, False: 257]
  ------------------
 1235|     10|				return r;
 1236|    257|			len += r;
 1237|    257|		}
 1238|      8|		else {
 1239|       |			/* implicit test */
 1240|      8|			p1 = 1;
 1241|      8|		}
 1242|       |
 1243|    265|		data->pin2.offset = data->pin1.offset + len;
 1244|    265|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1244:7): [True: 15, False: 250]
  ------------------
 1245|     15|			return r;
 1246|       |		/* Special case - where provided the old PIN on the command line
 1247|       |		 * but expect the new one to be entered on the keypad.
 1248|       |		 */
 1249|    250|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1249:7): [True: 242, False: 8]
  |  Branch (1249:25): [True: 0, False: 242]
  ------------------
 1250|      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__
  |  |  ------------------
  ------------------
 1251|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1252|      0|		};
 1253|    250|		len += r;
 1254|    250|		break;
 1255|    296|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|    296|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1255:2): [True: 296, False: 8.21k]
  ------------------
 1256|    296|		ins = 0x2C;
 1257|    296|		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 (1257:7): [True: 286, False: 10]
  |  Branch (1257:31): [True: 0, False: 10]
  |  Branch (1257:46): [True: 0, False: 0]
  ------------------
 1258|    286|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1258:8): [True: 6, False: 280]
  ------------------
 1259|      6|				return r;
 1260|    280|			len += r;
 1261|    280|		} else {
 1262|     10|			p1 |= 0x02;
 1263|     10|		}
 1264|       |
 1265|    290|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1265:7): [True: 290, False: 0]
  |  Branch (1265:30): [True: 0, False: 0]
  ------------------
 1266|    290|			data->pin2.offset = data->pin1.offset + len;
 1267|    290|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1267:8): [True: 11, False: 279]
  ------------------
 1268|     11|				return r;
 1269|    279|			len += r;
 1270|    279|		} else {
 1271|      0|			p1 |= 0x01;
 1272|      0|		}
 1273|    279|		if (p1 == 0x03) {
  ------------------
  |  Branch (1273:7): [True: 0, False: 279]
  ------------------
 1274|       |			/* No data to send or to receive */
 1275|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1276|      0|		}
 1277|    279|		break;
 1278|  6.91k|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  418|  6.91k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1278:2): [True: 6.91k, False: 1.59k]
  ------------------
 1279|  6.91k|		ins = 0x20;
 1280|       |		/* No data to send or to receive */
 1281|  6.91k|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|  6.91k|#define SC_APDU_CASE_1			0x01
  ------------------
 1282|  6.91k|		break;
 1283|      0|	default:
  ------------------
  |  Branch (1283:2): [True: 0, False: 8.50k]
  ------------------
 1284|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1285|  8.50k|	}
 1286|       |
 1287|  8.44k|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1288|  8.44k|	apdu->lc = len;
 1289|  8.44k|	apdu->datalen = len;
 1290|  8.44k|	apdu->data = buf;
 1291|  8.44k|	apdu->resplen = 0;
 1292|       |
 1293|  8.44k|	return 0;
 1294|  8.50k|}
iso7816_select_aid:
 1412|  26.4k|{
 1413|  26.4k|	struct sc_context *ctx = card->ctx;
 1414|  26.4k|	struct sc_apdu apdu;
 1415|  26.4k|	int rv;
 1416|       |
 1417|  26.4k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  26.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  26.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  26.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 26.4k]
  |  |  ------------------
  ------------------
 1418|       |
 1419|  26.4k|	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  293|  11.3k|#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.0k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1419:30): [True: 11.3k, False: 15.0k]
  |  Branch (1419:102): [True: 11.3k, False: 15.0k]
  ------------------
 1420|  26.4k|	apdu.lc = reqlen;
 1421|  26.4k|	apdu.data = req;
 1422|  26.4k|	apdu.datalen = reqlen;
 1423|  26.4k|	apdu.resp = resp;
 1424|  26.4k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1424:17): [True: 11.3k, False: 15.0k]
  ------------------
 1425|  26.4k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1425:12): [True: 11.3k, False: 15.0k]
  ------------------
 1426|       |
 1427|  26.4k|	rv = sc_transmit_apdu(card, &apdu);
 1428|  26.4k|	if (resplen)
  ------------------
  |  Branch (1428:6): [True: 15.0k, False: 11.3k]
  ------------------
 1429|  15.0k|		*resplen = apdu.resplen;
 1430|  26.4k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  26.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  26.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  26.4k|	int _ret = (r); \
  |  |  |  |  168|  26.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 217, False: 26.2k]
  |  |  |  |  ------------------
  |  |  |  |  169|    217|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    217|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    217|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    217|		return _ret; \
  |  |  |  |  172|    217|	} \
  |  |  |  |  173|  26.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1431|       |
 1432|  26.2k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1433|  26.2k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  26.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  26.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  26.2k|	int _ret = r; \
  |  |  |  |  155|  26.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|  20.7k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20.7k, False: 5.49k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  26.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|  26.2k|	return _ret; \
  |  |  |  |  163|  26.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1434|  26.2k|}
sc_get_iso7816_driver:
 1502|   626k|{
 1503|   626k|	return &iso_driver;
 1504|   626k|}
iso7816.c:no_match:
 1448|  7.78k|{
 1449|  7.78k|	return 0;
 1450|  7.78k|}
iso7816.c:iso7816_read_record:
  224|  32.3k|{
  225|  32.3k|	struct sc_apdu apdu;
  226|  32.3k|	int r;
  227|       |	/* XXX maybe use some bigger buffer */
  228|  32.3k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  229|  32.3k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  230|  32.3k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  231|       |
  232|       |	/* Record number/identifier 255 is reserved by ISO 7816-4. */
  233|  32.3k|	if (rec_nr >= 0xFF)
  ------------------
  |  Branch (233:6): [True: 27, False: 32.3k]
  ------------------
  234|  32.3k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  32.3k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 16.7k, False: 15.5k]
  ------------------
  237|  16.7k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  16.7k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  16.7k|		apdu.le = count;
  239|  16.7k|		apdu.resplen = count;
  240|  16.7k|		apdu.resp = buf;
  241|  16.7k|	} else {
  242|  15.5k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  15.5k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  15.5k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  15.5k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  15.5k|	int _ret = (r); \
  |  |  |  |  178|  15.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 15.5k]
  |  |  |  |  ------------------
  |  |  |  |  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.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 15.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  15.5k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  15.5k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  15.5k|		apdu.lc = encoded_data_len;
  247|  15.5k|		apdu.datalen = encoded_data_len;
  248|  15.5k|		apdu.data = encoded_data;
  249|  15.5k|		apdu.le = sizeof resp;
  250|  15.5k|		apdu.resplen = sizeof resp;
  251|  15.5k|		apdu.resp = resp;
  252|  15.5k|	}
  253|  32.3k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1293|  32.3k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  32.3k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1298|  32.3k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 32.3k, False: 0]
  ------------------
  255|  32.3k|		apdu.p2 |= 0x04;
  256|       |
  257|  32.3k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  32.3k|	r = sc_transmit_apdu(card, &apdu);
  259|  32.3k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  32.3k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  32.3k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  32.3k|	int _ret = (r); \
  |  |  |  |  178|  32.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 751, False: 31.5k]
  |  |  |  |  ------------------
  |  |  |  |  179|    751|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    751|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    751|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    751|		goto err; \
  |  |  |  |  182|    751|	} \
  |  |  |  |  183|  32.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 31.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  31.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  31.5k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  31.5k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  31.5k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  31.5k|	int _ret = (r); \
  |  |  |  |  178|  31.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2.74k, False: 28.8k]
  |  |  |  |  ------------------
  |  |  |  |  179|  2.74k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.74k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  2.74k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  2.74k|		goto err; \
  |  |  |  |  182|  2.74k|	} \
  |  |  |  |  183|  31.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 28.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  28.8k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 15.2k, False: 13.5k]
  ------------------
  264|  15.2k|		r = (int)apdu.resplen;
  265|  15.2k|	} else {
  266|  13.5k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  13.5k|				&decoded_data, &decoded_data_len);
  268|  13.5k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  13.5k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.5k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.5k|	int _ret = (r); \
  |  |  |  |  178|  13.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 11.6k, False: 1.94k]
  |  |  |  |  ------------------
  |  |  |  |  179|  11.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|  11.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  11.6k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  11.6k|		goto err; \
  |  |  |  |  182|  11.6k|	} \
  |  |  |  |  183|  13.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.94k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  1.94k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 1.56k, False: 385]
  ------------------
  270|  1.56k|			count = decoded_data_len;
  271|  1.56k|		}
  272|  1.94k|		memcpy(buf, decoded_data, count);
  273|  1.94k|		r = (int)count;
  274|  1.94k|	}
  275|       |
  276|  32.3k|err:
  277|  32.3k|	free(encoded_data);
  278|  32.3k|	free(decoded_data);
  279|  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: 16.7k, False: 15.6k]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.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|  15.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.1k, False: 1.60k]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.7k|	} else { \
  |  |  |  |  159|  15.6k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  15.6k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  15.6k|	} \
  |  |  |  |  162|  32.3k|	return _ret; \
  |  |  |  |  163|  32.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  32.3k|}
iso7816.c:iso7816_select_file:
  646|  50.4k|{
  647|  50.4k|	struct sc_context *ctx;
  648|  50.4k|	struct sc_apdu apdu;
  649|  50.4k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  650|  50.4k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  651|  50.4k|	int r, pathtype;
  652|  50.4k|	size_t pathlen;
  653|  50.4k|	int select_mf = 0;
  654|  50.4k|	struct sc_file *file = NULL;
  655|  50.4k|	const u8 *buffer;
  656|  50.4k|	size_t buffer_len;
  657|  50.4k|	unsigned int cla, tag;
  658|       |
  659|  50.4k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (659:6): [True: 0, False: 50.4k]
  |  Branch (659:22): [True: 0, False: 50.4k]
  ------------------
  660|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  661|      0|	}
  662|  50.4k|	ctx = card->ctx;
  663|  50.4k|	memcpy(path, in_path->value, in_path->len);
  664|  50.4k|	pathlen = in_path->len;
  665|  50.4k|	pathtype = in_path->type;
  666|       |
  667|  50.4k|	if (in_path->aid.len) {
  ------------------
  |  Branch (667:6): [True: 1.74k, False: 48.7k]
  ------------------
  668|  1.74k|		if (!pathlen) {
  ------------------
  |  Branch (668:7): [True: 1.27k, False: 472]
  ------------------
  669|  1.27k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  670|  1.27k|			pathlen = in_path->aid.len;
  671|  1.27k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.27k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  672|  1.27k|		} else {
  673|       |			/* First, select the application */
  674|    472|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    472|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  675|    472|			apdu.data = in_path->aid.value;
  676|    472|			apdu.datalen = in_path->aid.len;
  677|    472|			apdu.lc = in_path->aid.len;
  678|       |
  679|    472|			r = sc_transmit_apdu(card, &apdu);
  680|    472|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 3, False: 469]
  |  |  |  |  ------------------
  |  |  |  |  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|    472|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 469]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  681|    469|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  682|    469|			if (r)
  ------------------
  |  Branch (682:8): [True: 334, False: 135]
  ------------------
  683|    469|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    334|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    334|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    334|	int _ret = r; \
  |  |  |  |  155|    334|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 334, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    334|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    334|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 334, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    334|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    334|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    334|	return _ret; \
  |  |  |  |  163|    334|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  684|       |
  685|    135|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    270|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (685:8): [True: 135, False: 0]
  ------------------
  686|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (686:9): [True: 0, False: 0]
  ------------------
  687|    135|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|    135|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  688|    135|		}
  689|  1.74k|	}
  690|       |
  691|  50.1k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  50.1k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  692|       |
  693|  50.1k|	switch (pathtype) {
  694|  10.3k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  10.3k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (694:2): [True: 10.3k, False: 39.7k]
  ------------------
  695|  10.3k|		apdu.p1 = 0;
  696|  10.3k|		if (pathlen != 2)
  ------------------
  |  Branch (696:7): [True: 0, False: 10.3k]
  ------------------
  697|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  698|  10.3k|		break;
  699|  21.4k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  21.4k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (699:2): [True: 21.4k, False: 28.6k]
  ------------------
  700|  21.4k|		apdu.p1 = 4;
  701|  21.4k|		break;
  702|  18.0k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  18.0k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (702:2): [True: 18.0k, False: 32.0k]
  ------------------
  703|  18.0k|		apdu.p1 = 8;
  704|  18.0k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (704:7): [True: 17.9k, False: 114]
  |  Branch (704:23): [True: 12.5k, False: 5.38k]
  ------------------
  705|  12.5k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (705:8): [True: 3.69k, False: 8.89k]
  ------------------
  706|  3.69k|				select_mf = 1;
  707|  3.69k|				apdu.p1 = 0;
  708|  3.69k|				break;
  709|  3.69k|			}
  710|  8.89k|			path += 2;
  711|  8.89k|			pathlen -= 2;
  712|  8.89k|		}
  713|  14.3k|		break;
  714|  14.3k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    135|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (714:2): [True: 135, False: 49.9k]
  ------------------
  715|    135|		apdu.p1 = 9;
  716|    135|		break;
  717|    143|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    143|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (717:2): [True: 143, False: 49.9k]
  ------------------
  718|    143|		apdu.p1 = 3;
  719|    143|		pathlen = 0;
  720|    143|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    143|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  721|    143|		break;
  722|      0|	default:
  ------------------
  |  Branch (722:2): [True: 0, False: 50.1k]
  ------------------
  723|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|  50.1k|	}
  725|  50.1k|	apdu.lc = pathlen;
  726|  50.1k|	apdu.data = path;
  727|  50.1k|	apdu.datalen = pathlen;
  728|       |
  729|  50.1k|	if (file_out != NULL) {
  ------------------
  |  Branch (729:6): [True: 33.0k, False: 17.0k]
  ------------------
  730|  33.0k|		apdu.p2 = 0;		/* first record, return FCI */
  731|  33.0k|		apdu.resp = buf;
  732|  33.0k|		apdu.resplen = sizeof(buf);
  733|  33.0k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (733:13): [True: 1.09k, False: 31.9k]
  ------------------
  734|  33.0k|	}
  735|  17.0k|	else {
  736|  17.0k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  737|  17.0k|		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|  34.1k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (737:14): [True: 0, False: 17.0k]
  ------------------
  738|  17.0k|	}
  739|       |
  740|  50.1k|	r = sc_transmit_apdu(card, &apdu);
  741|  50.1k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  50.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  50.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  50.1k|	int _ret = (r); \
  |  |  |  |  168|  50.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 451, False: 49.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|    451|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    451|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    451|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    451|		return _ret; \
  |  |  |  |  172|    451|	} \
  |  |  |  |  173|  50.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 49.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|  49.6k|	if (file_out == NULL) {
  ------------------
  |  Branch (742:6): [True: 17.0k, False: 32.6k]
  ------------------
  743|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  744|  17.0k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  745|  17.0k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (745:7): [True: 112, False: 16.9k]
  |  Branch (745:27): [True: 20, False: 92]
  ------------------
  746|     20|			apdu.p2 = 0x00;
  747|     20|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
  |  Branch (747:8): [True: 10, False: 10]
  ------------------
  748|     10|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  749|     20|		}
  750|  17.0k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (750:7): [True: 0, False: 17.0k]
  ------------------
  751|  17.0k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  752|  17.0k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  17.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.0k|	int _ret = r; \
  |  |  |  |  155|  17.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.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|  11.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.8k, False: 5.16k]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.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|  17.0k|	return _ret; \
  |  |  |  |  163|  17.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  753|  17.0k|	}
  754|       |
  755|  32.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  756|  32.6k|	if (r)
  ------------------
  |  Branch (756:6): [True: 18.3k, False: 14.2k]
  ------------------
  757|  32.6k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  18.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.3k|	int _ret = r; \
  |  |  |  |  155|  18.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|  18.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 18.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.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|  18.3k|	return _ret; \
  |  |  |  |  163|  18.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|       |
  759|  14.2k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (759:6): [True: 14.2k, False: 0]
  |  Branch (759:18): [True: 2.61k, False: 11.6k]
  ------------------
  760|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  761|  2.61k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  2.15k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (761:7): [True: 462, False: 2.15k]
  |  Branch (761:20): [True: 1.21k, False: 938]
  ------------------
  762|  1.67k|			file = sc_file_new();
  763|  1.67k|			if (file == NULL)
  ------------------
  |  Branch (763:8): [True: 0, False: 1.67k]
  ------------------
  764|  1.67k|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  765|  1.67k|			file->path = *in_path;
  766|       |
  767|  1.67k|			*file_out = file;
  768|  1.67k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.67k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.67k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.67k|	int _ret = r; \
  |  |  |  |  155|  1.67k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.67k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.67k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, 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.67k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.67k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.67k|	} else { \
  |  |  |  |  159|      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.67k|	return _ret; \
  |  |  |  |  163|  1.67k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  769|  1.67k|		}
  770|  2.61k|	}
  771|       |
  772|  12.5k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (772:6): [True: 1.01k, False: 11.5k]
  ------------------
  773|  12.5k|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|  1.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  774|  11.5k|	switch (apdu.resp[0]) {
  775|  10.4k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  10.4k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (775:2): [True: 10.4k, False: 1.09k]
  ------------------
  776|  11.1k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  11.1k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (776:2): [True: 744, False: 10.7k]
  ------------------
  777|  11.1k|		file = sc_file_new();
  778|  11.1k|		if (file == NULL)
  ------------------
  |  Branch (778:7): [True: 0, False: 11.1k]
  ------------------
  779|  11.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|  11.1k|		file->path = *in_path;
  781|  11.1k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (781:7): [True: 0, False: 11.1k]
  ------------------
  782|      0|			sc_file_free(file);
  783|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  784|      0|		}
  785|  11.1k|		buffer = apdu.resp;
  786|  11.1k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  787|  11.1k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  11.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (787:7): [True: 10.5k, False: 660]
  ------------------
  788|  10.5k|			card->ops->process_fci(card, file, buffer, buffer_len);
  789|  11.1k|		*file_out = file;
  790|  11.1k|		break;
  791|     86|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (791:2): [True: 86, False: 11.4k]
  ------------------
  792|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  793|    261|	default:
  ------------------
  |  Branch (793:2): [True: 261, False: 11.2k]
  ------------------
  794|    261|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    261|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    261|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    261|	int _ret = r; \
  |  |  |  |  155|    261|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 261, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    261|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    261|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 261, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    261|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    261|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    261|	return _ret; \
  |  |  |  |  163|    261|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  795|  11.5k|	}
  796|       |
  797|  11.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  11.1k|#define SC_SUCCESS				0
  ------------------
  798|  11.5k|}
iso7816.c:iso7816_get_response:
  921|  40.4k|{
  922|  40.4k|	struct sc_apdu apdu = {0};
  923|  40.4k|	int r;
  924|  40.4k|	size_t rlen;
  925|       |
  926|       |	/* request at most max_recv_size bytes */
  927|  40.4k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (927:6): [True: 693, False: 39.7k]
  ------------------
  928|    693|		rlen = sc_get_max_recv_size(card);
  929|  39.7k|	else
  930|  39.7k|		rlen = *count;
  931|       |
  932|  40.4k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  40.4k|#define SC_APDU_CASE_2			0x22
  ------------------
  933|  40.4k|	apdu.le      = rlen;
  934|  40.4k|	apdu.resplen = rlen;
  935|  40.4k|	apdu.resp    = buf;
  936|       |	/* don't call GET RESPONSE recursively */
  937|  40.4k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  40.4k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  938|       |
  939|  40.4k|	r = sc_transmit_apdu(card, &apdu);
  940|  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: 467, False: 39.9k]
  |  |  |  |  ------------------
  |  |  |  |  169|    467|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    467|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    467|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    467|		return _ret; \
  |  |  |  |  172|    467|	} \
  |  |  |  |  173|  40.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 39.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  941|       |
  942|  39.9k|	*count = apdu.resplen;
  943|       |
  944|  39.9k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (944:6): [True: 9.39k, False: 30.5k]
  ------------------
  945|  9.39k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  9.39k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.39k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.39k|	int _ret = r; \
  |  |  |  |  155|  9.39k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.39k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.39k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.83k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.83k, False: 5.55k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.39k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.39k|	} else { \
  |  |  |  |  159|      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.39k|	return _ret; \
  |  |  |  |  163|  9.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  946|  9.39k|	}
  947|  30.5k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (947:6): [True: 19.3k, False: 11.1k]
  |  Branch (947:26): [True: 19.0k, False: 330]
  ------------------
  948|  19.0k|		r = 0;					/* no more data to read */
  949|  11.4k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (949:11): [True: 6.84k, False: 4.64k]
  ------------------
  950|  6.84k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (950:7): [True: 2.02k, False: 4.81k]
  ------------------
  951|  4.64k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (951:11): [True: 1.29k, False: 3.35k]
  |  Branch (951:31): [True: 1.17k, False: 120]
  ------------------
  952|  1.17k|		r = 0; /* Le not reached but file/record ended */
  953|  3.47k|	else
  954|  3.47k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  955|       |
  956|  30.5k|	return r;
  957|  39.9k|}
iso7816.c:iso7816_get_challenge:
  803|     37|{
  804|     37|	int r;
  805|     37|	struct sc_apdu apdu;
  806|       |
  807|     37|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x84, 0x00, 0x00);
  ------------------
  |  |  301|     37|#define SC_APDU_CASE_2			0x22
  ------------------
  808|     37|	apdu.le = len;
  809|     37|	apdu.resp = rnd;
  810|     37|	apdu.resplen = len;
  811|       |
  812|     37|	r = sc_transmit_apdu(card, &apdu);
  813|     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: 2, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  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|     37|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 35]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  814|       |
  815|     35|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  816|     35|	LOG_TEST_RET(card->ctx, r, "GET CHALLENGE failed");
  ------------------
  |  |  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: 9, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|     35|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  817|       |
  818|     26|	if (len < apdu.resplen) {
  ------------------
  |  Branch (818:6): [True: 0, False: 26]
  ------------------
  819|      0|		return (int) len;
  820|      0|	}
  821|       |
  822|     26|	return (int) apdu.resplen;
  823|     26|}
iso7816.c:iso7816_restore_security_env:
 1093|     40|{
 1094|     40|	struct sc_apdu apdu;
 1095|     40|	int r;
 1096|       |
 1097|     40|	if (card == NULL) {
  ------------------
  |  Branch (1097:6): [True: 0, False: 40]
  ------------------
 1098|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1099|      0|	}
 1100|       |
 1101|     40|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
  ------------------
  |  |  291|     40|#define SC_APDU_CASE_1			0x01
  ------------------
 1102|       |
 1103|     40|	r = sc_transmit_apdu(card, &apdu);
 1104|     40|	LOG_TEST_RET(card->ctx, r, "APDU 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1105|     30|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1106|     30|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 14, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  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|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1107|       |
 1108|     16|	return r;
 1109|     30|}
iso7816.c:iso7816_set_security_env:
  998|  1.60k|{
  999|  1.60k|	struct sc_apdu apdu;
 1000|  1.60k|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1001|  1.60k|	u8 *p;
 1002|  1.60k|	int r, locked = 0;
 1003|       |
 1004|  1.60k|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (1004:6): [True: 0, False: 1.60k]
  |  Branch (1004:22): [True: 0, False: 1.60k]
  ------------------
 1005|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1006|      0|	}
 1007|  1.60k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|  1.60k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1008|  1.60k|	switch (env->operation) {
 1009|      0|	case SC_SEC_OPERATION_AUTHENTICATE:
  ------------------
  |  |   49|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (1009:2): [True: 0, False: 1.60k]
  ------------------
 1010|      0|		apdu.p2 = 0xA4;
 1011|      0|		break;
 1012|    380|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   47|    380|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1012:2): [True: 380, False: 1.22k]
  ------------------
 1013|    380|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   50|    380|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1013:2): [True: 0, False: 1.60k]
  ------------------
 1014|    380|		apdu.p2 = 0xB8;
 1015|    380|		break;
 1016|  1.22k|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   48|  1.22k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1016:2): [True: 1.22k, False: 380]
  ------------------
 1017|  1.22k|		apdu.p2 = 0xB6;
 1018|  1.22k|		break;
 1019|      0|	default:
  ------------------
  |  Branch (1019:2): [True: 0, False: 1.60k]
  ------------------
 1020|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1021|  1.60k|	}
 1022|  1.60k|	p = sbuf;
 1023|  1.60k|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   56|  1.60k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1023:6): [True: 1.10k, False: 500]
  ------------------
 1024|  1.10k|		*p++ = 0x80;	/* algorithm reference */
 1025|  1.10k|		*p++ = 0x01;
 1026|  1.10k|		*p++ = env->algorithm_ref & 0xFF;
 1027|  1.10k|	}
 1028|  1.60k|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   57|  1.60k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1028:6): [True: 0, False: 1.60k]
  ------------------
 1029|      0|		if (env->file_ref.len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|      0|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (1029:7): [True: 0, False: 0]
  ------------------
 1030|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1031|      0|		if (sizeof(sbuf) - (p - sbuf) < env->file_ref.len + 2)
  ------------------
  |  Branch (1031:7): [True: 0, False: 0]
  ------------------
 1032|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1033|       |
 1034|      0|		*p++ = 0x81;
 1035|      0|		*p++ = (u8) env->file_ref.len;
 1036|      0|		memcpy(p, env->file_ref.value, env->file_ref.len);
 1037|      0|		p += env->file_ref.len;
 1038|      0|	}
 1039|  1.60k|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   58|  1.60k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1039:6): [True: 1.60k, False: 0]
  ------------------
 1040|  1.60k|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1040:7): [True: 0, False: 1.60k]
  ------------------
 1041|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1042|       |
 1043|  1.60k|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   59|  1.60k|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1043:7): [True: 0, False: 1.60k]
  ------------------
 1044|      0|			*p++ = 0x83;
 1045|  1.60k|		else
 1046|  1.60k|			*p++ = 0x84;
 1047|  1.60k|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|  1.60k|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1047:7): [True: 0, False: 1.60k]
  ------------------
 1048|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1049|  1.60k|		*p++ = env->key_ref_len & 0xFF;
 1050|  1.60k|		memcpy(p, env->key_ref, env->key_ref_len);
 1051|  1.60k|		p += env->key_ref_len;
 1052|  1.60k|	}
 1053|  1.60k|	r = (int)(p - sbuf);
 1054|  1.60k|	apdu.lc = r;
 1055|  1.60k|	apdu.datalen = r;
 1056|  1.60k|	apdu.data = sbuf;
 1057|  1.60k|	if (se_num > 0) {
  ------------------
  |  Branch (1057:6): [True: 0, False: 1.60k]
  ------------------
 1058|      0|		r = sc_lock(card);
 1059|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1060|      0|		locked = 1;
 1061|      0|	}
 1062|  1.60k|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1062:6): [True: 1.60k, False: 0]
  ------------------
 1063|  1.60k|		r = sc_transmit_apdu(card, &apdu);
 1064|  1.60k|		if (r) {
  ------------------
  |  Branch (1064:7): [True: 20, False: 1.58k]
  ------------------
 1065|     20|			sc_log(card->ctx, "%s: APDU transmit failed", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1066|     20|			goto err;
 1067|     20|		}
 1068|  1.58k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1069|  1.58k|		if (r) {
  ------------------
  |  Branch (1069:7): [True: 1.24k, False: 343]
  ------------------
 1070|  1.24k|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1071|  1.24k|			goto err;
 1072|  1.24k|		}
 1073|  1.58k|	}
 1074|    343|	if (se_num <= 0) {
  ------------------
  |  Branch (1074:6): [True: 343, False: 0]
  ------------------
 1075|    343|		r = SC_SUCCESS;
  ------------------
  |  |   28|    343|#define SC_SUCCESS				0
  ------------------
 1076|    343|		goto err;
 1077|    343|	}
 1078|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1079|      0|	r = sc_transmit_apdu(card, &apdu);
 1080|      0|	sc_unlock(card);
 1081|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1082|       |
 1083|      0|	return sc_check_sw(card, apdu.sw1, apdu.sw2);
 1084|  1.60k|err:
 1085|  1.60k|	if (locked)
  ------------------
  |  Branch (1085:6): [True: 0, False: 1.60k]
  ------------------
 1086|      0|		sc_unlock(card);
 1087|  1.60k|	return r;
 1088|      0|}
iso7816.c:iso7816_decipher:
 1155|     33|{
 1156|     33|	int r;
 1157|     33|	struct sc_apdu apdu;
 1158|     33|	u8 *sbuf = NULL;
 1159|       |
 1160|     33|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1160:6): [True: 0, False: 33]
  |  Branch (1160:22): [True: 0, False: 33]
  |  Branch (1160:40): [True: 0, False: 33]
  ------------------
 1161|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1162|      0|	}
 1163|     33|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1164|     33|	sc_log(card->ctx, "ISO7816 decipher: in-len %zu, out-len %zu", crgram_len, outlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1165|       |
 1166|     33|	sbuf = malloc(crgram_len + 1);
 1167|     33|	if (sbuf == NULL)
  ------------------
  |  Branch (1167:6): [True: 0, False: 33]
  ------------------
 1168|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1169|       |
 1170|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1171|       |	 * P1:  0x80  Resp: Plain value
 1172|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1173|     33|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     33|#define SC_APDU_CASE_4			0x24
  ------------------
 1174|     33|	apdu.resp    = out;
 1175|     33|	apdu.resplen = outlen;
 1176|     33|	apdu.le      = outlen;
 1177|       |
 1178|     33|	sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */
 1179|     33|	memcpy(sbuf + 1, crgram, crgram_len);
 1180|     33|	apdu.data = sbuf;
 1181|     33|	apdu.lc = crgram_len + 1;
 1182|     33|	apdu.datalen = crgram_len + 1;
 1183|       |
 1184|     33|	iso7816_fixup_transceive_length(card, &apdu);
 1185|     33|	r = sc_transmit_apdu(card, &apdu);
 1186|     33|	sc_mem_clear(sbuf, crgram_len + 1);
 1187|     33|	free(sbuf);
 1188|     33|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     33|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     33|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     33|	int _ret = (r); \
  |  |  |  |  168|     33|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 29]
  |  |  |  |  ------------------
  |  |  |  |  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|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 29]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1189|       |
 1190|     29|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1190:6): [True: 23, False: 6]
  |  Branch (1190:26): [True: 20, False: 3]
  ------------------
 1191|     29|		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: 5, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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|     15|	} 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|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1192|      9|	else
 1193|     29|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1194|     29|}
iso7816.c:iso7816_compute_signature:
 1116|    132|{
 1117|    132|	int r;
 1118|    132|	struct sc_apdu apdu;
 1119|       |
 1120|    132|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1120:6): [True: 0, False: 132]
  |  Branch (1120:22): [True: 0, False: 132]
  |  Branch (1120:38): [True: 0, False: 132]
  ------------------
 1121|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1122|      0|	}
 1123|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1124|    132|	sc_log(card->ctx, "ISO7816 compute signature: in-len %zu, out-len %zu", datalen, outlen);
  ------------------
  |  |   71|    132|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1125|       |
 1126|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1127|       |	 * P1:  0x9E  Resp: Digital Signature
 1128|       |	 * P2:  0x9A  Cmd: Input for Digital Signature */
 1129|    132|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  303|    132|#define SC_APDU_CASE_4			0x24
  ------------------
 1130|    132|	apdu.resp = out;
 1131|    132|	apdu.resplen = outlen;
 1132|    132|	apdu.le = outlen;
 1133|       |
 1134|    132|	apdu.data = data;
 1135|    132|	apdu.lc = datalen;
 1136|    132|	apdu.datalen = datalen;
 1137|       |
 1138|    132|	iso7816_fixup_transceive_length(card, &apdu);
 1139|    132|	r = sc_transmit_apdu(card, &apdu);
 1140|    132|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    132|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    132|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    132|	int _ret = (r); \
  |  |  |  |  168|    132|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  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|    132|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|     91|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1141:6): [True: 74, False: 17]
  |  Branch (1141:26): [True: 55, False: 19]
  ------------------
 1142|     91|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|     55|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     55|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     55|	int _ret = r; \
  |  |  |  |  155|     55|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 30, False: 25]
  |  |  |  |  ------------------
  |  |  |  |  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|     25|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     25|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     25|	} \
  |  |  |  |  162|     55|	return _ret; \
  |  |  |  |  163|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1143|       |
 1144|     36|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1145|     36|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|       |
 1147|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1148|      0|}
iso7816.c:iso7816_check_sw:
  110|   498k|{
  111|   498k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  112|   498k|	int i;
  113|       |
  114|       |	/* Handle special cases here */
  115|   498k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (115:6): [True: 439, False: 497k]
  ------------------
  116|    439|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    439|#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|    439|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    439|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  118|    439|	}
  119|   497k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (119:6): [True: 188k, False: 309k]
  |  Branch (119:21): [True: 181k, False: 7.04k]
  ------------------
  120|   181k|		return SC_SUCCESS;
  ------------------
  |  |   28|   181k|#define SC_SUCCESS				0
  ------------------
  121|   316k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (121:6): [True: 871, False: 315k]
  |  Branch (121:22): [True: 193, False: 678]
  ------------------
  122|    193|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   71|    193|#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|    193|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    193|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  124|    193|	}
  125|  12.9M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (125:14): [True: 12.9M, False: 33.2k]
  ------------------
  126|  12.9M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (126:7): [True: 282k, False: 12.6M]
  ------------------
  127|   282k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   282k|#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|   282k|			return iso7816_errors[i].errorno;
  129|   282k|		}
  130|  12.9M|	}
  131|       |
  132|  33.2k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  33.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__
  |  |  ------------------
  ------------------
  133|  33.2k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  33.2k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  134|   316k|}
iso7816.c:iso7816_process_fci:
  639|  7.45k|{
  640|  7.45k|	return iso7816_process_fci_nested(card, file, buf, buflen, 0);
  641|  7.45k|}
iso7816.c:iso7816_process_fci_nested:
  436|  9.01k|{
  437|  9.01k|	struct sc_context *ctx = card->ctx;
  438|  9.01k|	const unsigned char *p, *end;
  439|  9.01k|	unsigned int cla = 0, tag = 0;
  440|  9.01k|	size_t length;
  441|       |
  442|  9.01k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.01k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  443|       |
  444|  9.01k|	for (p = buf, length = buflen, end = buf + buflen;
  445|  26.0k|			p < end;
  ------------------
  |  Branch (445:4): [True: 22.7k, False: 3.34k]
  ------------------
  446|  22.7k|			p += length, length = end - p) {
  447|       |
  448|  22.7k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  22.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (448:7): [True: 3.94k, False: 18.8k]
  ------------------
  449|  18.8k|				|| p == NULL) {
  ------------------
  |  Branch (449:8): [True: 1.73k, False: 17.0k]
  ------------------
  450|  5.67k|			break;
  451|  5.67k|		}
  452|  17.0k|		switch (cla | tag) {
  ------------------
  |  Branch (452:11): [True: 12.9k, False: 4.16k]
  ------------------
  453|  1.79k|			case 0x81:
  ------------------
  |  Branch (453:4): [True: 1.79k, False: 15.2k]
  ------------------
  454|  1.79k|				if (file->size != 0) {
  ------------------
  |  Branch (454:9): [True: 101, False: 1.69k]
  ------------------
  455|       |					/* don't overwrite existing file size excluding structural information */
  456|    101|					break;
  457|    101|				}
  458|       |				/* fall through */
  459|  3.64k|			case 0x80:
  ------------------
  |  Branch (459:4): [True: 1.94k, False: 15.1k]
  ------------------
  460|       |				/* determine the file size */
  461|  3.64k|				file->size = 0;
  462|  3.64k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (462:9): [True: 3.64k, False: 0]
  |  Branch (462:14): [True: 3.60k, False: 37]
  ------------------
  463|  3.60k|					size_t size = 0, i;
  464|  11.8k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (464:18): [True: 8.26k, False: 3.60k]
  ------------------
  465|  8.26k|						size <<= 8;
  466|  8.26k|						size |= p[i];
  467|  8.26k|					}
  468|  3.60k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  220|  3.60k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (468:10): [True: 497, False: 3.10k]
  ------------------
  469|    497|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  220|    497|#define MAX_FILE_SIZE 65535
  ------------------
  470|    497|						sc_log(ctx, "  file size truncated, encoded length: %zu", size);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  471|  3.10k|					} else {
  472|  3.10k|						file->size = size;
  473|  3.10k|					}
  474|  3.60k|				}
  475|       |
  476|  3.64k|				sc_log(ctx, "  bytes in file: %zu", file->size);
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  477|  3.64k|				break;
  478|       |
  479|  1.84k|			case 0x82:
  ------------------
  |  Branch (479:4): [True: 1.84k, False: 15.2k]
  ------------------
  480|  1.84k|				if (length > 0) {
  ------------------
  |  Branch (480:9): [True: 1.58k, False: 262]
  ------------------
  481|  1.58k|					unsigned char byte = p[0];
  482|  1.58k|					const char *type;
  483|       |
  484|  1.58k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (484:24): [True: 342, False: 1.24k]
  ------------------
  485|  1.58k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  3.16k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 342, False: 1.24k]
  |  |  ------------------
  ------------------
  486|  1.58k|					file->ef_structure = byte & 0x07;
  487|  1.58k|					switch ((byte >> 3) & 7) {
  488|    834|						case 0:
  ------------------
  |  Branch (488:7): [True: 834, False: 750]
  ------------------
  489|    834|							type = "working EF";
  490|    834|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    834|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  491|    834|							break;
  492|    215|						case 1:
  ------------------
  |  Branch (492:7): [True: 215, False: 1.36k]
  ------------------
  493|    215|							type = "internal EF";
  494|    215|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    215|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  495|    215|							break;
  496|    259|						case 7:
  ------------------
  |  Branch (496:7): [True: 259, False: 1.32k]
  ------------------
  497|    259|							type = "DF";
  498|    259|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    259|#define SC_FILE_TYPE_DF			0x04
  ------------------
  499|    259|							break;
  500|    276|						default:
  ------------------
  |  Branch (500:7): [True: 276, False: 1.30k]
  ------------------
  501|    276|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    276|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  502|    276|							type = "unknown";
  503|    276|							break;
  504|  1.58k|					}
  505|  1.58k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  506|  1.58k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  507|  1.58k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  508|       |
  509|       |					/* if possible, get additional information for non-DFs */
  510|  1.58k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  1.58k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (510:10): [True: 1.32k, False: 259]
  ------------------
  511|       |						/* max. record length for fixed- & variable-sized records */
  512|  1.32k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (512:11): [True: 568, False: 757]
  |  Branch (512:25): [True: 435, False: 133]
  ------------------
  513|    435|							file->record_length = (length > 3)
  ------------------
  |  Branch (513:30): [True: 328, False: 107]
  ------------------
  514|    435|								? bebytes2ushort(p+2)
  515|    435|								: p[2];
  516|    435|							sc_log(ctx, "  record length: %zu", file->record_length);
  ------------------
  |  |   71|    435|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  517|    435|						}
  518|       |
  519|       |						/* number of records */
  520|  1.32k|						if (length > 4) {
  ------------------
  |  Branch (520:11): [True: 246, False: 1.07k]
  ------------------
  521|    246|							file->record_count = (length > 5)
  ------------------
  |  Branch (521:29): [True: 77, False: 169]
  ------------------
  522|    246|								? bebytes2ushort(p+4)
  523|    246|								: p[4];
  524|    246|							sc_log(ctx, "  records: %zu", file->record_count);
  ------------------
  |  |   71|    246|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  525|    246|						}
  526|  1.32k|					}
  527|       |
  528|  1.58k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  1.58k|#define SC_SUCCESS				0
  ------------------
  |  Branch (528:10): [True: 0, False: 1.58k]
  ------------------
  529|      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__
  |  |  ------------------
  ------------------
  530|  1.58k|				}
  531|  1.84k|				break;
  532|       |
  533|  1.84k|			case 0x83:
  ------------------
  |  Branch (533:4): [True: 1.09k, False: 15.9k]
  ------------------
  534|  1.09k|				if (length == 2) {
  ------------------
  |  Branch (534:9): [True: 806, False: 287]
  ------------------
  535|    806|					file->id = (p[0] << 8) | p[1];
  536|    806|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|    806|#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|    806|				}
  538|  1.09k|				break;
  539|       |
  540|    503|			case 0x84:
  ------------------
  |  Branch (540:4): [True: 503, False: 16.5k]
  ------------------
  541|    503|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (541:9): [True: 431, False: 72]
  |  Branch (541:23): [True: 411, False: 20]
  ------------------
  542|    411|					memcpy(file->name, p, length);
  543|    411|					file->namelen = length;
  544|       |
  545|    411|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    411|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    411|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  546|    411|					if (!file->type)
  ------------------
  |  Branch (546:10): [True: 264, False: 147]
  ------------------
  547|    264|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    264|#define SC_FILE_TYPE_DF			0x04
  ------------------
  548|    411|				}
  549|    503|				break;
  550|       |
  551|    903|			case 0x85:
  ------------------
  |  Branch (551:4): [True: 903, False: 16.1k]
  ------------------
  552|  1.16k|			case 0xA5:
  ------------------
  |  Branch (552:4): [True: 261, False: 16.8k]
  ------------------
  553|  1.16k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.16k|#define SC_SUCCESS				0
  ------------------
  |  Branch (553:9): [True: 0, False: 1.16k]
  ------------------
  554|      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__
  |  |  ------------------
  ------------------
  555|      0|				}
  556|  1.16k|				break;
  557|       |
  558|  1.25k|			case 0x86:
  ------------------
  |  Branch (558:4): [True: 1.25k, False: 15.8k]
  ------------------
  559|  1.25k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.25k|#define SC_SUCCESS				0
  ------------------
  |  Branch (559:9): [True: 0, False: 1.25k]
  ------------------
  560|      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__
  |  |  ------------------
  ------------------
  561|      0|				}
  562|  1.25k|				break;
  563|       |
  564|    336|			case 0x88:
  ------------------
  |  Branch (564:4): [True: 336, False: 16.7k]
  ------------------
  565|    336|				if (length == 1) {
  ------------------
  |  Branch (565:9): [True: 99, False: 237]
  ------------------
  566|     99|					file->sid = *p;
  567|     99|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  568|     99|				}
  569|    336|				break;
  570|       |
  571|  1.41k|			case 0x8A:
  ------------------
  |  Branch (571:4): [True: 1.41k, False: 15.6k]
  ------------------
  572|  1.41k|				if (length == 1) {
  ------------------
  |  Branch (572:9): [True: 1.16k, False: 247]
  ------------------
  573|  1.16k|					switch (p[0]) {
  574|     67|						case 0:
  ------------------
  |  Branch (574:7): [True: 67, False: 1.10k]
  ------------------
  575|     67|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     67|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  576|     67|							break;
  577|     72|						case 1:
  ------------------
  |  Branch (577:7): [True: 72, False: 1.09k]
  ------------------
  578|     72|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     72|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  579|     72|							break;
  580|     67|						case 3:
  ------------------
  |  Branch (580:7): [True: 67, False: 1.10k]
  ------------------
  581|     67|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     67|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  582|     67|							break;
  583|     67|						case 4:
  ------------------
  |  Branch (583:7): [True: 67, False: 1.10k]
  ------------------
  584|    134|						case 6:
  ------------------
  |  Branch (584:7): [True: 67, False: 1.10k]
  ------------------
  585|    134|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    134|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  586|    134|							break;
  587|     82|						case 5:
  ------------------
  |  Branch (587:7): [True: 82, False: 1.08k]
  ------------------
  588|    154|						case 7:
  ------------------
  |  Branch (588:7): [True: 72, False: 1.09k]
  ------------------
  589|    154|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    154|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  590|    154|							break;
  591|     66|						case 12:
  ------------------
  |  Branch (591:7): [True: 66, False: 1.10k]
  ------------------
  592|    132|						case 13:
  ------------------
  |  Branch (592:7): [True: 66, False: 1.10k]
  ------------------
  593|    200|						case 14:
  ------------------
  |  Branch (593:7): [True: 68, False: 1.09k]
  ------------------
  594|    266|						case 15:
  ------------------
  |  Branch (594:7): [True: 66, False: 1.10k]
  ------------------
  595|    266|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    266|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  596|    266|							break;
  597|     67|						case 2:
  ------------------
  |  Branch (597:7): [True: 67, False: 1.10k]
  ------------------
  598|     67|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     67|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  599|     67|							break;
  600|     68|						case 8:
  ------------------
  |  Branch (600:7): [True: 68, False: 1.09k]
  ------------------
  601|     68|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     68|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  602|     68|							break;
  603|     66|						case 9:
  ------------------
  |  Branch (603:7): [True: 66, False: 1.10k]
  ------------------
  604|     66|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     66|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  605|     66|							break;
  606|     66|						case 10:
  ------------------
  |  Branch (606:7): [True: 66, False: 1.10k]
  ------------------
  607|     66|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     66|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  608|     66|							break;
  609|     67|						case 11:
  ------------------
  |  Branch (609:7): [True: 67, False: 1.10k]
  ------------------
  610|     67|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     67|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  611|     67|							break;
  612|     73|						default:
  ------------------
  |  Branch (612:7): [True: 73, False: 1.09k]
  ------------------
  613|     73|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|     73|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  614|  1.16k|					}
  615|  1.16k|				}
  616|  1.41k|				break;
  617|       |
  618|  1.41k|			case 0x62:
  ------------------
  |  Branch (618:4): [True: 886, False: 16.1k]
  ------------------
  619|  1.14k|			case 0x64:
  ------------------
  |  Branch (619:4): [True: 258, False: 16.8k]
  ------------------
  620|  1.56k|			case 0x6F:
  ------------------
  |  Branch (620:4): [True: 420, False: 16.6k]
  ------------------
  621|       |				/* allow nested FCP/FMD/FCI templates */
  622|  1.56k|				if (depth >= ISO7816_MAX_FCI_TEMPLATE_NESTING) {
  ------------------
  |  |  431|  1.56k|#define ISO7816_MAX_FCI_TEMPLATE_NESTING 32
  ------------------
  |  Branch (622:9): [True: 0, False: 1.56k]
  ------------------
  623|      0|					sc_log(ctx, "FCP/FMD/FCI template nesting too deep, skipping");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  624|      0|					break;
  625|      0|				}
  626|  1.56k|				iso7816_process_fci_nested(card, file, p, length, depth + 1);
  627|  17.0k|		}
  628|  17.0k|	}
  629|       |
  630|  9.01k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|  9.01k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  631|       |
  632|  9.01k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.01k|#define SC_SUCCESS				0
  ------------------
  633|  9.01k|}
iso7816.c:iso7816_pin_cmd:
 1299|  8.68k|{
 1300|  8.68k|	struct sc_apdu local_apdu, *apdu;
 1301|  8.68k|	int r;
 1302|  8.68k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1303|       |
 1304|  8.68k|	data->pin1.tries_left = -1;
 1305|       |
 1306|       |	/* Many cards do support PIN status queries, but some cards don't and
 1307|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1308|       |	 * allow cards with this flag.  In future this may be reduced to a
 1309|       |	 * blocklist, subject to testing more cards. */
 1310|  8.68k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  418|  17.3k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1310:6): [True: 7.09k, False: 1.59k]
  ------------------
 1311|  7.09k|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  553|  7.09k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1311:6): [True: 180, False: 6.91k]
  ------------------
 1312|    180|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   71|    180|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1313|    180|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    180|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1314|    180|	}
 1315|       |
 1316|       |	/* See if we've been called from another card driver, which is
 1317|       |	 * passing an APDU to us (this allows to write card drivers
 1318|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1319|       |	 * special circumstances.
 1320|       |	 */
 1321|  8.50k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1321:6): [True: 8.50k, False: 2]
  ------------------
 1322|  8.50k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1323|  8.50k|		if (r < 0)
  ------------------
  |  Branch (1323:7): [True: 62, False: 8.44k]
  ------------------
 1324|     62|			return r;
 1325|  8.44k|		data->apdu = &local_apdu;
 1326|  8.44k|	}
 1327|  8.44k|	apdu = data->apdu;
 1328|       |
 1329|  8.44k|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  421|  8.44k|#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 (1329:6): [True: 8.44k, False: 0]
  |  Branch (1329:48): [True: 0, False: 0]
  ------------------
 1330|       |		/* Transmit the APDU to the card */
 1331|  8.44k|		r = sc_transmit_apdu(card, apdu);
 1332|       |
 1333|       |		/* Clear the buffer - it may contain pins */
 1334|  8.44k|		sc_mem_clear(sbuf, sizeof(sbuf));
 1335|  8.44k|	}
 1336|      0|	else {
 1337|       |		/* Call the reader driver to collect
 1338|       |		 * the PIN and pass on the APDU to the card */
 1339|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1339:7): [True: 0, False: 0]
  ------------------
 1340|      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__
  |  |  ------------------
  ------------------
 1341|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1342|      0|		}
 1343|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1343:7): [True: 0, False: 0]
  |  Branch (1343:23): [True: 0, False: 0]
  |  Branch (1343:44): [True: 0, False: 0]
  ------------------
 1344|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1345|       |			/* sw1/sw2 filled in by reader driver */
 1346|      0|		}
 1347|      0|		else {
 1348|      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__
  |  |  ------------------
  ------------------
 1349|      0|					"PIN entry through reader key pad");
 1350|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1351|      0|		}
 1352|      0|	}
 1353|       |
 1354|       |	/* Don't pass references to local variables up to the caller. */
 1355|  8.44k|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1355:6): [True: 8.44k, False: 2]
  ------------------
 1356|  8.44k|		data->apdu = NULL;
 1357|       |
 1358|  8.44k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  8.44k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  8.44k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  8.44k|	int _ret = (r); \
  |  |  |  |  168|  8.44k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 8.40k]
  |  |  |  |  ------------------
  |  |  |  |  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|  8.44k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8.40k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1359|  8.40k|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1360|       |
 1361|  8.40k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  8.40k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1361:6): [True: 2.01k, False: 6.39k]
  ------------------
 1362|  2.01k|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  432|  2.01k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1363|  6.39k|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|  6.39k|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1363:13): [True: 47, False: 6.34k]
  ------------------
 1364|     47|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1365|     47|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|     47|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1366|     47|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|     47|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1366:7): [True: 21, False: 26]
  ------------------
 1367|     21|			r = SC_SUCCESS;
  ------------------
  |  |   28|     21|#define SC_SUCCESS				0
  ------------------
 1368|  6.34k|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|  6.34k|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1368:13): [True: 6, False: 6.34k]
  ------------------
 1369|      6|		data->pin1.tries_left = 0;
 1370|      6|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  431|      6|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1371|      6|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  418|      6|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1371:7): [True: 3, False: 3]
  ------------------
 1372|      3|			r = SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 1373|      6|	}
 1374|       |
 1375|  8.40k|	return r;
 1376|  8.44k|}
iso7816.c:iso7816_get_data:
 1380|    187|{
 1381|    187|	int                             r, cse;
 1382|    187|	struct sc_apdu                  apdu;
 1383|       |
 1384|    187|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    187|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    187|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    187|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 187]
  |  |  ------------------
  ------------------
 1385|       |
 1386|    187|	if (buf && len)
  ------------------
  |  Branch (1386:6): [True: 187, False: 0]
  |  Branch (1386:13): [True: 187, False: 0]
  ------------------
 1387|    187|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    187|#define SC_APDU_CASE_2			0x22
  ------------------
 1388|      0|	else
 1389|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1390|       |
 1391|    187|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1392|    187|	apdu.le = len;
 1393|    187|	apdu.resp = buf;
 1394|    187|	apdu.resplen = len;
 1395|    187|	r = sc_transmit_apdu(card, &apdu);
 1396|    187|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    187|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    187|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    187|	int _ret = (r); \
  |  |  |  |  168|    187|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 183]
  |  |  |  |  ------------------
  |  |  |  |  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|    187|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 183]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1397|       |
 1398|    183|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1399|    183|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|    183|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    183|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    183|	int _ret = (r); \
  |  |  |  |  168|    183|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 56, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  169|     56|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     56|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     56|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     56|		return _ret; \
  |  |  |  |  172|     56|	} \
  |  |  |  |  173|    183|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1400|       |
 1401|    127|	if (apdu.resplen > len)
  ------------------
  |  Branch (1401:6): [True: 0, False: 127]
  ------------------
 1402|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1403|    127|	else
 1404|    127|		r = (int)apdu.resplen;
 1405|       |
 1406|    127|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    127|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    127|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    127|	int _ret = r; \
  |  |  |  |  155|    127|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 39, False: 88]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 39]
  |  |  |  |  ------------------
  |  |  |  |  157|     39|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     88|	} else { \
  |  |  |  |  159|     88|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     88|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     88|	} \
  |  |  |  |  162|    127|	return _ret; \
  |  |  |  |  163|    127|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1407|    127|}
iso7816.c:iso7816_read_binary:
  139|  19.5k|{
  140|  19.5k|	struct sc_context *ctx = card->ctx;
  141|  19.5k|	struct sc_apdu apdu;
  142|  19.5k|	int r;
  143|       |
  144|  19.5k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (144:6): [True: 6, False: 19.5k]
  ------------------
  145|      6|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  146|      6|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      6|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  147|      6|	}
  148|       |
  149|  19.5k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  19.5k|#define SC_APDU_CASE_2			0x22
  ------------------
  150|  19.5k|	apdu.le = count;
  151|  19.5k|	apdu.resplen = count;
  152|  19.5k|	apdu.resp = buf;
  153|       |
  154|  19.5k|	iso7816_fixup_transceive_length(card, &apdu);
  155|  19.5k|	r = sc_transmit_apdu(card, &apdu);
  156|  19.5k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  19.5k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  19.5k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  19.5k|	int _ret = (r); \
  |  |  |  |  168|  19.5k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 486, False: 19.0k]
  |  |  |  |  ------------------
  |  |  |  |  169|    486|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    486|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    486|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    486|		return _ret; \
  |  |  |  |  172|    486|	} \
  |  |  |  |  173|  19.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  157|       |
  158|  19.0k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  159|  19.0k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  38.0k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  18.7k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (159:6): [True: 274, False: 18.7k]
  |  Branch (159:40): [True: 136, False: 18.6k]
  ------------------
  160|  19.0k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    410|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    410|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    410|	int _ret = r; \
  |  |  |  |  155|    410|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 81, False: 329]
  |  |  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  157|     81|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    329|	} else { \
  |  |  |  |  159|    329|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    329|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    329|	} \
  |  |  |  |  162|    410|	return _ret; \
  |  |  |  |  163|    410|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  161|  18.6k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  18.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  18.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  18.6k|	int _ret = (r); \
  |  |  |  |  168|  18.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.34k, False: 16.2k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.34k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.34k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.34k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.34k|		return _ret; \
  |  |  |  |  172|  2.34k|	} \
  |  |  |  |  173|  18.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16.2k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|       |
  163|  16.2k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  16.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.2k|	int _ret = r; \
  |  |  |  |  155|  16.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 943, False: 15.3k]
  |  |  |  |  ------------------
  |  |  |  |  156|    943|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 943]
  |  |  |  |  ------------------
  |  |  |  |  157|    943|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.3k|	} else { \
  |  |  |  |  159|  15.3k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  15.3k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  15.3k|	} \
  |  |  |  |  162|  16.2k|	return _ret; \
  |  |  |  |  163|  16.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  164|  16.2k|}

sc_do_log:
   57|  18.3M|{
   58|  18.3M|	va_list ap;
   59|       |
   60|  18.3M|	va_start(ap, format);
   61|  18.3M|	sc_do_log_va(ctx, level, file, line, func, 0, format, ap);
   62|       |	va_end(ap);
   63|  18.3M|}
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|  5.68k|{
   77|  5.68k|	BIO *bio = NULL;
   78|  5.68k|	int length, rc;
   79|  5.68k|	char *buffer = NULL;
   80|       |
   81|  5.68k|	if ((bio = BIO_new(BIO_s_mem())) == NULL) {
  ------------------
  |  Branch (81:6): [True: 0, False: 5.68k]
  ------------------
   82|      0|		sc_do_log(ctx, level, file, line, func, "Cannot log OpenSSL error");
   83|      0|		goto end;
   84|      0|	}
   85|  5.68k|	ERR_print_errors(bio);
   86|       |
   87|  5.68k|	length = BIO_pending(bio);
   88|  5.68k|	if (length <= 0) {
  ------------------
  |  Branch (88:6): [True: 5.68k, False: 1]
  ------------------
   89|       |		/* no error? */
   90|  5.68k|		goto end;
   91|  5.68k|	}
   92|       |	/* trailing null byte */
   93|      1|	buffer = malloc(length + 1);
   94|      1|	if (buffer == NULL) {
  ------------------
  |  Branch (94:6): [True: 0, False: 1]
  ------------------
   95|      0|		sc_do_log(ctx, level, file, line, func, "No memory!");
   96|      0|		goto end;
   97|      0|	}
   98|      1|	rc = BIO_read(bio, buffer, length);
   99|      1|	buffer[length] = '\0';
  100|      1|	if (rc <= 0) {
  ------------------
  |  Branch (100:6): [True: 0, False: 1]
  ------------------
  101|      0|		sc_do_log(ctx, level, file, line, func, "Cannot read OpenSSL error");
  102|      0|		goto end;
  103|      0|	}
  104|       |
  105|      1|	sc_do_log(ctx, level, file, line, func, "OpenSSL error\n%s", buffer);
  106|  5.68k|end:
  107|  5.68k|	free(buffer);
  108|  5.68k|	BIO_free(bio);
  109|  5.68k|}
_sc_debug_hex:
  342|   506k|{
  343|   506k|	size_t blen;
  344|   506k|	char *buf;
  345|   506k|	const char *truncated = "";
  346|       |
  347|   506k|	if (len > SC_MAX_EXT_APDU_BUFFER_SIZE) {
  ------------------
  |  |   37|   506k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
  |  Branch (347:6): [True: 0, False: 506k]
  ------------------
  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|   506k|	blen = len * 5 + 128;
  352|       |
  353|   506k|	buf = malloc(blen);
  354|   506k|	if (buf == NULL)
  ------------------
  |  Branch (354:6): [True: 0, False: 506k]
  ------------------
  355|      0|		return;
  356|       |
  357|   506k|	sc_hex_dump(data, len, buf, blen);
  358|       |
  359|   506k|	if (label)
  ------------------
  |  Branch (359:6): [True: 506k, False: 0]
  ------------------
  360|   506k|		sc_do_log(ctx, type, file, line, func, "\n%s (%s%zu byte%s):\n%s",
  361|   506k|				label, truncated, len, len == 1 ? "" : "s", buf);
  ------------------
  |  Branch (361:28): [True: 1.72k, False: 504k]
  ------------------
  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|   506k|	free(buf);
  367|   506k|}
sc_hex_dump:
  370|   506k|{
  371|   506k|	char *p = buf;
  372|   506k|	size_t p_len = len;
  373|   506k|	int lines = 0;
  374|       |
  375|   506k|	if (buf == NULL || len == 0 || (in == NULL && count != 0)) {
  ------------------
  |  Branch (375:6): [True: 0, False: 506k]
  |  Branch (375:21): [True: 0, False: 506k]
  |  Branch (375:34): [True: 98, False: 506k]
  |  Branch (375:48): [True: 0, False: 98]
  ------------------
  376|      0|		return;
  377|      0|	}
  378|   506k|	buf[0] = 0;
  379|   506k|	if (count == 0)
  ------------------
  |  Branch (379:6): [True: 113k, False: 393k]
  ------------------
  380|   113k|		return;
  381|   393k|	if (count > (SIZE_MAX - 15) / 65 || ((count + 15) / 16) * 65 >= len)
  ------------------
  |  Branch (381:6): [True: 0, False: 393k]
  |  Branch (381:38): [True: 0, False: 393k]
  ------------------
  382|      0|		return;
  383|  3.51M|	while (count && p_len > 0) {
  ------------------
  |  Branch (383:9): [True: 3.12M, False: 393k]
  |  Branch (383:18): [True: 3.12M, False: 0]
  ------------------
  384|  3.12M|		char ascbuf[17];
  385|  3.12M|		size_t i;
  386|  3.12M|		size_t asc_len;
  387|       |
  388|  50.0M|		for (i = 0; i < count && i < 16; i++) {
  ------------------
  |  Branch (388:15): [True: 49.6M, False: 393k]
  |  Branch (388:28): [True: 46.8M, False: 2.73M]
  ------------------
  389|  46.8M|			if (p_len < 4)
  ------------------
  |  Branch (389:8): [True: 0, False: 46.8M]
  ------------------
  390|      0|				return;
  391|  46.8M|			snprintf(p, p_len, "%02X ", *in);
  392|  46.8M|			if (isprint(*in))
  ------------------
  |  Branch (392:8): [True: 26.8M, False: 20.0M]
  ------------------
  393|  26.8M|				ascbuf[i] = *in;
  394|  20.0M|			else
  395|  20.0M|				ascbuf[i] = '.';
  396|  46.8M|			p += 3;
  397|  46.8M|			p_len -= 3;
  398|  46.8M|			in++;
  399|  46.8M|		}
  400|  3.12M|		count -= i;
  401|  3.12M|		ascbuf[i] = 0;
  402|  3.12M|		asc_len = i;
  403|  3.73M|		for (; i < 16 && lines; i++) {
  ------------------
  |  Branch (403:10): [True: 831k, False: 2.90M]
  |  Branch (403:20): [True: 612k, False: 218k]
  ------------------
  404|   612k|			if (p_len < 4)
  ------------------
  |  Branch (404:8): [True: 0, False: 612k]
  ------------------
  405|      0|				return;
  406|   612k|			strlcat(p, "   ", p_len);
  407|   612k|			p += 3;
  408|   612k|			p_len -= 3;
  409|   612k|		}
  410|  3.12M|		if (p_len < asc_len + 2)
  ------------------
  |  Branch (410:7): [True: 0, False: 3.12M]
  ------------------
  411|      0|			return;
  412|  3.12M|		snprintf(p, p_len, "%s\n", ascbuf);
  413|  3.12M|		p += asc_len + 1;
  414|  3.12M|		p_len -= asc_len + 1;
  415|  3.12M|		lines++;
  416|  3.12M|	}
  417|   393k|}
sc_dump_hex:
  421|   219k|{
  422|   219k|	static char dump_buf[0x1000];
  423|   219k|	size_t ii, size = sizeof(dump_buf) - 0x10;
  424|   219k|	size_t offs = 0;
  425|       |
  426|   219k|	memset(dump_buf, 0, sizeof(dump_buf));
  427|   219k|	if (in == NULL)
  ------------------
  |  Branch (427:6): [True: 0, False: 219k]
  ------------------
  428|      0|		return dump_buf;
  429|       |
  430|  1.30M|	for (ii=0; ii<count; ii++) {
  ------------------
  |  Branch (430:13): [True: 1.08M, False: 219k]
  ------------------
  431|  1.08M|		if (ii && !(ii%16))   {
  ------------------
  |  Branch (431:7): [True: 1.00M, False: 81.1k]
  |  Branch (431:13): [True: 22.6k, False: 984k]
  ------------------
  432|  22.6k|			if (!(ii%48))
  ------------------
  |  Branch (432:8): [True: 6.22k, False: 16.4k]
  ------------------
  433|  6.22k|				snprintf(dump_buf + offs, size - offs, "\n");
  434|  16.4k|			else
  435|  16.4k|				snprintf(dump_buf + offs, size - offs, " ");
  436|  22.6k|			offs = strlen(dump_buf);
  437|  22.6k|		}
  438|       |
  439|  1.08M|		snprintf(dump_buf + offs, size - offs, "%02X", *(in + ii));
  440|  1.08M|		offs += 2;
  441|       |
  442|  1.08M|		if (offs > size)
  ------------------
  |  Branch (442:7): [True: 0, False: 1.08M]
  ------------------
  443|      0|			break;
  444|  1.08M|	}
  445|       |
  446|   219k|	if (ii<count)
  ------------------
  |  Branch (446:6): [True: 0, False: 219k]
  ------------------
  447|      0|		snprintf(dump_buf + offs, sizeof(dump_buf) - offs, "....\n");
  448|       |
  449|   219k|	return dump_buf;
  450|   219k|}
sc_dump_oid:
  454|  7.53k|{
  455|  7.53k|	static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];
  456|  7.53k|        size_t ii;
  457|       |
  458|  7.53k|	memset(dump_buf, 0, sizeof(dump_buf));
  459|  7.53k|	if (oid)
  ------------------
  |  Branch (459:6): [True: 7.53k, False: 0]
  ------------------
  460|  57.3k|		for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS && oid->value[ii] != -1; ii++)
  ------------------
  |  |   46|   114k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (460:14): [True: 57.3k, False: 11]
  |  Branch (460:44): [True: 49.8k, False: 7.51k]
  ------------------
  461|  49.8k|			snprintf(dump_buf + strlen(dump_buf), sizeof(dump_buf) - strlen(dump_buf), "%s%i", (ii ? "." : ""), oid->value[ii]);
  ------------------
  |  Branch (461:88): [True: 42.2k, False: 7.53k]
  ------------------
  462|       |
  463|  7.53k|	return dump_buf;
  464|  7.53k|}
log.c:sc_do_log_va:
  123|  23.9M|{
  124|       |#ifdef _WIN32
  125|       |	SYSTEMTIME st;
  126|       |#else
  127|  23.9M|	struct tm *tm;
  128|  23.9M|	struct timeval tv;
  129|  23.9M|	char time_string[40];
  130|  23.9M|#endif
  131|       |
  132|  23.9M|	if (!ctx || ctx->debug < level)
  ------------------
  |  Branch (132:6): [True: 0, False: 23.9M]
  |  Branch (132:14): [True: 23.9M, False: 0]
  ------------------
  133|  23.9M|		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|    428|mscfs_t *mscfs_new(void) {
   45|    428|	mscfs_t *fs = malloc(sizeof(mscfs_t));
   46|    428|	if (!fs)
  ------------------
  |  Branch (46:6): [True: 0, False: 428]
  ------------------
   47|      0|		return NULL;
   48|    428|	memset(fs, 0, sizeof(mscfs_t));
   49|    428|	memcpy(fs->currentPath, "\x3F\x00", 2);
   50|    428|	return fs;
   51|    428|}
mscfs_free:
   53|    428|void mscfs_free(mscfs_t *fs) {
   54|    428|	mscfs_clear_cache(fs);
   55|    428|	free(fs);
   56|    428|}
mscfs_clear_cache:
   58|  1.57k|void mscfs_clear_cache(mscfs_t* fs) {
   59|  1.57k|	if(!fs->cache.array) {
  ------------------
  |  Branch (59:5): [True: 1.30k, False: 269]
  ------------------
   60|  1.30k|		return;
   61|  1.30k|	}
   62|    269|	free(fs->cache.array);
   63|       |	fs->cache.array = NULL;
   64|    269|	fs->cache.totalSize = 0;
   65|    269|	fs->cache.size = 0;
   66|    269|}
mscfs_push_file:
   82|  30.3k|{
   83|  30.3k|	mscfs_cache_t *cache = &fs->cache;
   84|  30.3k|	if (cache->size >= MAX_FILES)
  ------------------
  |  |   80|  30.3k|#define MAX_FILES 10000
  ------------------
  |  Branch (84:6): [True: 1, False: 30.3k]
  ------------------
   85|      1|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      1|#define SC_ERROR_INTERNAL			-1400
  ------------------
   86|  30.3k|	if(!cache->array || cache->size == cache->totalSize) {
  ------------------
  |  Branch (86:5): [True: 269, False: 30.1k]
  |  Branch (86:22): [True: 226, False: 29.8k]
  ------------------
   87|    495|		int length = cache->totalSize + MSCFS_CACHE_INCREMENT;
  ------------------
  |  |   34|    495|#define MSCFS_CACHE_INCREMENT 128
  ------------------
   88|    495|		mscfs_file_t *oldArray;
   89|    495|		cache->totalSize = length;
   90|    495|		oldArray = cache->array;
   91|    495|		cache->array = malloc(sizeof(mscfs_file_t) * length);
   92|    495|		if(!cache->array)
  ------------------
  |  Branch (92:6): [True: 0, False: 495]
  ------------------
   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|    495|		if(oldArray) {
  ------------------
  |  Branch (94:6): [True: 226, False: 269]
  ------------------
   95|    226|			memcpy(cache->array, oldArray, sizeof(mscfs_file_t) * cache->size);
   96|    226|			free(oldArray);
   97|    226|		}
   98|    495|	}
   99|  30.3k|	cache->array[cache->size] = *file;
  100|  30.3k|	cache->size++;
  101|  30.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  30.3k|#define SC_SUCCESS				0
  ------------------
  102|  30.3k|}
mscfs_update_cache:
  104|  1.14k|int mscfs_update_cache(mscfs_t* fs) {
  105|  1.14k|	mscfs_file_t file;
  106|  1.14k|	int r;
  107|  1.14k|	mscfs_clear_cache(fs);
  108|  1.14k|	r = fs->listFile(&file, 1, fs->udata);
  109|  1.14k|	if(r == 0)
  ------------------
  |  Branch (109:5): [True: 67, False: 1.08k]
  ------------------
  110|     67|		return 0;
  111|  1.08k|	else if(r < 0)
  ------------------
  |  Branch (111:10): [True: 784, False: 298]
  ------------------
  112|    784|		return r;
  113|  30.8k|	while(1) {
  ------------------
  |  Branch (113:8): [True: 30.8k, Folded]
  ------------------
  114|  30.8k|		if(!mscfs_is_ignored(fs, file.objectId)) {
  ------------------
  |  Branch (114:6): [True: 30.3k, False: 467]
  ------------------
  115|       |			/* Check if its a directory in the root */
  116|  30.3k|			u8* oid = file.objectId.id;
  117|  30.3k|			if(oid[2] == 0 && oid[3] == 0) {
  ------------------
  |  Branch (117:7): [True: 12.6k, False: 17.7k]
  |  Branch (117:22): [True: 6.17k, False: 6.47k]
  ------------------
  118|  6.17k|				oid[2] = oid[0];
  119|  6.17k|				oid[3] = oid[1];
  120|  6.17k|				oid[0] = 0x3F;
  121|  6.17k|				oid[1] = 0x00;
  122|  6.17k|				file.ef = 0;
  123|  24.1k|			} else  {
  124|  24.1k|				file.ef = 1; /* File is a working elementary file */
  125|  24.1k|			}
  126|       |
  127|  30.3k|			r = mscfs_push_file(fs, &file);
  128|  30.3k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  30.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (128:8): [True: 1, False: 30.3k]
  ------------------
  129|      1|				return r;
  130|  30.3k|		}
  131|  30.8k|		r = fs->listFile(&file, 0, fs->udata);
  132|  30.8k|		if(r == 0)
  ------------------
  |  Branch (132:6): [True: 114, False: 30.7k]
  ------------------
  133|    114|			break;
  134|  30.7k|		else if(r < 0)
  ------------------
  |  Branch (134:11): [True: 183, False: 30.5k]
  ------------------
  135|    183|			return r;
  136|  30.8k|	}
  137|    114|	return fs->cache.size;
  138|    298|}
mscfs_check_cache:
  141|  2.80k|{
  142|  2.80k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  2.80k|#define SC_SUCCESS				0
  ------------------
  143|  2.80k|	if(!fs->cache.array) {
  ------------------
  |  Branch (143:5): [True: 1.14k, False: 1.65k]
  ------------------
  144|  1.14k|		r = mscfs_update_cache(fs);
  145|  1.14k|	}
  146|  2.80k|	return r;
  147|  2.80k|}
mscfs_lookup_path:
  150|  1.16k|{
  151|  1.16k|	u8* oid = objectId->id;
  152|  1.16k|	if ((pathlen & 1) != 0) /* not divisible by 2 */
  ------------------
  |  Branch (152:6): [True: 484, False: 685]
  ------------------
  153|    484|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|    484|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|    484|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  154|    685|	if(isDirectory) {
  ------------------
  |  Branch (154:5): [True: 0, False: 685]
  ------------------
  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|    685|	oid[0] = fs->currentPath[0];
  166|    685|	oid[1] = fs->currentPath[1];
  167|       |	/* Chop off the root in the path */
  168|    685|	if(pathlen > 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (168:5): [True: 664, False: 21]
  |  Branch (168:20): [True: 656, False: 8]
  ------------------
  169|    656|		path += 2;
  170|    656|		pathlen -= 2;
  171|    656|		oid[0] = 0x3F;
  172|    656|		oid[1] = 0x00;
  173|    656|	}
  174|       |	/* Limit to a single directory */
  175|    685|	if(pathlen > 4)
  ------------------
  |  Branch (175:5): [True: 1, False: 684]
  ------------------
  176|      1|		return MSCFS_INVALID_ARGS;
  ------------------
  |  |   32|      1|#define MSCFS_INVALID_ARGS 	SC_ERROR_INVALID_ARGUMENTS
  |  |  ------------------
  |  |  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  |  |  ------------------
  ------------------
  177|       |	/* Reset to root */
  178|    684|	if(pathlen == 2 && 0 == memcmp(path, "\x3F\x00", 2)) {
  ------------------
  |  Branch (178:5): [True: 391, False: 293]
  |  Branch (178:21): [True: 1, False: 390]
  ------------------
  179|      1|		oid[0] = oid[2] = path[0];
  180|      1|		oid[1] = oid[3] = path[1];
  181|    683|	} else if(pathlen == 2) { /* Path preserved for current-path */
  ------------------
  |  Branch (181:12): [True: 390, False: 293]
  ------------------
  182|    390|		oid[2] = path[0];
  183|    390|		oid[3] = path[1];
  184|    390|	} else if(pathlen == 4) {
  ------------------
  |  Branch (184:12): [True: 293, False: 0]
  ------------------
  185|    293|		oid[0] = path[0];
  186|    293|		oid[1] = path[1];
  187|    293|		oid[2] = path[2];
  188|    293|		oid[3] = path[3];
  189|    293|	}
  190|       |
  191|    684|	return 0;
  192|    685|}
mscfs_check_selection:
  206|    367|{
  207|    367|	if(fs->currentPath[0] == 0 && fs->currentPath[1] == 0)
  ------------------
  |  Branch (207:5): [True: 0, False: 367]
  |  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|    367|	if(requiredItem == 1 && fs->currentFile[0] == 0 && fs->currentFile[1] == 0)
  ------------------
  |  Branch (209:5): [True: 0, False: 367]
  |  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|    367|	return 0;
  212|    367|}
mscfs_loadFileInfo:
  215|  1.16k|{
  216|  1.16k|	msc_id fullPath = {{0, 0, 0, 0}};
  217|  1.16k|	int x, rc;
  218|  1.16k|	if (fs == NULL || path == NULL || file_data == NULL)
  ------------------
  |  Branch (218:6): [True: 0, False: 1.16k]
  |  Branch (218:20): [True: 0, False: 1.16k]
  |  Branch (218:36): [True: 0, False: 1.16k]
  ------------------
  219|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  220|  1.16k|	rc = mscfs_lookup_path(fs, path, pathlen, &fullPath, 0);
  221|  1.16k|	if (rc != SC_SUCCESS) {
  ------------------
  |  |   28|  1.16k|#define SC_SUCCESS				0
  ------------------
  |  Branch (221:6): [True: 485, False: 684]
  ------------------
  222|    485|		return rc;
  223|    485|	}
  224|       |
  225|       |	/* Obtain file information while checking if it exists */
  226|    684|	rc = mscfs_check_cache(fs);
  227|    684|	if (rc < 0)
  ------------------
  |  Branch (227:6): [True: 21, False: 663]
  ------------------
  228|     21|		return rc;
  229|    663|	if(idx) *idx = -1;
  ------------------
  |  Branch (229:5): [True: 663, False: 0]
  ------------------
  230|  64.6k|	for(x = 0; x < fs->cache.size; x++) {
  ------------------
  |  Branch (230:13): [True: 64.2k, False: 427]
  ------------------
  231|  64.2k|		*file_data = &fs->cache.array[x];
  232|  64.2k|		if (*file_data) {
  ------------------
  |  Branch (232:7): [True: 64.2k, False: 0]
  ------------------
  233|  64.2k|			msc_id objectId;
  234|  64.2k|			objectId = (*file_data)->objectId;
  235|  64.2k|			if(0 == memcmp(objectId.id, fullPath.id, 4)) {
  ------------------
  |  Branch (235:7): [True: 236, False: 63.9k]
  ------------------
  236|    236|				if (idx)
  ------------------
  |  Branch (236:9): [True: 236, False: 0]
  ------------------
  237|    236|					*idx = x;
  238|    236|				break;
  239|    236|			}
  240|  63.9k|			*file_data = NULL;
  241|  63.9k|		}
  242|  64.2k|	}
  243|    663|	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: 427, False: 236]
  |  Branch (243:28): [True: 1, False: 426]
  |  Branch (243:79): [True: 223, False: 203]
  |  Branch (243:131): [True: 1, False: 202]
  ------------------
  244|    225|		static mscfs_file_t ROOT_FILE;
  245|    225|		ROOT_FILE.ef = 0;
  246|    225|		ROOT_FILE.size = 0;
  247|       |		/* Faked Root ID */
  248|    225|		ROOT_FILE.objectId = rootId;
  249|       |
  250|    225|		ROOT_FILE.read = 0;
  251|    225|		ROOT_FILE.write = 0x02; /* User Pin access */
  252|    225|		ROOT_FILE.delete = 0x02;
  253|       |
  254|    225|		*file_data = &ROOT_FILE;
  255|    225|		if(idx) *idx = -2;
  ------------------
  |  Branch (255:6): [True: 225, False: 0]
  ------------------
  256|    438|	} else if(*file_data == NULL) {
  ------------------
  |  Branch (256:12): [True: 202, False: 236]
  ------------------
  257|    202|		return MSCFS_FILE_NOT_FOUND;
  ------------------
  |  |   33|    202|#define MSCFS_FILE_NOT_FOUND 	SC_ERROR_FILE_NOT_FOUND
  |  |  ------------------
  |  |  |  |   51|    202|#define SC_ERROR_FILE_NOT_FOUND			-1201
  |  |  ------------------
  ------------------
  258|    202|	}
  259|       |
  260|    461|	return 0;
  261|    663|}
muscle-filesystem.c:mscfs_is_ignored:
   69|  30.8k|{
   70|  30.8k|	int ignored = 0;
   71|  30.8k|	const u8** ptr = ignoredFiles;
   72|  92.0k|	while(ptr && *ptr && !ignored) {
  ------------------
  |  Branch (72:8): [True: 92.0k, False: 0]
  |  Branch (72:15): [True: 61.6k, False: 30.3k]
  |  Branch (72:23): [True: 61.2k, False: 450]
  ------------------
   73|  61.2k|		if(0 == memcmp(objectId.id, *ptr, 4))
  ------------------
  |  Branch (73:6): [True: 467, False: 60.7k]
  ------------------
   74|    467|			ignored = 1;
   75|  61.2k|		ptr++;
   76|  61.2k|	}
   77|  30.8k|	return ignored;
   78|  30.8k|}

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

sc_pkcs1_strip_02_padding_constant_time:
  159|    183|{
  160|    183|	unsigned int i = 0;
  161|    183|	u8 *msg, *msg_orig = NULL;
  162|    183|	unsigned int good, found_zero_byte, mask, tmp_outlen;
  163|    183|	unsigned int zero_index = 0, msg_index, mlen = -1, len = 0;
  164|    183|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    183|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    183|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    183|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    183|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 183]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|       |
  166|    183|	if (data == NULL || out == NULL || data_len <= 0 || data_len > n ||
  ------------------
  |  Branch (166:6): [True: 0, False: 183]
  |  Branch (166:22): [True: 0, False: 183]
  |  Branch (166:37): [True: 47, False: 136]
  |  Branch (166:54): [True: 32, False: 104]
  ------------------
  167|    104|			n < SC_PKCS1_PADDING_MIN_SIZE || out_len == NULL)
  ------------------
  |  |   40|    287|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (167:4): [True: 0, False: 104]
  |  Branch (167:37): [True: 0, False: 104]
  ------------------
  168|    183|		LOG_FUNC_RETURN(ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|     79|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     79|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     79|	int _ret = r; \
  |  |  |  |  155|     79|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 79, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     79|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     79|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 79, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     79|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     79|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     79|	return _ret; \
  |  |  |  |  163|     79|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  169|       |
  170|    104|	tmp_outlen = *out_len;
  171|    104|	msg = msg_orig = calloc(n, sizeof(u8));
  172|    104|	if (msg == NULL)
  ------------------
  |  Branch (172:6): [True: 0, False: 104]
  ------------------
  173|    104|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  174|       |
  175|       |	/*
  176|       |	 * We can not check length of input data straight away and still we need to read
  177|       |	 * from input even when the input is not as long as needed to keep the time constant.
  178|       |	 * If data has wrong size, it is padded by zeroes from left and the following checks
  179|       |	 * do not pass.
  180|       |	 */
  181|    104|	len = data_len;
  182|  25.3k|	for (data += len, msg += n, i = 0; i < n; i++) {
  ------------------
  |  Branch (182:37): [True: 25.2k, False: 104]
  ------------------
  183|  25.2k|		mask = ~constant_time_is_zero(len);
  184|  25.2k|		len -= 1 & mask;
  185|  25.2k|		data -= 1 & mask;
  186|  25.2k|		*--msg = *data & mask;
  187|  25.2k|	}
  188|       |	// check first byte to be 0x00
  189|    104|	good = constant_time_is_zero(msg[0]);
  190|       |	// check second byte to be 0x02
  191|    104|	good &= constant_time_eq(msg[1], 2);
  192|       |
  193|       |	// find zero byte after random data in padding
  194|    104|	found_zero_byte = 0;
  195|  25.1k|	for (i = 2; i < n; i++) {
  ------------------
  |  Branch (195:14): [True: 25.0k, False: 104]
  ------------------
  196|  25.0k|		unsigned int equals0 = constant_time_is_zero(msg[i]);
  197|  25.0k|		zero_index = constant_time_select(~found_zero_byte & equals0, i, zero_index);
  198|  25.0k|		found_zero_byte |= equals0;
  199|  25.0k|	}
  200|       |
  201|       |	// zero_index stands for index of last found zero
  202|    104|	good &= constant_time_ge(zero_index, 2 + 8);
  203|       |
  204|       |	// start of the actual message in data
  205|    104|	msg_index = zero_index + 1;
  206|       |
  207|       |	// length of message
  208|    104|	mlen = data_len - msg_index;
  209|       |
  210|       |	// check that message fits into out buffer
  211|    104|	good &= constant_time_ge(tmp_outlen, mlen);
  212|       |
  213|       |	// move the result in-place by |num|-SC_PKCS1_PADDING_MIN_SIZE-|mlen| bytes to the left.
  214|    104|	tmp_outlen = constant_time_select(constant_time_lt(n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen),
  ------------------
  |  |   40|    104|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  215|    104|			n - SC_PKCS1_PADDING_MIN_SIZE, tmp_outlen);
  ------------------
  |  |   40|    104|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  216|    925|	for (msg_index = 1; msg_index < n - SC_PKCS1_PADDING_MIN_SIZE; msg_index <<= 1) {
  ------------------
  |  |   40|    925|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (216:22): [True: 821, False: 104]
  ------------------
  217|    821|		mask = ~constant_time_eq(msg_index & (n - SC_PKCS1_PADDING_MIN_SIZE - mlen), 0);
  ------------------
  |  |   40|    821|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  218|   169k|		for (i = SC_PKCS1_PADDING_MIN_SIZE; i < n - msg_index; i++)
  ------------------
  |  |   40|    821|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  |  Branch (218:39): [True: 169k, False: 821]
  ------------------
  219|   169k|			msg[i] = constant_time_select_8(mask, msg[i + msg_index], msg[i]);
  220|    821|	}
  221|       |	// move message into out buffer, if good
  222|  5.03k|	for (i = 0; i < tmp_outlen; i++) {
  ------------------
  |  Branch (222:14): [True: 4.93k, False: 104]
  ------------------
  223|  4.93k|		unsigned int msg_index;
  224|       |		// when out is longer than message in data, use some bogus index in msg
  225|  4.93k|		mask = good & constant_time_lt(i, mlen);
  226|  4.93k|		msg_index = constant_time_select(mask, i + SC_PKCS1_PADDING_MIN_SIZE, 0); // to now overflow msg buffer
  ------------------
  |  |   40|  4.93k|#define SC_PKCS1_PADDING_MIN_SIZE 11
  ------------------
  227|  4.93k|		out[i] = constant_time_select_8(mask, msg[msg_index], out[i]);
  228|  4.93k|	}
  229|       |
  230|    104|	*out_len = constant_time_select(good, mlen, *out_len);
  231|    104|	free(msg_orig);
  232|    104|	return constant_time_select(good, mlen, SC_ERROR_WRONG_PADDING);
  ------------------
  |  |   93|    104|#define SC_ERROR_WRONG_PADDING			-1412
  ------------------
  233|    104|}
sc_pkcs1_strip_digest_info_prefix:
  414|    199|{
  415|    199|	int i;
  416|       |
  417|    199|	if (in_dat == NULL)
  ------------------
  |  Branch (417:6): [True: 0, False: 199]
  ------------------
  418|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  419|       |
  420|  1.44k|	for (i = 0; digest_info_prefix[i].algorithm != 0; i++) {
  ------------------
  |  Branch (420:14): [True: 1.37k, False: 71]
  ------------------
  421|  1.37k|		size_t    hdr_len  = digest_info_prefix[i].hdr_len,
  422|  1.37k|		          hash_len = digest_info_prefix[i].hash_len;
  423|  1.37k|		const u8 *hdr      = digest_info_prefix[i].hdr;
  424|       |
  425|  1.37k|		if (in_len == (hdr_len + hash_len) &&
  ------------------
  |  Branch (425:7): [True: 166, False: 1.20k]
  ------------------
  426|    166|		    !memcmp(in_dat, hdr, hdr_len)) {
  ------------------
  |  Branch (426:7): [True: 128, False: 38]
  ------------------
  427|    128|			if (algorithm)
  ------------------
  |  Branch (427:8): [True: 0, False: 128]
  ------------------
  428|      0|				*algorithm = digest_info_prefix[i].algorithm;
  429|    128|			if (out_dat == NULL) {
  ------------------
  |  Branch (429:8): [True: 0, False: 128]
  ------------------
  430|       |				/* just check the DigestInfo prefix */
  431|      0|				if (out_len != NULL)
  ------------------
  |  Branch (431:9): [True: 0, False: 0]
  ------------------
  432|      0|					*out_len = hash_len;
  433|      0|				return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  434|      0|			}
  435|    128|			if (out_len == NULL || *out_len < hash_len)
  ------------------
  |  Branch (435:8): [True: 0, False: 128]
  |  Branch (435:27): [True: 0, False: 128]
  ------------------
  436|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  437|    128|			memmove(out_dat, in_dat + hdr_len, hash_len);
  438|    128|			*out_len = hash_len;
  439|    128|			return SC_SUCCESS;
  ------------------
  |  |   28|    128|#define SC_SUCCESS				0
  ------------------
  440|    128|		}
  441|  1.37k|	}
  442|     71|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     71|#define SC_ERROR_INTERNAL			-1400
  ------------------
  443|    199|}
sc_pkcs1_encode:
  629|  6.45k|{
  630|  6.45k|	int    rv, i;
  631|  6.45k|	size_t tmp_len;
  632|  6.45k|	const u8    *tmp = in;
  633|  6.45k|	unsigned int hash_algo, pad_algo;
  634|  6.45k|	size_t mod_len = BYTES4BITS(mod_bits);
  ------------------
  |  |  145|  6.45k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  635|  6.45k|#ifdef ENABLE_OPENSSL
  636|  6.45k|	size_t sLen;
  637|  6.45k|	EVP_MD* md = NULL;
  638|  6.45k|	unsigned int mgf1_hash;
  639|  6.45k|#endif
  640|       |
  641|  6.45k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.45k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.45k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  642|       |
  643|  6.45k|	if (out == NULL || out_len == NULL || (in_len > 0 && in == NULL))
  ------------------
  |  Branch (643:6): [True: 0, False: 6.45k]
  |  Branch (643:21): [True: 0, False: 6.45k]
  |  Branch (643:41): [True: 4.48k, False: 1.96k]
  |  Branch (643:55): [True: 0, False: 4.48k]
  ------------------
  644|  6.45k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  645|       |
  646|  6.45k|	tmp_len = *out_len;
  647|       |
  648|  6.45k|	hash_algo = flags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|  6.45k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  649|  6.45k|	pad_algo  = flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|  6.45k|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  650|  6.45k|	if (pad_algo == 0)
  ------------------
  |  Branch (650:6): [True: 20, False: 6.43k]
  ------------------
  651|     20|		pad_algo = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|     20|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  652|  6.45k|	sc_log(ctx, "hash algorithm 0x%X, pad algorithm 0x%X", hash_algo, pad_algo);
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  653|       |
  654|  6.45k|	if ((pad_algo == SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 || pad_algo == SC_ALGORITHM_RSA_PAD_NONE) &&
  ------------------
  |  |  109|  12.9k|#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|  5.70k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (654:7): [True: 752, False: 5.70k]
  |  Branch (654:57): [True: 20, False: 5.68k]
  ------------------
  655|    772|	    hash_algo != SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|    772|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (655:6): [True: 752, False: 20]
  ------------------
  656|    752|		i = sc_pkcs1_add_digest_info_prefix(hash_algo, in, in_len, out, &tmp_len);
  657|    752|		if (i != SC_SUCCESS) {
  ------------------
  |  |   28|    752|#define SC_SUCCESS				0
  ------------------
  |  Branch (657:7): [True: 752, False: 0]
  ------------------
  658|    752|			sc_log(ctx, "Unable to add digest info 0x%x", hash_algo);
  ------------------
  |  |   71|    752|#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|    752|			LOG_FUNC_RETURN(ctx, i);
  ------------------
  |  |  164|    752|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    752|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    752|	int _ret = r; \
  |  |  |  |  155|    752|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 752, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    752|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    752|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 752, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    752|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    752|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    752|	return _ret; \
  |  |  |  |  163|    752|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  660|    752|		}
  661|      0|		tmp = out;
  662|  5.70k|	} else   {
  663|  5.70k|		tmp_len = in_len;
  664|  5.70k|	}
  665|       |
  666|  5.70k|	switch(pad_algo) {
  667|     20|	case SC_ALGORITHM_RSA_PAD_NONE:
  ------------------
  |  |  104|     20|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (667:2): [True: 20, False: 5.68k]
  ------------------
  668|       |		/* padding done by card => nothing to do */
  669|     20|		if (out != tmp)
  ------------------
  |  Branch (669:7): [True: 20, False: 0]
  ------------------
  670|     20|			memcpy(out, tmp, tmp_len);
  671|     20|		*out_len = tmp_len;
  672|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  673|      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 (673:2): [True: 0, False: 5.70k]
  ------------------
  674|       |		/* add pkcs1 bt01 padding */
  675|      0|		rv = sc_pkcs1_add_01_padding(tmp, tmp_len, out, out_len, mod_len);
  676|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|  5.68k|	case SC_ALGORITHM_RSA_PAD_PSS:
  ------------------
  |  |  107|  5.68k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (677:2): [True: 5.68k, False: 20]
  ------------------
  678|       |		/* add PSS padding */
  679|  5.68k|#ifdef ENABLE_OPENSSL
  680|  5.68k|		mgf1_hash = flags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  150|  5.68k|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  681|  5.68k|		if (hash_algo == SC_ALGORITHM_RSA_HASH_NONE) {
  ------------------
  |  |  133|  5.68k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (681:7): [True: 0, False: 5.68k]
  ------------------
  682|       |			/* this is generic RSA_PKCS1_PSS mechanism with hash
  683|       |			 * already done outside of the module. The parameters
  684|       |			 * were already checked so we need to adjust the hash
  685|       |			 * algorithm to do the padding with the correct hash
  686|       |			 * function.
  687|       |			 */
  688|      0|			hash_algo = hash_len2algo(tmp_len);
  689|      0|		}
  690|       |		/* sLen is by default same as hash length */
  691|  5.68k|		if (!(md = hash_flag2md(ctx, hash_algo))) {
  ------------------
  |  Branch (691:7): [True: 5.68k, False: 0]
  ------------------
  692|  5.68k|			sc_log_openssl(ctx);
  ------------------
  |  |   72|  5.68k|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  693|  5.68k|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|  5.68k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  694|  5.68k|		}
  695|      0|		sLen = EVP_MD_size(md);
  696|      0|		sc_evp_md_free(md);
  697|       |		/* if application provide sLen, use it */
  698|      0|		if (pMechanism != NULL) {
  ------------------
  |  Branch (698:7): [True: 0, False: 0]
  ------------------
  699|      0|			CK_MECHANISM *mech = (CK_MECHANISM *)pMechanism;
  700|      0|			CK_RSA_PKCS_PSS_PARAMS *pss_params;
  701|      0|			if (mech->pParameter && sizeof(CK_RSA_PKCS_PSS_PARAMS) == mech->ulParameterLen) {
  ------------------
  |  Branch (701:8): [True: 0, False: 0]
  |  Branch (701:28): [True: 0, False: 0]
  ------------------
  702|      0|				pss_params = mech->pParameter;
  703|      0|				sLen = pss_params->sLen;
  704|      0|			}
  705|      0|		}
  706|      0|		rv = sc_pkcs1_add_pss_padding(ctx, hash_algo, mgf1_hash,
  707|      0|		    tmp, tmp_len, out, out_len, mod_bits, sLen);
  708|       |#else
  709|       |		rv = SC_ERROR_NOT_SUPPORTED;
  710|       |#endif
  711|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  712|      0|	default:
  ------------------
  |  Branch (712:2): [True: 0, False: 5.70k]
  ------------------
  713|       |		/* We shouldn't be called with an unexpected padding type, we've already
  714|       |		 * returned SC_ERROR_NOT_SUPPORTED if the card can't be used. */
  715|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  716|  5.70k|	}
  717|  5.70k|}
sc_get_encoding_flags:
  722|  58.7k|{
  723|  58.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  58.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  58.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  58.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  58.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 58.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|  58.7k|	if (pflags == NULL || sflags == NULL)
  ------------------
  |  Branch (724:6): [True: 0, False: 58.7k]
  |  Branch (724:24): [True: 0, False: 58.7k]
  ------------------
  725|  58.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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  726|       |
  727|  58.7k|	sc_log(ctx, "iFlags 0x%lX, card capabilities 0x%lX", iflags, caps);
  ------------------
  |  |   71|  58.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__
  |  |  ------------------
  ------------------
  728|       |
  729|       |	/* For ECDSA and GOSTR, we don't do any padding or hashing ourselves, the
  730|       |	 * card has to support the requested operation.  Similarly, for RSA with
  731|       |	 * raw padding (raw RSA) and ISO9796, we require the card to do it for us.
  732|       |	 * Finally, for PKCS1 (v1.5 and PSS) and ASNI X9.31 we can apply the padding
  733|       |	 * ourselves if the card supports raw RSA. */
  734|       |
  735|       |	/* TODO: Could convert GOSTR3410_HASH_GOSTR3411 -> GOSTR3410_RAW and
  736|       |	 *       ECDSA_HASH_ -> ECDSA_RAW using OpenSSL (not much benefit though). */
  737|       |
  738|  58.7k|	if ((caps & iflags) == iflags) {
  ------------------
  |  Branch (738:6): [True: 11.7k, False: 46.9k]
  ------------------
  739|       |		/* Card supports the signature operation we want to do, great, let's
  740|       |		 * go with it then. */
  741|  11.7k|		*sflags = iflags;
  742|  11.7k|		*pflags = 0;
  743|       |
  744|  46.9k|	} else if ((caps & SC_ALGORITHM_RSA_PAD_PSS) &&
  ------------------
  |  |  107|  46.9k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (744:13): [True: 4.11k, False: 42.8k]
  ------------------
  745|  4.11k|			(iflags & SC_ALGORITHM_RSA_PAD_PSS)) {
  ------------------
  |  |  107|  4.11k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (745:4): [True: 1.21k, False: 2.89k]
  ------------------
  746|  1.21k|		*sflags |= SC_ALGORITHM_RSA_PAD_PSS;
  ------------------
  |  |  107|  1.21k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  747|  1.21k|		*sflags |= iflags & SC_ALGORITHM_MGF1_HASHES;
  ------------------
  |  |  150|  1.21k|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
  748|  1.21k|		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  150|  1.21k|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
              		*pflags = iflags & ~(iflags & (SC_ALGORITHM_MGF1_HASHES | SC_ALGORITHM_RSA_PAD_PSS));
  ------------------
  |  |  107|  1.21k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  749|       |
  750|  45.7k|	} else if ((caps & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|  45.7k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (750:13): [True: 24.6k, False: 21.0k]
  ------------------
  751|  24.6k|				(iflags & SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  111|  49.3k|#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.6k|#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.6k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (751:6): [True: 2.34k, False: 22.3k]
  ------------------
  752|  22.3k|				|| iflags & SC_ALGORITHM_RSA_PAD_PSS
  ------------------
  |  |  107|  47.0k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (752:8): [True: 5.68k, False: 16.6k]
  ------------------
  753|  16.6k|#ifdef ENABLE_OPENSSL
  754|  16.6k|				|| iflags & SC_ALGORITHM_RSA_PAD_OAEP
  ------------------
  |  |  108|  41.3k|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (754:8): [True: 0, False: 16.6k]
  ------------------
  755|  16.6k|#endif
  756|  16.6k|				|| iflags & SC_ALGORITHM_RSA_PAD_NONE)) {
  ------------------
  |  |  104|  16.6k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (756:8): [True: 0, False: 16.6k]
  ------------------
  757|       |		/* Use the card's raw RSA capability on the padded input */
  758|  8.02k|		*sflags = SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  104|  8.02k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  759|  8.02k|		*pflags = iflags;
  760|       |
  761|  37.7k|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|  37.7k|#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|  37.7k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (761:13): [True: 27.4k, False: 10.3k]
  ------------------
  762|  27.4k|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)) {
  ------------------
  |  |  109|  27.4k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (762:4): [True: 327, False: 27.1k]
  ------------------
  763|       |		/* A corner case - the card can partially do PKCS1, if we prepend the
  764|       |		 * DigestInfo bit it will do the rest. */
  765|    327|		*sflags = SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  109|    327|#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|    327|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  766|    327|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|    327|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  767|       |
  768|  37.4k|	} else if ((caps & (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  110|  37.4k|#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|  37.4k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (768:13): [True: 27.1k, False: 10.3k]
  ------------------
  769|  27.1k|			(iflags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)) {
  ------------------
  |  |  110|  27.1k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (769:4): [True: 0, False: 27.1k]
  ------------------
  770|      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 */
  ------------------
  771|      0|		*pflags = iflags & SC_ALGORITHM_RSA_HASHES;
  ------------------
  |  |  142|      0|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  772|       |
  773|  37.4k|	} 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|  37.4k|#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|  37.4k|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (773:13): [True: 0, False: 37.4k]
  ------------------
  774|      0|		*sflags = 0;
  775|      0|		*pflags = 0;
  776|       |
  777|  37.4k|	} else if ((iflags & SC_ALGORITHM_AES_FLAGS) > 0) {
  ------------------
  |  |  209|  37.4k|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  |  Branch (777:13): [True: 1.24k, False: 36.1k]
  ------------------
  778|  1.24k|		*sflags = iflags & SC_ALGORITHM_AES_FLAGS;
  ------------------
  |  |  209|  1.24k|#define SC_ALGORITHM_AES_FLAGS		 0x0F000000
  ------------------
  779|  1.24k|		if (iflags & SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  208|  1.24k|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (779:7): [True: 0, False: 1.24k]
  ------------------
  780|      0|			*pflags = SC_ALGORITHM_AES_CBC_PAD;
  ------------------
  |  |  208|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  781|  1.24k|		else
  782|  1.24k|			*pflags = 0;
  783|       |
  784|  36.1k|	} else {
  785|  36.1k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported algorithm");
  ------------------
  |  |  174|  36.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  36.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  36.1k|	int _ret = (r); \
  |  |  |  |  168|  36.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 36.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  36.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|  36.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  36.1k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  36.1k|		return _ret; \
  |  |  |  |  172|  36.1k|	} \
  |  |  |  |  173|  36.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  786|  36.1k|	}
  787|       |
  788|  22.6k|	sc_log(ctx, "pad flags 0x%lX, secure algorithm flags 0x%lX", *pflags, *sflags);
  ------------------
  |  |   71|  22.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__
  |  |  ------------------
  ------------------
  789|  22.6k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  22.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  22.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  22.6k|	int _ret = r; \
  |  |  |  |  155|  22.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.6k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 22.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.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|  22.6k|	return _ret; \
  |  |  |  |  163|  22.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  790|  22.6k|}
padding.c:hash_flag2md:
  448|  5.68k|{
  449|  5.68k|	switch (hash & SC_ALGORITHM_RSA_HASHES) {
  ------------------
  |  |  142|  5.68k|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  450|      0|	case SC_ALGORITHM_RSA_HASH_SHA1:
  ------------------
  |  |  134|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (450:2): [True: 0, False: 5.68k]
  ------------------
  451|      0|		return sc_evp_md(ctx, "SHA1");
  ------------------
  |  |   87|      0|#define sc_evp_md(ctx, alg) _sc_evp_md((ctx)->ossl3ctx, alg)
  ------------------
  452|      0|	case SC_ALGORITHM_RSA_HASH_SHA224:
  ------------------
  |  |  141|      0|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  ------------------
  |  Branch (452:2): [True: 0, False: 5.68k]
  ------------------
  453|      0|		return sc_evp_md(ctx, "SHA224");
  ------------------
  |  |   87|      0|#define sc_evp_md(ctx, alg) _sc_evp_md((ctx)->ossl3ctx, alg)
  ------------------
  454|      0|	case SC_ALGORITHM_RSA_HASH_SHA256:
  ------------------
  |  |  138|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (454:2): [True: 0, False: 5.68k]
  ------------------
  455|      0|		return sc_evp_md(ctx, "SHA256");
  ------------------
  |  |   87|      0|#define sc_evp_md(ctx, alg) _sc_evp_md((ctx)->ossl3ctx, alg)
  ------------------
  456|      0|	case SC_ALGORITHM_RSA_HASH_SHA384:
  ------------------
  |  |  139|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  |  Branch (456:2): [True: 0, False: 5.68k]
  ------------------
  457|      0|		return sc_evp_md(ctx, "SHA384");
  ------------------
  |  |   87|      0|#define sc_evp_md(ctx, alg) _sc_evp_md((ctx)->ossl3ctx, alg)
  ------------------
  458|      0|	case SC_ALGORITHM_RSA_HASH_SHA512:
  ------------------
  |  |  140|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  |  Branch (458:2): [True: 0, False: 5.68k]
  ------------------
  459|      0|		return sc_evp_md(ctx, "SHA512");
  ------------------
  |  |   87|      0|#define sc_evp_md(ctx, alg) _sc_evp_md((ctx)->ossl3ctx, alg)
  ------------------
  460|  5.68k|	default:
  ------------------
  |  Branch (460:2): [True: 5.68k, False: 0]
  ------------------
  461|       |		return NULL;
  462|  5.68k|	}
  463|  5.68k|}
padding.c:sc_pkcs1_add_digest_info_prefix:
  386|    752|{
  387|    752|	int i;
  388|       |
  389|    752|	if (in == NULL || out == NULL || out_len == NULL)
  ------------------
  |  Branch (389:6): [True: 0, False: 752]
  |  Branch (389:20): [True: 0, False: 752]
  |  Branch (389:35): [True: 0, False: 752]
  ------------------
  390|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  391|       |
  392|  7.52k|	for (i = 0; digest_info_prefix[i].algorithm != 0; i++) {
  ------------------
  |  Branch (392:14): [True: 6.76k, False: 752]
  ------------------
  393|  6.76k|		if (algorithm == digest_info_prefix[i].algorithm) {
  ------------------
  |  Branch (393:7): [True: 0, False: 6.76k]
  ------------------
  394|      0|			const u8 *hdr      = digest_info_prefix[i].hdr;
  395|      0|			size_t    hdr_len  = digest_info_prefix[i].hdr_len,
  396|      0|			          hash_len = digest_info_prefix[i].hash_len;
  397|       |
  398|      0|			if (in_len != hash_len || *out_len < (hdr_len + hash_len))
  ------------------
  |  Branch (398:8): [True: 0, False: 0]
  |  Branch (398:30): [True: 0, False: 0]
  ------------------
  399|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  400|       |
  401|      0|			memmove(out + hdr_len, in, hash_len);
  402|      0|			memmove(out, hdr, hdr_len);
  403|      0|			*out_len = hdr_len + hash_len;
  404|       |
  405|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  406|      0|		}
  407|  6.76k|	}
  408|       |
  409|    752|	return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    752|#define SC_ERROR_INTERNAL			-1400
  ------------------
  410|    752|}

sc_asn1_decode_algorithm_id:
  509|  5.47k|{
  510|  5.47k|	struct sc_asn1_pkcs15_algorithm_info *alg_info = NULL;
  511|  5.47k|	struct sc_asn1_entry asn1_alg_id[3];
  512|  5.47k|	int r;
  513|       |
  514|  5.47k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  5.47k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.47k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.47k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.47k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.47k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|  5.47k|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  516|  5.47k|	sc_format_asn1_entry(asn1_alg_id + 0, &id->oid, NULL, 0);
  517|       |
  518|  5.47k|	memset(id, 0, sizeof(*id));
  519|  5.47k|	r = _sc_asn1_decode(ctx, asn1_alg_id, in, len, &in, &len, 0, depth + 1);
  520|  5.47k|	LOG_TEST_RET(ctx, r, "ASN.1 parsing of algo ID failed");
  ------------------
  |  |  174|  5.47k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.47k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.47k|	int _ret = (r); \
  |  |  |  |  168|  5.47k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 30, False: 5.44k]
  |  |  |  |  ------------------
  |  |  |  |  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|  5.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.44k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  521|       |
  522|  5.44k|        sc_log(ctx, "decoded OID '%s'", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|  5.44k|#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.44k|	id->algorithm = (unsigned int ) -1;
  527|  5.44k|	alg_info = sc_asn1_get_algorithm_info(id);
  528|  5.44k|	if (alg_info != NULL) {
  ------------------
  |  Branch (528:6): [True: 2.82k, False: 2.61k]
  ------------------
  529|  2.82k|		id->algorithm = alg_info->id;
  530|  2.82k|		if (alg_info->decode) {
  ------------------
  |  Branch (530:7): [True: 1.25k, False: 1.56k]
  ------------------
  531|  1.25k|			if (asn1_alg_id[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|  1.25k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (531:8): [True: 10, False: 1.24k]
  ------------------
  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.24k|			r = alg_info->decode(ctx, &id->params, in, len, depth);
  536|  1.24k|		}
  537|  2.82k|	}
  538|       |
  539|  5.43k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  5.43k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.43k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.43k|	int _ret = r; \
  |  |  |  |  155|  5.43k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.43k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|     44|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 44, False: 5.38k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.43k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.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|  5.43k|	return _ret; \
  |  |  |  |  163|  5.43k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  540|  5.43k|}
sc_asn1_encode_algorithm_id:
  546|  2.08k|{
  547|  2.08k|	struct sc_asn1_pkcs15_algorithm_info *alg_info;
  548|  2.08k|	struct sc_algorithm_id temp_id;
  549|  2.08k|	struct sc_asn1_entry asn1_alg_id[3];
  550|  2.08k|	u8 *obj = NULL;
  551|  2.08k|	size_t obj_len = 0;
  552|  2.08k|	int r;
  553|  2.08k|	u8 *tmp;
  554|       |
  555|  2.08k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.08k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.08k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.08k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.08k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  556|  2.08k|        sc_log(ctx, "type of algorithm to encode: %lu", id->algorithm);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  557|  2.08k|	alg_info = sc_asn1_get_algorithm_info(id);
  558|  2.08k|	if (alg_info == NULL) {
  ------------------
  |  Branch (558:6): [True: 0, False: 2.08k]
  ------------------
  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.08k|	if (!sc_valid_oid(&id->oid)) {
  ------------------
  |  Branch (564:6): [True: 0, False: 2.08k]
  ------------------
  565|      0|		temp_id = *id;
  566|      0|		temp_id.oid = alg_info->oid;
  567|      0|		id = &temp_id;
  568|      0|	}
  569|       |
  570|  2.08k|        sc_log(ctx, "encode algo %s", sc_dump_oid(&(id->oid)));
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  571|  2.08k|	sc_copy_asn1_entry(c_asn1_alg_id, asn1_alg_id);
  572|  2.08k|	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.08k|	if (id->algorithm != SC_ALGORITHM_EDDSA &&
  ------------------
  |  |   72|  4.17k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (578:6): [True: 2.08k, False: 0]
  ------------------
  579|  2.08k|	    id->algorithm != SC_ALGORITHM_XEDDSA &&
  ------------------
  |  |   73|  4.17k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (579:6): [True: 2.08k, False: 0]
  ------------------
  580|  2.08k|	    (!id->params || !alg_info->encode))
  ------------------
  |  Branch (580:7): [True: 1.08k, False: 1.00k]
  |  Branch (580:22): [True: 0, False: 1.00k]
  ------------------
  581|  1.08k|		asn1_alg_id[1].flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  171|  1.08k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  582|       |
  583|  2.08k|	r = _sc_asn1_encode(ctx, asn1_alg_id, buf, len, depth + 1);
  584|  2.08k|	LOG_TEST_RET(ctx, r, "ASN.1 encode of algorithm failed");
  ------------------
  |  |  174|  2.08k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.08k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.08k|	int _ret = (r); \
  |  |  |  |  168|  2.08k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.08k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|       |	/* Encode any parameters */
  587|  2.08k|	if (id->params && alg_info->encode) {
  ------------------
  |  Branch (587:6): [True: 1.00k, False: 1.08k]
  |  Branch (587:20): [True: 1.00k, False: 0]
  ------------------
  588|  1.00k|		r = alg_info->encode(ctx, id->params, &obj, &obj_len, depth+1);
  589|  1.00k|		if (r < 0) {
  ------------------
  |  Branch (589:7): [True: 0, False: 1.00k]
  ------------------
  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.00k|	}
  595|       |
  596|  2.08k|	if (obj_len) {
  ------------------
  |  Branch (596:6): [True: 1.00k, False: 1.08k]
  ------------------
  597|  1.00k|		tmp = (u8 *) realloc(*buf, *len + obj_len);
  598|  1.00k|		if (!tmp) {
  ------------------
  |  Branch (598:7): [True: 0, False: 1.00k]
  ------------------
  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.00k|		*buf = tmp;
  605|  1.00k|		memcpy(*buf + *len, obj, obj_len);
  606|  1.00k|		*len += obj_len;
  607|  1.00k|		free(obj);
  608|  1.00k|	}
  609|       |
  610|  2.08k|	sc_log(ctx, "return encoded algorithm ID: %s", sc_dump_hex(*buf, *len));
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
  611|  2.08k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.08k|	int _ret = r; \
  |  |  |  |  155|  2.08k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.08k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.08k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.08k|	return _ret; \
  |  |  |  |  163|  2.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|  2.08k|}
sc_asn1_clear_algorithm_id:
  616|  7.15k|{
  617|  7.15k|	struct sc_asn1_pkcs15_algorithm_info *aip;
  618|       |
  619|  7.15k|	if (id->params && (aip = sc_asn1_get_algorithm_info(id)) && aip->free) {
  ------------------
  |  Branch (619:6): [True: 2.16k, False: 4.99k]
  |  Branch (619:20): [True: 2.16k, False: 0]
  |  Branch (619:62): [True: 2.16k, False: 0]
  ------------------
  620|  2.16k|		aip->free(id->params);
  621|       |		id->params = NULL;
  622|  2.16k|	}
  623|  7.15k|}
pkcs15-algo.c:sc_asn1_get_algorithm_info:
  485|  9.69k|{
  486|  9.69k|	struct sc_asn1_pkcs15_algorithm_info *aip = NULL;
  487|       |
  488|   123k|	for (aip = algorithm_table; aip->id >= 0; aip++)   {
  ------------------
  |  Branch (488:30): [True: 120k, False: 2.61k]
  ------------------
  489|   120k|		if ((int) id->algorithm < 0 && sc_compare_oid(&id->oid, &aip->oid))
  ------------------
  |  Branch (489:7): [True: 73.8k, False: 46.8k]
  |  Branch (489:34): [True: 2.82k, False: 71.0k]
  ------------------
  490|  2.82k|			return aip;
  491|       |
  492|   117k|		if (aip->id == (int)id->algorithm)
  ------------------
  |  Branch (492:7): [True: 4.25k, False: 113k]
  ------------------
  493|  4.25k|			return aip;
  494|   117k|	}
  495|       |
  496|  2.61k|	return NULL;
  497|  9.69k|}
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.22k|{
  265|  1.22k|	int r;
  266|  1.22k|	struct sc_object_id curve;
  267|  1.22k|	struct sc_asn1_entry asn1_ec_params[4];
  268|  1.22k|	struct sc_ec_parameters *ecp;
  269|       |
  270|  1.22k|	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.22k|	sc_copy_asn1_entry(c_asn1_ec_params, asn1_ec_params);
  276|  1.22k|	sc_format_asn1_entry(asn1_ec_params + 1, &curve, 0, 0);
  277|       |
  278|       |	/* Some signature algorithms will not have any data */
  279|  1.22k|	if (buflen == 0 || buf == NULL)
  ------------------
  |  Branch (279:6): [True: 48, False: 1.17k]
  |  Branch (279:21): [True: 0, False: 1.17k]
  ------------------
  280|     48|		return 0;
  281|       |
  282|  1.17k|	r = sc_asn1_decode_choice(ctx, asn1_ec_params, buf, buflen, NULL, NULL);
  283|       |	/* r = index in asn1_ec_params */
  284|  1.17k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_decode_ec_params r=%d", r);
  ------------------
  |  |   70|  1.17k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  285|  1.17k|	if (r < 0)
  ------------------
  |  Branch (285:6): [True: 22, False: 1.15k]
  ------------------
  286|     22|		return r;
  287|       |
  288|  1.15k|	ecp = calloc(1, sizeof(struct sc_ec_parameters));
  289|  1.15k|	if (ecp == NULL)
  ------------------
  |  Branch (289:6): [True: 0, False: 1.15k]
  ------------------
  290|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  291|       |
  292|  1.15k|	if (r <= 1) {
  ------------------
  |  Branch (292:6): [True: 1.15k, False: 0]
  ------------------
  293|  1.15k|		ecp->der.value = malloc(buflen);
  294|  1.15k|		if (ecp->der.value == NULL) {
  ------------------
  |  Branch (294:7): [True: 0, False: 1.15k]
  ------------------
  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.15k|		ecp->der.len = buflen;
  299|  1.15k|		memcpy(ecp->der.value, buf, buflen);
  300|  1.15k|	}
  301|      0|	else    {
  302|      0|		r = 0;
  303|      0|	}
  304|       |
  305|  1.15k|	ecp->type = r; /* but 0 = ecparams if any, 1=named curve */
  306|  1.15k|	*paramp = ecp;
  307|  1.15k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.15k|#define SC_SUCCESS				0
  ------------------
  308|  1.15k|};
pkcs15-algo.c:asn1_encode_ec_params:
  313|  1.00k|{
  314|  1.00k|	 struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  315|       |
  316|       |	/* Only handle named curves. They may be absent too */
  317|  1.00k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "asn1_encode_ec_params() called");
  ------------------
  |  |   70|  1.00k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  318|  1.00k|	*buf = NULL;
  319|  1.00k|	*buflen = 0;
  320|  1.00k|	if (ecp && ecp->type == 1 && ecp->der.value) { /* named curve */
  ------------------
  |  Branch (320:6): [True: 1.00k, False: 0]
  |  Branch (320:13): [True: 1.00k, False: 0]
  |  Branch (320:31): [True: 1.00k, False: 0]
  ------------------
  321|  1.00k|		*buf = malloc(ecp->der.len);
  322|  1.00k|		if (*buf == NULL)
  ------------------
  |  Branch (322:7): [True: 0, False: 1.00k]
  ------------------
  323|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  324|       |
  325|  1.00k|		memcpy(*buf, ecp->der.value, ecp->der.len);
  326|  1.00k|		*buflen = ecp->der.len;
  327|  1.00k|	}
  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.00k|	return 0;
  333|  1.00k|}
pkcs15-algo.c:asn1_free_ec_params:
  337|  2.16k|{
  338|  2.16k|	struct sc_ec_parameters *ecp = (struct sc_ec_parameters *) params;
  339|       |
  340|  2.16k|	if (ecp) {
  ------------------
  |  Branch (340:6): [True: 2.16k, False: 0]
  ------------------
  341|  2.16k|		if (ecp->der.value)
  ------------------
  |  Branch (341:7): [True: 2.16k, False: 0]
  ------------------
  342|  2.16k|			free(ecp->der.value);
  343|  2.16k|		if (ecp->named_curve)
  ------------------
  |  Branch (343:7): [True: 0, False: 2.16k]
  ------------------
  344|      0|			free(ecp->named_curve);
  345|  2.16k|		free(ecp);
  346|  2.16k|	}
  347|  2.16k|}

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

sc_pkcs15_read_cached_file:
  134|  7.33k|{
  135|  7.33k|	char fname[PATH_MAX];
  136|  7.33k|	int rv;
  137|  7.33k|	FILE *f;
  138|  7.33k|	size_t count;
  139|  7.33k|	struct stat stbuf;
  140|  7.33k|	u8 *data = NULL;
  141|       |
  142|  7.33k|	if (path->len < 2)
  ------------------
  |  Branch (142:6): [True: 2.94k, False: 4.39k]
  ------------------
  143|  2.94k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.94k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  144|       |
  145|       |	/* Accept full path or FILE-ID path with AID */
  146|  4.39k|	if ((path->type != SC_PATH_TYPE_PATH) && (path->type != SC_PATH_TYPE_FILE_ID || path->aid.len == 0))
  ------------------
  |  |  119|  4.39k|#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.68k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (146:6): [True: 1.84k, False: 2.55k]
  |  Branch (146:44): [True: 0, False: 1.84k]
  |  Branch (146:82): [True: 468, False: 1.37k]
  ------------------
  147|    468|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    468|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  148|       |
  149|  3.92k|	sc_log(p15card->card->ctx, "try to read cache for %s", sc_print_path(path));
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  150|  3.92k|	rv = generate_cache_filename(p15card, path, fname, sizeof(fname));
  151|  3.92k|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|  3.92k|#define SC_SUCCESS				0
  ------------------
  |  Branch (151:6): [True: 789, False: 3.13k]
  ------------------
  152|    789|		return rv;
  153|  3.13k|	sc_log(p15card->card->ctx, "read cached file %s", fname);
  ------------------
  |  |   71|  3.13k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  154|       |
  155|  3.13k|	f = fopen(fname, "rb");
  156|  3.13k|	if (!f)
  ------------------
  |  Branch (156:6): [True: 2.46k, False: 667]
  ------------------
  157|  2.46k|		return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  2.46k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  158|    667|	if (fstat(fileno(f), &stbuf))   {
  ------------------
  |  Branch (158:6): [True: 0, False: 667]
  ------------------
  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|    667|	if (path->count < 0) {
  ------------------
  |  Branch (163:6): [True: 338, False: 329]
  ------------------
  164|    338|		count = stbuf.st_size;
  165|    338|	}
  166|    329|	else {
  167|    329|		count = path->count;
  168|    329|		if (path->index + count > (size_t)stbuf.st_size)   {
  ------------------
  |  Branch (168:7): [True: 329, False: 0]
  ------------------
  169|    329|			rv = SC_ERROR_FILE_NOT_FOUND; /* cache file bad? */
  ------------------
  |  |   51|    329|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  170|    329|			goto err;
  171|    329|		}
  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|    338|	if (*buf == NULL) {
  ------------------
  |  Branch (179:6): [True: 335, False: 3]
  ------------------
  180|    335|		if (count == 0) {
  ------------------
  |  Branch (180:7): [True: 206, False: 129]
  ------------------
  181|    206|			data = NULL;
  182|    206|		} else {
  183|    129|			data = malloc(count);
  184|    129|			if (data == NULL)   {
  ------------------
  |  Branch (184:8): [True: 0, False: 129]
  ------------------
  185|      0|				rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  186|      0|				goto err;
  187|      0|			}
  188|    129|		}
  189|    335|	}
  190|      3|	else {
  191|      3|		if (count > *bufsize) {
  ------------------
  |  Branch (191:7): [True: 0, False: 3]
  ------------------
  192|      0|			rv =  SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  193|      0|			goto err;
  194|      0|		}
  195|      3|		data = *buf;
  196|      3|	}
  197|       |
  198|    338|	if (count > 0 && count != fread(data, 1, count, f)) {
  ------------------
  |  Branch (198:6): [True: 132, False: 206]
  |  Branch (198:19): [True: 0, False: 132]
  ------------------
  199|      0|		rv = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  200|      0|		goto err;
  201|      0|	}
  202|    338|	*buf = data;
  203|    338|	*bufsize = count;
  204|       |
  205|    338|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    338|#define SC_SUCCESS				0
  ------------------
  206|       |
  207|    667|err:
  208|    667|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    667|#define SC_SUCCESS				0
  ------------------
  |  Branch (208:6): [True: 329, False: 338]
  ------------------
  209|    329|		if (data != *buf) {
  ------------------
  |  Branch (209:7): [True: 0, False: 329]
  ------------------
  210|      0|			free(data);
  211|      0|		}
  212|    329|	}
  213|       |
  214|    667|	fclose(f);
  215|    667|	return rv;
  216|    338|}
sc_pkcs15_cache_file:
  221|    839|{
  222|    839|	char fname[PATH_MAX];
  223|    839|	int r;
  224|    839|	long len;
  225|    839|	FILE *f;
  226|    839|	size_t c;
  227|       |
  228|    839|	r = generate_cache_filename(p15card, path, fname, sizeof(fname));
  229|    839|	if (r != 0)
  ------------------
  |  Branch (229:6): [True: 577, False: 262]
  ------------------
  230|    577|		return r;
  231|       |
  232|    262|	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|    262|	if (f == NULL && errno == ENOENT) {
  ------------------
  |  Branch (236:6): [True: 1, False: 261]
  |  Branch (236:19): [True: 1, False: 0]
  ------------------
  237|      1|		if ((r = sc_make_cache_dir(p15card->card->ctx)) < 0)
  ------------------
  |  Branch (237:7): [True: 0, False: 1]
  ------------------
  238|      0|			return r;
  239|      1|		f = fopen(fname, "ab");
  240|      1|	}
  241|    262|	if (f == NULL)
  ------------------
  |  Branch (241:6): [True: 0, False: 262]
  ------------------
  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|    262|	len = ftell(f);
  247|    262|	if (len > path->index) {
  ------------------
  |  Branch (247:6): [True: 40, False: 222]
  ------------------
  248|       |		/* override previous cache records on this location */
  249|     40|		r = fseek(f, path->index, SEEK_SET);
  250|     40|		if (r != 0) {
  ------------------
  |  Branch (250:7): [True: 0, False: 40]
  ------------------
  251|      0|			fclose(f);
  252|      0|			return 0;
  253|      0|		}
  254|    222|	} else if (path->index > len) {
  ------------------
  |  Branch (254:13): [True: 34, False: 188]
  ------------------
  255|       |		/* We miss some bytes so we will not cache this chunk */
  256|     34|		fclose(f);
  257|     34|		return 0;
  258|     34|	}
  259|       |
  260|    228|	c = fwrite(buf, 1, bufsize, f);
  261|    228|	fclose(f);
  262|    228|	if (c != bufsize) {
  ------------------
  |  Branch (262:6): [True: 0, False: 228]
  ------------------
  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|    228|	return 0;
  268|    228|}
pkcs15-cache.c:generate_cache_filename:
   63|  4.76k|{
   64|  4.76k|	char dir[PATH_MAX];
   65|  4.76k|	char *last_update = NULL;
   66|  4.76k|	char *serial_number = NULL;
   67|  4.76k|	int  r;
   68|  4.76k|	unsigned u;
   69|  4.76k|	size_t change_counter;
   70|       |
   71|  4.76k|	if (p15card == NULL || p15card->tokeninfo == NULL || p15card->card == NULL || p15card->card->ctx == NULL) {
  ------------------
  |  Branch (71:6): [True: 0, False: 4.76k]
  |  Branch (71:25): [True: 0, False: 4.76k]
  |  Branch (71:55): [True: 0, False: 4.76k]
  |  Branch (71:80): [True: 0, False: 4.76k]
  ------------------
   72|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   73|      0|	}
   74|       |
   75|  4.76k|	serial_number = p15card->tokeninfo->serial_number;
   76|  4.76k|	if (serial_number == NULL &&
  ------------------
  |  Branch (76:6): [True: 959, False: 3.80k]
  ------------------
   77|    959|			(p15card->card->uid.len == 0 || p15card->card->uid.value[0] == RANDOM_UID_INDICATOR))
  ------------------
  |  |   40|      0|#define RANDOM_UID_INDICATOR 0x08
  ------------------
  |  Branch (77:5): [True: 959, False: 0]
  |  Branch (77:36): [True: 0, False: 0]
  ------------------
   78|    959|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    959|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   79|       |
   80|  3.80k|	if (path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  3.80k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (80:6): [True: 0, False: 3.80k]
  ------------------
   81|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
   82|  3.80k|	r = sc_get_cache_dir(p15card->card->ctx, dir, sizeof(dir));
   83|  3.80k|	if (r)
  ------------------
  |  Branch (83:6): [True: 0, False: 3.80k]
  ------------------
   84|      0|		return r;
   85|  3.80k|	snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "/");
   86|       |
   87|  3.80k|	last_update = sc_pkcs15_get_lastupdate(p15card);
   88|  3.80k|	if (!last_update || !is_safe_cache_component(last_update))
  ------------------
  |  Branch (88:6): [True: 3.46k, False: 336]
  |  Branch (88:22): [True: 266, False: 70]
  ------------------
   89|  3.73k|		last_update = "NODATE";
   90|       |
   91|  3.80k|	if (serial_number && is_safe_cache_component(serial_number)) {
  ------------------
  |  Branch (91:6): [True: 3.80k, False: 0]
  |  Branch (91:23): [True: 3.43k, False: 364]
  ------------------
   92|  3.43k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
   93|  3.43k|				"%s_%s", serial_number, last_update);
   94|  3.43k|	} else {
   95|    364|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "uid-%s_%s",
   96|    364|				sc_dump_hex(p15card->card->uid.value, p15card->card->uid.len), last_update);
   97|    364|	}
   98|       |
   99|  3.80k|	if (SC_SUCCESS == sc_card_ctl(p15card->card, SC_CARDCTL_GET_CHANGE_COUNTER, &change_counter))
  ------------------
  |  |   28|  3.80k|#define SC_SUCCESS				0
  ------------------
  |  Branch (99:6): [True: 0, False: 3.80k]
  ------------------
  100|      0|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_%zu", change_counter);
  101|       |
  102|  3.80k|	if (path->aid.len &&
  ------------------
  |  Branch (102:6): [True: 1.89k, False: 1.91k]
  ------------------
  103|  1.89k|		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  117|  3.78k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
              		(path->type == SC_PATH_TYPE_FILE_ID || path->type == SC_PATH_TYPE_PATH))   {
  ------------------
  |  |  119|    399|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (103:4): [True: 1.49k, False: 399]
  |  Branch (103:42): [True: 6, False: 393]
  ------------------
  104|  1.49k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
  105|  12.0k|		for (u = 0; u < path->aid.len; u++)
  ------------------
  |  Branch (105:15): [True: 10.5k, False: 1.49k]
  ------------------
  106|  10.5k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  107|  10.5k|					"%02X",  path->aid.value[u]);
  108|  1.49k|	}
  109|  2.30k|	else if (path->type != SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  2.30k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (109:11): [True: 407, False: 1.89k]
  ------------------
  110|    407|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    407|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  111|    407|	}
  112|       |
  113|  3.39k|	if (path->len)   {
  ------------------
  |  Branch (113:6): [True: 3.39k, False: 0]
  ------------------
  114|  3.39k|		size_t offs = 0;
  115|       |
  116|  3.39k|		if (path->len > 2 && memcmp(path->value, "\x3F\x00", 2) == 0)
  ------------------
  |  Branch (116:7): [True: 1.89k, False: 1.49k]
  |  Branch (116:24): [True: 1.89k, False: 0]
  ------------------
  117|  1.89k|			offs = 2;
  118|  3.39k|		snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir), "_");
  119|  14.1k|		for (u = 0; u < path->len - offs; u++)
  ------------------
  |  Branch (119:15): [True: 10.7k, False: 3.39k]
  ------------------
  120|  10.7k|			snprintf(dir + strlen(dir), sizeof(dir) - strlen(dir),
  121|  10.7k|					"%02X",  path->value[u + offs]);
  122|  3.39k|	}
  123|       |
  124|  3.39k|	if (!buf)
  ------------------
  |  Branch (124:6): [True: 0, False: 3.39k]
  ------------------
  125|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  126|  3.39k|	strlcpy(buf, dir, bufsize);
  ------------------
  |  |   43|  3.39k|#define strlcpy _strlcpy
  ------------------
  127|       |
  128|  3.39k|	return SC_SUCCESS;
  ------------------
  |  |   28|  3.39k|#define SC_SUCCESS				0
  ------------------
  129|  3.39k|}
pkcs15-cache.c:is_safe_cache_component:
   44|  4.13k|{
   45|  4.13k|	const unsigned char *p = (const unsigned char *)s;
   46|       |
   47|  4.13k|	if (s == NULL || *s == '\0')
  ------------------
  |  Branch (47:6): [True: 0, False: 4.13k]
  |  Branch (47:19): [True: 299, False: 3.83k]
  ------------------
   48|    299|		return 0;
   49|  3.83k|	if (strstr(s, "..") != NULL)
  ------------------
  |  Branch (49:6): [True: 20, False: 3.81k]
  ------------------
   50|     20|		return 0;
   51|  80.9k|	for (; *p; p++) {
  ------------------
  |  Branch (51:9): [True: 77.4k, False: 3.50k]
  ------------------
   52|  77.4k|		if (*p == '/' || *p == '\n')
  ------------------
  |  Branch (52:7): [True: 89, False: 77.3k]
  |  Branch (52:20): [True: 40, False: 77.3k]
  ------------------
   53|    129|			return 0;
   54|  77.3k|		if (!isalnum(*p) && *p != '_' && *p != '-' && *p != '.')
  ------------------
  |  Branch (54:7): [True: 288, False: 77.0k]
  |  Branch (54:23): [True: 252, False: 36]
  |  Branch (54:36): [True: 217, False: 35]
  |  Branch (54:49): [True: 182, False: 35]
  ------------------
   55|    182|			return 0;
   56|  77.3k|	}
   57|  3.50k|	return 1;
   58|  3.81k|}

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

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

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

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

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

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

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

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

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

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

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

sc_pkcs15emu_esteid2018_init_ex:
  256|  7.38k|int sc_pkcs15emu_esteid2018_init_ex(sc_pkcs15_card_t *p15card, struct sc_aid *aid) {
  257|  7.38k|	if (p15card->card->type == SC_CARD_TYPE_ESTEID_2018 ||
  ------------------
  |  Branch (257:6): [True: 46, False: 7.33k]
  ------------------
  258|  7.33k|			p15card->card->type == SC_CARD_TYPE_ESTEID_2018_V2_2025 ||
  ------------------
  |  Branch (258:4): [True: 0, False: 7.33k]
  ------------------
  259|  7.33k|			is_latvian_eid(p15card))
  ------------------
  |  Branch (259:4): [True: 0, False: 7.33k]
  ------------------
  260|     46|		return sc_pkcs15emu_esteid2018_init(p15card);
  261|  7.33k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  7.33k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  262|  7.38k|}
pkcs15-esteid2018.c:is_latvian_eid:
   38|  7.34k|{
   39|  7.34k|	return p15card->card->type == SC_CARD_TYPE_LATEID_2018 ||
  ------------------
  |  Branch (39:9): [True: 0, False: 7.34k]
  ------------------
   40|  7.34k|	       p15card->card->type == SC_CARD_TYPE_LATEID_2018_V2_2025;
  ------------------
  |  Branch (40:9): [True: 0, False: 7.34k]
  ------------------
   41|  7.34k|}
pkcs15-esteid2018.c:sc_pkcs15emu_esteid2018_init:
   43|     46|static int sc_pkcs15emu_esteid2018_init(sc_pkcs15_card_t *p15card) {
   44|     46|	sc_card_t *card = p15card->card;
   45|     46|	u8 buff[11];
   46|     46|	int r, i, cert_slot = 0;
   47|     46|	size_t field_length = 0, taglen, buflen;
   48|     46|	sc_path_t tmppath;
   49|       |
   50|       |	/* Read documber number to be used as serial */
   51|     46|	sc_format_path("3F00D003", &tmppath);
   52|     46|	LOG_TEST_RET(card->ctx, sc_select_file(card, &tmppath, NULL), "SELECT docnr");
  ------------------
  |  |  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: 31, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   53|     15|	r = sc_read_binary(card, 0, buff, 11, 0);
   54|     15|	LOG_TEST_RET(card->ctx, r, "read document number failed");
  ------------------
  |  |  174|     15|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     15|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     15|	int _ret = (r); \
  |  |  |  |  168|     15|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  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|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   55|     10|	const u8 *tag = sc_asn1_find_tag(card->ctx, buff, (size_t)r, 0x04, &taglen);
   56|     10|	if (tag == NULL)
  ------------------
  |  Branch (56:6): [True: 2, False: 8]
  ------------------
   57|     10|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   58|       |
   59|     47|	for (size_t j = 0; j < taglen; j++)
  ------------------
  |  Branch (59:21): [True: 41, False: 6]
  ------------------
   60|     41|		if (!isalnum(tag[j]))
  ------------------
  |  Branch (60:7): [True: 2, False: 39]
  ------------------
   61|      8|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   62|      6|	free(p15card->tokeninfo->serial_number);
   63|      6|	p15card->tokeninfo->serial_number = malloc(taglen + 1);
   64|      6|	if (!p15card->tokeninfo->serial_number)
  ------------------
  |  Branch (64:6): [True: 0, False: 6]
  ------------------
   65|      6|		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|      6|	set_string(&p15card->tokeninfo->label, "ID-kaart");
   68|      6|	set_string(&p15card->tokeninfo->manufacturer_id, "IDEMIA");
   69|      6|	p15card->tokeninfo->serial_number = memcpy(p15card->tokeninfo->serial_number, tag, taglen);
   70|      6|	p15card->tokeninfo->serial_number[taglen] = '\0';
   71|      6|	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|      6|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
   72|       |
   73|      6|	if (is_latvian_eid(p15card)) {
  ------------------
  |  Branch (73:6): [True: 0, False: 6]
  ------------------
   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|      6|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (111:14): [True: 6, False: 0]
  ------------------
  112|      6|		static const char *esteid_cert_names[2] = {"Isikutuvastus", "Allkirjastamine"};
  113|      6|		static const char *cert_paths[2][2] = {
  114|      6|				{"3f00:adf1:3401", "3f00:adf2:341f"},
  115|      6|				{"3f00:adf1:3402", "3f00:adf2:341e"}
  116|      6|		    };
  117|      6|		static const u8 esteid_cert_ids[2] = {1, 2};
  118|       |
  119|      6|		struct sc_pkcs15_cert_info cert_info = {
  120|      6|				.id = {.len = 1, .value[0] = esteid_cert_ids[i]}
  121|      6|		};
  122|      6|		struct sc_pkcs15_object cert_obj = {0};
  123|       |
  124|      6|		strlcpy(cert_obj.label, esteid_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|      6|#define strlcpy _strlcpy
  ------------------
  125|      6|		sc_format_path(cert_paths[cert_slot][i], &cert_info.path);
  126|      6|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  127|      6|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not add cert oebjct");
  ------------------
  |  |  184|      6|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      6|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      6|	int _ret = (r); \
  |  |  |  |  178|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  128|       |
  129|       |		// Read data from first cert
  130|      6|		if (i != 0)
  ------------------
  |  Branch (130:7): [True: 0, False: 6]
  ------------------
  131|      0|			continue;
  132|       |
  133|      6|		sc_pkcs15_cert_t *cert = NULL;
  134|      6|		r = sc_pkcs15_read_certificate(p15card, &cert_info, 0, &cert);
  135|      6|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not read authentication certificate");
  ------------------
  |  |  184|      6|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      6|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      6|	int _ret = (r); \
  |  |  |  |  178|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      6|		goto err; \
  |  |  |  |  182|      6|	} \
  |  |  |  |  183|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|      6|err:
  252|      6|	sc_pkcs15_card_clear(p15card);
  253|      6|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|      6|}

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

sc_pkcs15emu_gemsafeV1_init_ex:
  451|  10.0k|{
  452|  10.0k|	if (gemsafe_detect_card(p15card))
  ------------------
  |  Branch (452:6): [True: 9.25k, False: 780]
  ------------------
  453|  9.25k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.25k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  454|    780|	return sc_pkcs15emu_gemsafeV1_init(p15card);
  455|  10.0k|}
pkcs15-gemsafeV1.c:gemsafe_detect_card:
  298|  10.0k|{
  299|  10.0k|	if (strcmp(p15card->card->name, "GemSAFE V1"))
  ------------------
  |  Branch (299:6): [True: 9.25k, False: 780]
  ------------------
  300|  9.25k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.25k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  301|       |
  302|    780|	return SC_SUCCESS;
  ------------------
  |  |   28|    780|#define SC_SUCCESS				0
  ------------------
  303|  10.0k|}
pkcs15-gemsafeV1.c:sc_pkcs15emu_gemsafeV1_init:
  306|    780|{
  307|    780|	int		    r;
  308|    780|	unsigned int    i;
  309|    780|	struct sc_path  path;
  310|    780|	struct sc_file *file = NULL;
  311|    780|	struct sc_card *card = p15card->card;
  312|    780|	struct sc_apdu  apdu;
  313|    780|	u8		    rbuf[SC_MAX_APDU_BUFFER_SIZE];
  314|       |
  315|    780|	sc_log(p15card->card->ctx, "Setting pkcs15 parameters");
  ------------------
  |  |   71|    780|#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|    780|	set_string(&p15card->tokeninfo->label, APPLET_NAME);
  ------------------
  |  |   32|    780|#define APPLET_NAME		"GemSAFE V1"
  ------------------
  318|    780|	if (!p15card->tokeninfo->label)
  ------------------
  |  Branch (318:6): [True: 0, False: 780]
  ------------------
  319|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  320|       |
  321|    780|	set_string(&p15card->tokeninfo->serial_number, DRIVER_SERIAL_NUMBER);
  ------------------
  |  |   33|    780|#define DRIVER_SERIAL_NUMBER	"v0.9"
  ------------------
  322|    780|	if (!p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (322:6): [True: 0, False: 780]
  ------------------
  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|    780|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0xdf, 0x03);
  ------------------
  |  |  292|    780|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  330|    780|	apdu.cla = 0x80;
  331|    780|	apdu.resp = rbuf;
  332|    780|	apdu.resplen = sizeof(rbuf);
  333|       |	/* Manual says Le=0x05, but should be 0x08 to return full version number */
  334|    780|	apdu.le = 0x08;
  335|    780|	apdu.lc = 0;
  336|    780|	apdu.datalen = 0;
  337|    780|	r = sc_transmit_apdu(card, &apdu);
  338|    780|	if (r < 0)
  ------------------
  |  Branch (338:6): [True: 5, False: 775]
  ------------------
  339|      5|		sc_pkcs15_card_clear(p15card);
  340|    780|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    780|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    780|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    780|	int _ret = (r); \
  |  |  |  |  168|    780|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 775]
  |  |  |  |  ------------------
  |  |  |  |  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|    780|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 775]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|       |
  342|    775|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00 || r != SC_SUCCESS) {
  ------------------
  |  |   28|    138|#define SC_SUCCESS				0
  ------------------
  |  Branch (342:6): [True: 629, False: 146]
  |  Branch (342:26): [True: 8, False: 138]
  |  Branch (342:46): [True: 0, False: 138]
  ------------------
  343|    637|		sc_pkcs15_card_clear(p15card);
  344|    637|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    637|#define SC_ERROR_INTERNAL			-1400
  ------------------
  345|    637|	}
  346|       |
  347|       |	/* the manufacturer ID, in this case GemPlus */
  348|    138|	set_string(&p15card->tokeninfo->manufacturer_id, MANU_ID);
  ------------------
  |  |   31|    138|#define MANU_ID			"Gemplus"
  ------------------
  349|    138|	if (!p15card->tokeninfo->manufacturer_id) {
  ------------------
  |  Branch (349:6): [True: 0, False: 138]
  ------------------
  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|    138|	r = gemsafe_get_cert_len(card);
  356|    138|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    138|#define SC_SUCCESS				0
  ------------------
  |  Branch (356:6): [True: 80, False: 58]
  ------------------
  357|     80|		sc_pkcs15_card_clear(p15card);
  358|     80|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     80|#define SC_ERROR_INTERNAL			-1400
  ------------------
  359|     80|	}
  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: 5, False: 53]
  ------------------
  388|      5|		    memcmp(p15card->card->atr.value, gemsafe_pin[i].atr,
  ------------------
  |  Branch (388:7): [True: 1, False: 4]
  ------------------
  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|    138|{
  164|    138|	int r;
  165|    138|	u8  ibuf[GEMSAFE_MAX_OBJLEN];
  166|    138|	u8 *iptr;
  167|    138|	struct sc_path path;
  168|    138|	struct sc_file *file;
  169|    138|	size_t objlen;
  170|    138|	int certlen;
  171|    138|	unsigned int ind, i=0;
  172|    138|	int read_len;
  173|       |
  174|    138|	sc_format_path(GEMSAFE_PATH, &path);
  ------------------
  |  |   35|    138|#define GEMSAFE_PATH		"3F0016000004"
  ------------------
  175|    138|	r = sc_select_file(card, &path, &file);
  176|    138|	if (r != SC_SUCCESS || !file)
  ------------------
  |  |   28|    276|#define SC_SUCCESS				0
  ------------------
  |  Branch (176:6): [True: 3, False: 135]
  |  Branch (176:25): [True: 0, False: 135]
  ------------------
  177|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
  178|    135|	sc_file_free(file);
  179|       |
  180|       |	/* Initial read */
  181|    135|	read_len = sc_read_binary(card, 0, ibuf, GEMSAFE_READ_QUANTUM, 0);
  ------------------
  |  |   40|    135|#define GEMSAFE_READ_QUANTUM    248
  ------------------
  182|    135|	if (read_len <= 2) {
  ------------------
  |  Branch (182:6): [True: 11, False: 124]
  ------------------
  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|    124|	objlen = (((size_t) ibuf[0]) << 8) | ibuf[1];
  191|    124|	sc_log(card->ctx, "Stored object is of size: %zu", objlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  192|    124|	if (objlen < 1 || objlen > GEMSAFE_MAX_OBJLEN) {
  ------------------
  |  |   41|    123|#define GEMSAFE_MAX_OBJLEN      28672
  ------------------
  |  Branch (192:6): [True: 1, False: 123]
  |  Branch (192:20): [True: 2, False: 121]
  ------------------
  193|      3|		sc_log(card->ctx, "Invalid object size: %zu", objlen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  194|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
  195|      3|	}
  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|    121|	ind = 2; /* skip length */
  212|    229|	while (ind + 1 < (size_t)read_len && ibuf[ind] == 0x01 && i < gemsafe_cert_max) {
  ------------------
  |  Branch (212:9): [True: 201, False: 28]
  |  Branch (212:39): [True: 109, False: 92]
  |  Branch (212:60): [True: 108, False: 1]
  ------------------
  213|    108|		if (ibuf[ind+1] == 0xFE) {
  ------------------
  |  Branch (213:7): [True: 29, False: 79]
  ------------------
  214|     29|			gemsafe_prkeys[i].ref = ibuf[ind+4];
  215|     29|			sc_log(card->ctx, "Key container %d is allocated and uses key_ref %d",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  216|     29|					i+1, gemsafe_prkeys[i].ref);
  217|     29|			ind += 9;
  218|     29|		}
  219|     79|		else {
  220|     79|			gemsafe_prkeys[i].label = NULL;
  221|     79|			gemsafe_cert[i].label = NULL;
  222|     79|			sc_log(card->ctx, "Key container %d is unallocated", i+1);
  ------------------
  |  |   71|     79|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  223|     79|			ind += 8;
  224|     79|		}
  225|    108|		i++;
  226|    108|	}
  227|       |
  228|       |	/* Delete additional key containers from the data structures if
  229|       |	 * this card can't accommodate them.
  230|       |	 */
  231|  1.46k|	for (; i < gemsafe_cert_max; i++) {
  ------------------
  |  Branch (231:9): [True: 1.34k, False: 121]
  ------------------
  232|  1.34k|		gemsafe_prkeys[i].label = NULL;
  233|  1.34k|		gemsafe_cert[i].label = NULL;
  234|  1.34k|	}
  235|       |
  236|       |	/* Read entire file, then dissect in memory.
  237|       |	 * Gemalto ClassicClient seems to do it the same way.
  238|       |	 */
  239|    121|	iptr = ibuf + read_len;
  240|  1.03k|	while ((size_t)(iptr - ibuf) < objlen) {
  ------------------
  |  Branch (240:9): [True: 978, False: 58]
  ------------------
  241|    978|		r = sc_read_binary(card, (unsigned)(iptr - ibuf), iptr,
  242|    978|				   MIN(GEMSAFE_READ_QUANTUM, objlen - (iptr - ibuf)), 0);
  ------------------
  |  |   69|    978|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 886, False: 92]
  |  |  ------------------
  ------------------
  243|    978|		if (r < 0) {
  ------------------
  |  Branch (243:7): [True: 56, False: 922]
  ------------------
  244|     56|			sc_log(card->ctx, "Could not read cert object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  245|     56|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     56|#define SC_ERROR_INTERNAL			-1400
  ------------------
  246|     56|		}
  247|    922|		if (r == 0)
  ------------------
  |  Branch (247:7): [True: 7, False: 915]
  ------------------
  248|      7|			break;
  249|    915|		read_len += r;
  250|    915|		iptr += r;
  251|    915|	}
  252|     65|	if ((size_t)read_len < objlen) {
  ------------------
  |  Branch (252:6): [True: 7, False: 58]
  ------------------
  253|      7|		sc_log(card->ctx, "Could not read cert object");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  254|      7|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      7|#define SC_ERROR_INTERNAL			-1400
  ------------------
  255|      7|	}
  256|       |
  257|       |	/* Search buffer for certificates, they start with 0x3082. */
  258|     58|	i = 0;
  259|  5.06k|	while (ind < objlen - 1) {
  ------------------
  |  Branch (259:9): [True: 5.00k, False: 57]
  ------------------
  260|  5.00k|		if (ibuf[ind] == 0x30 && ibuf[ind+1] == 0x82) {
  ------------------
  |  Branch (260:7): [True: 214, False: 4.78k]
  |  Branch (260:28): [True: 1, False: 213]
  ------------------
  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|  5.00k|			ind++;
  281|  5.00k|	}
  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|  9.68k|{
  242|  9.68k|	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: 9.56k, False: 112]
  |  Branch (242:58): [True: 9.56k, False: 1]
  |  Branch (242:105): [True: 9.56k, False: 0]
  ------------------
  243|  9.56k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.56k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  244|  9.56k|	}
  245|    113|	return sc_pkcs15emu_gids_init(p15card);
  246|  9.68k|}
pkcs15-gids.c:sc_pkcs15emu_gids_init:
  112|    113|{
  113|    113|	sc_card_t *card = p15card->card;
  114|    113|	int r;
  115|    113|	size_t i;
  116|    113|	struct sc_pkcs15_auth_info pin_info;
  117|    113|	struct sc_pkcs15_object pin_obj;
  118|    113|	struct sc_pin_cmd_data pin_cmd_data;
  119|    113|	size_t recordsnum;
  120|    113|	int has_puk;
  121|       |
  122|    113|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  123|    113|	LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
  ------------------
  |  |  174|    113|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    113|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    113|	int _ret = (r); \
  |  |  |  |  168|    113|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 113, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    113|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    113|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    113|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    113|		return _ret; \
  |  |  |  |  172|    113|	} \
  |  |  |  |  173|    113|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|       |
  125|      0|	r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, NULL);
  126|      0|	LOG_TEST_RET(card->ctx, r, "unable to get the serial number. Uninitialized card ?");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  127|       |
  128|      0|	free(p15card->tokeninfo->serial_number);
  129|      0|	p15card->tokeninfo->serial_number = (char*) malloc(card->serialnr.len *2 +1);
  130|      0|	if (!p15card->tokeninfo->serial_number) {
  ------------------
  |  Branch (130:6): [True: 0, False: 0]
  ------------------
  131|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  132|      0|	}
  133|      0|	sc_bin_to_hex(card->serialnr.value, card->serialnr.len, p15card->tokeninfo->serial_number, card->serialnr.len *2 +1, 0);
  134|       |
  135|      0|	if (p15card->tokeninfo->label == NULL) {
  ------------------
  |  Branch (135:6): [True: 0, False: 0]
  ------------------
  136|      0|		p15card->tokeninfo->label = strdup("GIDS card");
  137|      0|		if (p15card->tokeninfo->label == NULL) {
  ------------------
  |  Branch (137:7): [True: 0, False: 0]
  ------------------
  138|      0|			free(p15card->tokeninfo->serial_number);
  139|      0|			p15card->tokeninfo->serial_number = NULL;
  140|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|      0|		}
  142|      0|	}
  143|       |
  144|      0|	if ((p15card->tokeninfo->manufacturer_id != NULL) && !strcmp("(unknown)", p15card->tokeninfo->manufacturer_id)) {
  ------------------
  |  Branch (144:6): [True: 0, False: 0]
  |  Branch (144:55): [True: 0, False: 0]
  ------------------
  145|      0|		free(p15card->tokeninfo->manufacturer_id);
  146|      0|		p15card->tokeninfo->manufacturer_id = NULL;
  147|      0|	}
  148|       |
  149|      0|	if (p15card->tokeninfo->manufacturer_id == NULL) {
  ------------------
  |  Branch (149:6): [True: 0, False: 0]
  ------------------
  150|      0|		p15card->tokeninfo->manufacturer_id = strdup("www.mysmartlogon.com");
  151|      0|		if (p15card->tokeninfo->manufacturer_id == NULL) {
  ------------------
  |  Branch (151:7): [True: 0, False: 0]
  ------------------
  152|      0|			sc_pkcs15_card_clear(p15card);
  153|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  154|      0|		}
  155|      0|	}
  156|      0|	if (p15card->card->type == SC_CARD_TYPE_GIDS_V2) {
  ------------------
  |  Branch (156:6): [True: 0, False: 0]
  ------------------
  157|      0|		p15card->tokeninfo->version = 2;
  158|      0|	} else if (p15card->card->type == SC_CARD_TYPE_GIDS_V1) {
  ------------------
  |  Branch (158:13): [True: 0, False: 0]
  ------------------
  159|      0|		p15card->tokeninfo->version = 1;
  160|      0|	}
  161|       |
  162|      0|	memset(&pin_info, 0, sizeof(pin_info));
  163|      0|	memset(&pin_obj, 0, sizeof(pin_obj));
  164|       |
  165|      0|	pin_info.auth_id.len = 1;
  166|      0|	pin_info.auth_id.value[0] = 0x80;
  167|      0|	pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|      0|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  168|      0|	pin_info.attrs.pin.reference = 0x80;
  169|      0|	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              	pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED;
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  170|      0|	pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|      0|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  171|      0|	pin_info.attrs.pin.min_length = 4;
  172|      0|	pin_info.attrs.pin.stored_length = 0;
  173|      0|	pin_info.attrs.pin.max_length = 15;
  174|      0|	pin_info.attrs.pin.pad_char = '\0';
  175|      0|	pin_info.tries_left = -1;
  176|      0|	pin_info.max_tries = -1;
  177|       |
  178|      0|	memset(&pin_cmd_data, 0, sizeof(pin_cmd_data));
  179|      0|	pin_cmd_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  180|      0|	pin_cmd_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  181|      0|	pin_cmd_data.pin_reference = pin_info.attrs.pin.reference;
  182|       |
  183|      0|	r = sc_pin_cmd(card, &pin_cmd_data);
  184|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (184:6): [True: 0, False: 0]
  ------------------
  185|      0|		pin_info.max_tries = pin_cmd_data.pin1.max_tries;
  186|      0|		pin_info.tries_left = pin_cmd_data.pin1.tries_left;
  187|      0|	}
  188|       |
  189|      0|	strlcpy(pin_obj.label, "UserPIN", sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  190|      0|	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE|SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|      0|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              	pin_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE|SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|      0|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  191|       |
  192|       |	/*
  193|       |	 * check whether PUK is available on this card and then optionally
  194|       |	 * link PIN with PUK.
  195|       |	 */
  196|      0|	pin_cmd_data.pin_reference = 0x81;
  197|      0|	has_puk = sc_pin_cmd(card, &pin_cmd_data) == SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  198|      0|	if (has_puk) {
  ------------------
  |  Branch (198:6): [True: 0, False: 0]
  ------------------
  199|      0|		pin_obj.auth_id.len = 1;
  200|      0|		pin_obj.auth_id.value[0] = 0x81;
  201|      0|	}
  202|       |
  203|      0|	r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  204|      0|	LOG_TEST_GOTO_ERR(card->ctx, r, "unable to sc_pkcs15emu_add_pin_obj");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  205|       |
  206|      0|	if (has_puk) {
  ------------------
  |  Branch (206:6): [True: 0, False: 0]
  ------------------
  207|      0|		pin_info.auth_id.value[0] = 0x81;
  208|      0|		pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   55|      0|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
              		pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   58|      0|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
              		pin_info.attrs.pin.flags = SC_PKCS15_PIN_FLAG_LOCAL|SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN;
  ------------------
  |  |   60|      0|#define SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN		0x0040
  ------------------
  209|      0|		pin_info.attrs.pin.reference = 0x81;
  210|      0|		pin_info.max_tries = pin_cmd_data.pin1.max_tries;
  211|      0|		pin_info.tries_left = pin_cmd_data.pin1.tries_left;
  212|      0|		strlcpy(pin_obj.label, "PUK", sizeof(pin_obj.label));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  213|      0|		pin_obj.auth_id.len = 0;
  214|      0|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  215|      0|		LOG_TEST_GOTO_ERR(card->ctx, r, "unable to sc_pkcs15emu_add_pin_obj with PUK");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  216|      0|	}
  217|       |
  218|      0|	r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
  219|      0|	LOG_TEST_GOTO_ERR(card->ctx, r, "sc_card_ctl SC_CARDCTL_GIDS_GET_ALL_CONTAINERS");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|       |
  221|      0|	for (i = 0; i < recordsnum; i++) {
  ------------------
  |  Branch (221:14): [True: 0, False: 0]
  ------------------
  222|      0|		sc_cardctl_gids_get_container_t container;
  223|      0|		memset(&container, 0, sizeof(sc_cardctl_gids_get_container_t));
  224|      0|		container.containernum = i;
  225|      0|		r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_CONTAINER_DETAIL, &container);
  226|      0|		if (r < 0) {
  ------------------
  |  Branch (226:7): [True: 0, False: 0]
  ------------------
  227|       |			// one of the container information couldn't be retrieved
  228|       |			// ignore it
  229|      0|			continue;
  230|      0|		}
  231|      0|		sc_pkcs15emu_gids_add_prkey(p15card, &container);
  232|      0|	}
  233|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  234|      0|err:
  235|      0|	sc_pkcs15_card_clear(p15card);
  236|      0|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  237|      0|}

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

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

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

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

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

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

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

sc_pkcs15emu_openpgp_init_ex:
  694|  12.9k|{
  695|  12.9k|	if (openpgp_detect_card(p15card))
  ------------------
  |  Branch (695:6): [True: 12.2k, False: 680]
  ------------------
  696|  12.2k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  12.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  697|    680|	return sc_pkcs15emu_openpgp_init(p15card);
  698|  12.9k|}
pkcs15-openpgp.c:openpgp_detect_card:
  682|  12.9k|{
  683|  12.9k|	if (p15card->card->type == SC_CARD_TYPE_OPENPGP_BASE
  ------------------
  |  Branch (683:6): [True: 433, False: 12.4k]
  ------------------
  684|  12.4k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V1
  ------------------
  |  Branch (684:7): [True: 3, False: 12.4k]
  ------------------
  685|  12.4k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V2
  ------------------
  |  Branch (685:7): [True: 3, False: 12.4k]
  ------------------
  686|  12.4k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_GNUK
  ------------------
  |  Branch (686:7): [True: 224, False: 12.2k]
  ------------------
  687|  12.2k|			|| p15card->card->type == SC_CARD_TYPE_OPENPGP_V3)
  ------------------
  |  Branch (687:7): [True: 17, False: 12.2k]
  ------------------
  688|    680|		return SC_SUCCESS;
  ------------------
  |  |   28|    680|#define SC_SUCCESS				0
  ------------------
  689|  12.2k|	else
  690|  12.2k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  12.2k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  691|  12.9k|}
pkcs15-openpgp.c:sc_pkcs15emu_openpgp_init:
  181|    680|{
  182|    680|	sc_card_t	*card = p15card->card;
  183|    680|	sc_context_t	*ctx = card->ctx;
  184|    680|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    680|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  185|    680|	char		string[256];
  186|    680|	u8		c4data[10];
  187|    680|	u8		c5data[100];
  188|    680|	int		r, i;
  189|    680|	const pgp_pin_cfg_t *pin_cfg = (card->type == SC_CARD_TYPE_OPENPGP_V1)
  ------------------
  |  Branch (189:33): [True: 3, False: 677]
  ------------------
  190|    680|	                               ? pin_cfg_v1 : pin_cfg_v2;
  191|    680|	sc_path_t path;
  192|    680|	sc_file_t *file = NULL;
  193|       |
  194|    680|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    680|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    680|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    680|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    680|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 680]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  195|       |
  196|    680|	set_string(&p15card->tokeninfo->label, "OpenPGP card");
  197|    680|	set_string(&p15card->tokeninfo->manufacturer_id, "OpenPGP project");
  198|       |
  199|       |	/* card->serialnr = 2 byte manufacturer_id + 4 byte serial_number */
  200|    680|	if (card->serialnr.len > 0) {
  ------------------
  |  Branch (200:6): [True: 382, False: 298]
  ------------------
  201|    382|		unsigned short manuf_id = bebytes2ushort(card->serialnr.value);
  202|    382|		int j;
  203|       |
  204|    382|		sc_bin_to_hex(card->serialnr.value, card->serialnr.len, string, sizeof(string), 0);
  205|    382|		set_string(&p15card->tokeninfo->serial_number, string);
  206|       |
  207|  9.16k|		for (j = 0; manuf_map[j].name != NULL; j++) {
  ------------------
  |  Branch (207:15): [True: 8.84k, False: 320]
  ------------------
  208|  8.84k|			if (manuf_id == manuf_map[j].id) {
  ------------------
  |  Branch (208:8): [True: 62, False: 8.78k]
  ------------------
  209|     62|				set_string(&p15card->tokeninfo->manufacturer_id, manuf_map[j].name);
  210|     62|				break;
  211|     62|			}
  212|  8.84k|		}
  213|    382|	}
  214|       |
  215|    680|	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_EID_COMPLIANT;
  ------------------
  |  |  597|    680|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
              	p15card->tokeninfo->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_EID_COMPLIANT;
  ------------------
  |  |  598|    680|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  216|       |
  217|       |	/* Extract preferred language */
  218|    680|	r = read_file(card, "0065:5f2d", string, sizeof(string)-1);
  219|    680|	if (r < 0)
  ------------------
  |  Branch (219:6): [True: 447, False: 233]
  ------------------
  220|    447|		goto failed;
  221|    233|	string[r] = '\0';
  222|    233|	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|    233|	sc_log(ctx, "Reading PW status bytes");
  ------------------
  |  |   71|    233|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|    233|	if ((r = read_file(card, "006E:0073:00C4", c4data, sizeof(c4data))) < 0)
  ------------------
  |  Branch (231:6): [True: 29, False: 204]
  ------------------
  232|     29|		goto failed;
  233|    204|	if (r != 7) {
  ------------------
  |  Branch (233:6): [True: 2, False: 202]
  ------------------
  234|      2|		sc_log(ctx, "CHV status bytes have unexpected length (expected 7, got %d)\n", r);
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  235|      2|		r = SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      2|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
  236|      2|		goto failed;
  237|      2|	}
  238|       |
  239|       |	/* Add PIN codes */
  240|    808|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (240:14): [True: 606, False: 202]
  ------------------
  241|    606|		sc_pkcs15_auth_info_t pin_info;
  242|    606|		sc_pkcs15_object_t   pin_obj;
  243|       |
  244|    606|		memset(&pin_info, 0, sizeof(pin_info));
  245|    606|		memset(&pin_obj,  0, sizeof(pin_obj));
  246|       |
  247|    606|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    606|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  248|    606|		pin_info.auth_id.len      = 1;
  249|    606|		pin_info.auth_id.value[0] = pin_cfg[i].reference;
  250|    606|		pin_info.attrs.pin.reference     = pin_cfg[i].reference;
  251|    606|		pin_info.attrs.pin.flags         = pin_cfg[i].flags;
  252|    606|		pin_info.attrs.pin.type          = SC_PKCS15_PIN_TYPE_UTF8;
  ------------------
  |  |   90|    606|#define SC_PKCS15_PIN_TYPE_UTF8				2
  ------------------
  253|    606|		pin_info.attrs.pin.min_length    = pin_cfg[i].min_length;
  254|    606|		pin_info.attrs.pin.stored_length = c4data[1 + pin_cfg[i].do_index];
  255|    606|		pin_info.attrs.pin.max_length    = c4data[1 + pin_cfg[i].do_index];
  256|    606|		pin_info.attrs.pin.pad_char      = '\0';
  257|    606|		pin_info.tries_left = c4data[4 + pin_cfg[i].do_index];
  258|    606|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|    606|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  259|       |
  260|    606|		sc_format_path("3F00", &pin_info.path);
  261|       |
  262|    606|		strlcpy(pin_obj.label, pin_cfg[i].label, sizeof(pin_obj.label));
  ------------------
  |  |   43|    606|#define strlcpy _strlcpy
  ------------------
  263|    606|		pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   51|    606|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
              		pin_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE | SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    606|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  264|    606|		if (i < 2) {
  ------------------
  |  Branch (264:7): [True: 404, False: 202]
  ------------------
  265|    404|			pin_obj.auth_id.len = 1;
  266|    404|			pin_obj.auth_id.value[0] = 3;
  267|    404|		}
  268|       |
  269|    606|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  270|    606|		if (r < 0) {
  ------------------
  |  Branch (270:7): [True: 0, False: 606]
  ------------------
  271|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  272|      0|			goto failed;
  273|      0|		}
  274|    606|	}
  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|    202|	sc_log(ctx, "Reading Fingerprints");
  ------------------
  |  |   71|    202|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  282|    202|	if ((r = read_file(card, "006E:0073:00C5", c5data, sizeof(c5data))) < 0)
  ------------------
  |  Branch (282:6): [True: 1, False: 201]
  ------------------
  283|      1|		goto failed;
  284|    201|	if (r < 60) {
  ------------------
  |  Branch (284:6): [True: 1, False: 200]
  ------------------
  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|    200|	sc_log(ctx, "Adding private keys");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  292|       |	/* XXX: check if "halfkeys" can be stored with gpg2. If not, add key pairs in one loop */
  293|    720|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (293:14): [True: 574, False: 146]
  ------------------
  294|    574|		sc_pkcs15_prkey_info_t prkey_info;
  295|    574|		sc_pkcs15_object_t     prkey_obj;
  296|    574|		u8 cxdata[12];
  297|    574|		int cxdata_len = sizeof(cxdata);
  298|    574|		char path_template[] = "006E:0073:00Cx";
  299|    574|		int j;
  300|       |
  301|    574|		memset(&prkey_info, 0, sizeof(prkey_info));
  302|    574|		memset(&prkey_obj,  0, sizeof(prkey_obj));
  303|    574|		memset(&cxdata, 0, sizeof(cxdata));
  304|       |
  305|    574|		path_template[13] = '1' + i; /* The needed tags are C1 C2 and C3 */
  306|    574|		if ((cxdata_len = read_file(card, path_template, cxdata, sizeof(cxdata))) < 1)
  ------------------
  |  Branch (306:7): [True: 51, False: 523]
  ------------------
  307|     51|			goto failed;
  308|       |
  309|       |		/* check validity using finger prints */
  310|  1.41k|		for (j = 19; j >= 0; j--) {
  ------------------
  |  Branch (310:16): [True: 1.39k, False: 14]
  ------------------
  311|  1.39k|			if (c5data[20 * i + j] != '\0')
  ------------------
  |  Branch (311:8): [True: 509, False: 888]
  ------------------
  312|    509|				break;
  313|  1.39k|		}
  314|       |
  315|       |		/* only add valid keys, i.e. those with a legal algorithm identifier & finger print */
  316|    523|		if (j >= 0 && cxdata[0] != 0) {
  ------------------
  |  Branch (316:7): [True: 509, False: 14]
  |  Branch (316:17): [True: 497, False: 12]
  ------------------
  317|    497|			struct sc_object_id oid = {0};
  318|    497|			struct sc_algorithm_info * algorithm_info; /* no need to free */
  319|       |
  320|    497|			algorithm_info = NULL;
  321|    497|			prkey_info.id.len         = 1;
  322|    497|			prkey_info.id.value[0]    = i + 1;
  323|    497|			prkey_info.usage          = key_cfg[i].prkey_usage;
  324|    497|			prkey_info.native         = 1;
  325|    497|			prkey_info.key_reference  = i;
  326|       |
  327|    497|			strlcpy(prkey_obj.label, key_cfg[i].label, sizeof(prkey_obj.label));
  ------------------
  |  |   43|    497|#define strlcpy _strlcpy
  ------------------
  328|    497|			prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|    497|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              			prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|    497|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  329|    497|			prkey_obj.auth_id.len      = 1;
  330|    497|			prkey_obj.auth_id.value[0] = key_cfg[i].prkey_pin;
  331|       |
  332|       |			/* need to get size from algorithms using oid */
  333|    497|			if (cxdata[0] == SC_OPENPGP_KEYALGO_ECDH ||
  ------------------
  |  |  878|    994|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (333:8): [True: 102, False: 395]
  ------------------
  334|    395|				cxdata[0] == SC_OPENPGP_KEYALGO_ECDSA ||
  ------------------
  |  |  879|    892|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (334:5): [True: 8, False: 387]
  ------------------
  335|    387|				cxdata[0] == SC_OPENPGP_KEYALGO_EDDSA) {
  ------------------
  |  |  880|    387|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (335:5): [True: 86, False: 301]
  ------------------
  336|       |				/* Last byte could be Import-Format of private key, let's ignore it,
  337|       |				 * as it is not part of OID */
  338|    196|				if (cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STD ||
  ------------------
  |  |  887|    392|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (338:9): [True: 18, False: 178]
  ------------------
  339|    178|				    cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB)
  ------------------
  |  |  888|    178|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (339:9): [True: 6, False: 172]
  ------------------
  340|     24|					cxdata_len--;
  341|    196|				r = sc_asn1_decode_object_id(&cxdata[1], cxdata_len-1, &oid);
  342|    196|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    196|#define SC_SUCCESS				0
  ------------------
  |  Branch (342:9): [True: 147, False: 49]
  ------------------
  343|    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__
  |  |  ------------------
  ------------------
  344|    147|				}
  345|    196|			}
  346|       |
  347|    497|			switch (cxdata[0]) {
  ------------------
  |  Branch (347:12): [True: 196, False: 301]
  ------------------
  348|    102|			case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|    102|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (348:4): [True: 102, False: 395]
  ------------------
  349|    102|				if (sc_compare_oid(&oid, &curve25519_oid)) {
  ------------------
  |  Branch (349:9): [True: 0, False: 102]
  ------------------
  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|    110|			case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|    110|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (359:4): [True: 8, False: 489]
  ------------------
  360|    110|				if((algorithm_info = sc_card_find_ec_alg(card, 0, &oid)))
  ------------------
  |  Branch (360:8): [True: 0, False: 110]
  ------------------
  361|      0|					prkey_info.field_length = algorithm_info->key_length;
  362|    110|				else {
  363|    110|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  364|    110|					continue;
  365|    110|				}
  366|      0|				break;
  367|     86|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|     86|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (367:4): [True: 86, False: 411]
  ------------------
  368|     86|				if ((algorithm_info = sc_card_find_eddsa_alg(card, 0, &oid)))
  ------------------
  |  Branch (368:9): [True: 0, False: 86]
  ------------------
  369|      0|					prkey_info.field_length = algorithm_info->key_length;
  370|     86|				else {
  371|     86|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  372|     86|					continue;
  373|     86|				}
  374|      0|				break;
  375|    497|			}
  376|       |
  377|    301|			switch (cxdata[0]) {
  378|      0|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|      0|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (378:4): [True: 0, False: 301]
  ------------------
  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: 301]
  ------------------
  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: 301]
  ------------------
  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|    167|			case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|    167|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (403:4): [True: 167, False: 134]
  ------------------
  404|    167|				if (cxdata_len >= 3) {
  ------------------
  |  Branch (404:9): [True: 163, False: 4]
  ------------------
  405|       |					/* with Authentication key, can only decrypt if can change MSE */
  406|    163|					if (i == 2 && !(priv->ext_caps & EXT_CAP_MSE)) {
  ------------------
  |  Branch (406:10): [True: 59, False: 104]
  |  Branch (406:20): [True: 44, False: 15]
  ------------------
  407|     44|						prkey_info.usage &= ~PGP_ENC_PRKEY_USAGE;
  ------------------
  |  |   81|     44|#define	PGP_ENC_PRKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_DECRYPT \
  |  |  ------------------
  |  |  |  |  306|     44|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  |  |  ------------------
  |  |   82|     44|				| SC_PKCS15_PRKEY_USAGE_UNWRAP)
  |  |  ------------------
  |  |  |  |  310|     44|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  |  |  ------------------
  ------------------
  408|     44|					}
  409|    163|					prkey_info.modulus_length = bebytes2ushort(cxdata + 1);
  410|    163|					r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  411|    163|					break;
  412|    163|				}
  413|       |				/* Fallthrough */
  414|    138|			default:
  ------------------
  |  Branch (414:4): [True: 134, False: 167]
  ------------------
  415|    138|				sc_log(ctx, "Invalid algorithm identifier %x (length = %d)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  416|    301|					cxdata[0], r);
  417|    301|			}
  418|       |
  419|    301|			if (r < 0) {
  ------------------
  |  Branch (419:8): [True: 3, False: 298]
  ------------------
  420|      3|				r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
  421|      3|				goto failed;
  422|      3|			}
  423|    301|		}
  424|    523|	}
  425|       |
  426|    146|	sc_log(ctx, "Adding public keys");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  427|       |	/* Add public keys */
  428|    570|	for (i = 0; i < 3; i++) {
  ------------------
  |  Branch (428:14): [True: 429, False: 141]
  ------------------
  429|    429|		sc_pkcs15_pubkey_info_t pubkey_info;
  430|    429|		sc_pkcs15_object_t      pubkey_obj;
  431|    429|		u8 cxdata[12];
  432|    429|		int cxdata_len = sizeof(cxdata);
  433|    429|		char path_template[] = "006E:0073:00Cx";
  434|    429|		int j;
  435|       |
  436|    429|		memset(&pubkey_info, 0, sizeof(pubkey_info));
  437|    429|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
  438|    429|		memset(&cxdata, 0, sizeof(cxdata));
  439|       |
  440|    429|		path_template[13] = '1' + i; /* The needed tags are C1 C2 and C3 */
  441|    429|		if ((cxdata_len = read_file(card, path_template, cxdata, sizeof(cxdata))) < 1)
  ------------------
  |  Branch (441:7): [True: 0, False: 429]
  ------------------
  442|      0|			goto failed;
  443|       |
  444|       |		/* check validity using finger prints */
  445|  1.11k|		for (j = 19; j >= 0; j--) {
  ------------------
  |  Branch (445:16): [True: 1.10k, False: 12]
  ------------------
  446|  1.10k|			if (c5data[20 * i + j] != '\0')
  ------------------
  |  Branch (446:8): [True: 417, False: 686]
  ------------------
  447|    417|				break;
  448|  1.10k|		}
  449|       |
  450|       |		/* only add valid keys, i.e. those with a legal algorithm identifier & finger print */
  451|    429|		if (j >= 0 && cxdata[0] != 0) {
  ------------------
  |  Branch (451:7): [True: 417, False: 12]
  |  Branch (451:17): [True: 406, False: 11]
  ------------------
  452|    406|			struct sc_object_id oid;
  453|    406|			struct sc_algorithm_info * algorithm_info; /* no need to free */
  454|       |
  455|    406|			algorithm_info = NULL;
  456|    406|			pubkey_info.id.len         = 1;
  457|    406|			pubkey_info.id.value[0]    = i + 1;
  458|    406|			pubkey_info.usage          = key_cfg[i].pubkey_usage;
  459|    406|			sc_format_path(key_cfg[i].pubkey_path, &pubkey_info.path);
  460|       |
  461|    406|			strlcpy(pubkey_obj.label, key_cfg[i].label, sizeof(pubkey_obj.label));
  ------------------
  |  |   43|    406|#define strlcpy _strlcpy
  ------------------
  462|    406|			pubkey_obj.flags = SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|    406|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  463|       |
  464|    406|			if (cxdata[0] == SC_OPENPGP_KEYALGO_ECDH ||
  ------------------
  |  |  878|    812|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (464:8): [True: 70, False: 336]
  ------------------
  465|    336|				cxdata[0] == SC_OPENPGP_KEYALGO_ECDSA ||
  ------------------
  |  |  879|    742|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (465:5): [True: 8, False: 328]
  ------------------
  466|    328|				cxdata[0] == SC_OPENPGP_KEYALGO_EDDSA) {
  ------------------
  |  |  880|    328|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (466:5): [True: 74, False: 254]
  ------------------
  467|       |				/* Last byte could be Import-Format of private key, let's ignore it,
  468|       |				 * as it is not part of OID */
  469|    152|				if (cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STD ||
  ------------------
  |  |  887|    304|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (469:9): [True: 13, False: 139]
  ------------------
  470|    139|				    cxdata[cxdata_len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB)
  ------------------
  |  |  888|    139|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (470:9): [True: 6, False: 133]
  ------------------
  471|     19|					cxdata_len--;
  472|    152|				r = sc_asn1_decode_object_id(&cxdata[1], cxdata_len-1, &oid);
  473|    152|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    152|#define SC_SUCCESS				0
  ------------------
  |  Branch (473:9): [True: 120, False: 32]
  ------------------
  474|    120|					sc_log(ctx, "Failed to parse OID for elliptic curve algorithm");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  475|    120|				}
  476|    152|			}
  477|       |
  478|    406|			switch (cxdata[0]) {
  ------------------
  |  Branch (478:12): [True: 152, False: 254]
  ------------------
  479|     70|			case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  878|     70|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (479:4): [True: 70, False: 336]
  ------------------
  480|     70|				if (sc_compare_oid(&oid, &curve25519_oid)) {
  ------------------
  |  Branch (480:9): [True: 0, False: 70]
  ------------------
  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|     78|			case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  879|     78|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (490:4): [True: 8, False: 398]
  ------------------
  491|     78|				if((algorithm_info = sc_card_find_ec_alg(card, 0, &oid)))
  ------------------
  |  Branch (491:8): [True: 0, False: 78]
  ------------------
  492|      0|					pubkey_info.field_length = algorithm_info->key_length;
  493|     78|				else {
  494|     78|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  495|     78|					continue;
  496|     78|				}
  497|      0|				break;
  498|     74|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|     74|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (498:4): [True: 74, False: 332]
  ------------------
  499|     74|				if ((algorithm_info = sc_card_find_eddsa_alg(card, 0, &oid)))
  ------------------
  |  Branch (499:9): [True: 0, False: 74]
  ------------------
  500|      0|					pubkey_info.field_length = algorithm_info->key_length;
  501|     74|				else {
  502|     74|					sc_log(ctx, "algorithm not found");
  ------------------
  |  |   71|     74|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|     74|					continue;
  504|     74|				}
  505|      0|				break;
  506|    406|			}
  507|       |
  508|    254|			switch (cxdata[0]) {
  509|      0|			case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  880|      0|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (509:4): [True: 0, False: 254]
  ------------------
  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: 254]
  ------------------
  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: 254]
  ------------------
  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|    130|			case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  877|    130|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (531:4): [True: 130, False: 124]
  ------------------
  532|    130|				if (cxdata_len >= 3) {
  ------------------
  |  Branch (532:9): [True: 126, False: 4]
  ------------------
  533|       |					/* with Authentication pubkey, can only encrypt if can change MSE */
  534|    126|					if (i == 2 && !(priv->ext_caps & EXT_CAP_MSE)) {
  ------------------
  |  Branch (534:10): [True: 59, False: 67]
  |  Branch (534:20): [True: 44, False: 15]
  ------------------
  535|     44|						pubkey_info.usage &= ~PGP_ENC_PUBKEY_USAGE;
  ------------------
  |  |   87|     44|#define	PGP_ENC_PUBKEY_USAGE	(SC_PKCS15_PRKEY_USAGE_ENCRYPT \
  |  |  ------------------
  |  |  |  |  305|     44|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  |  |  ------------------
  |  |   88|     44|				| SC_PKCS15_PRKEY_USAGE_WRAP)
  |  |  ------------------
  |  |  |  |  309|     44|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  |  |  ------------------
  ------------------
  536|     44|					}
  537|    126|					pubkey_info.modulus_length = bebytes2ushort(cxdata + 1);
  538|    126|					r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  539|    126|					break;
  540|    126|				}
  541|       |				/* Fall through */
  542|    128|			default:
  ------------------
  |  Branch (542:4): [True: 124, False: 130]
  ------------------
  543|    128|				sc_log(ctx, "Invalid algorithm identifier %x (length = %d)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  544|    254|					cxdata[0], r);
  545|    254|			}
  546|       |
  547|    254|			if (r < 0) {
  ------------------
  |  Branch (547:8): [True: 5, False: 249]
  ------------------
  548|      5|				r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      5|#define SC_ERROR_INTERNAL			-1400
  ------------------
  549|      5|				goto failed;
  550|      5|			}
  551|    254|		}
  552|    429|	}
  553|       |
  554|       |	/* Check if certificate DO 7F21 holds data */
  555|    141|	sc_format_path("7F21", &path);
  556|    141|	r = sc_select_file(card, &path, &file);
  557|    141|	if (r < 0)
  ------------------
  |  Branch (557:6): [True: 1, False: 140]
  ------------------
  558|      1|		goto failed;
  559|       |
  560|    231|	for(u8 i=0; i<PGP_MAX_NUM_CERTS; i++) {
  ------------------
  |  |   47|    231|#define PGP_MAX_NUM_CERTS    3
  ------------------
  |  Branch (560:14): [True: 208, False: 23]
  ------------------
  561|    208|		struct sc_pkcs15_cert_info cert_info;
  562|    208|		struct sc_pkcs15_object    cert_obj;
  563|    208|		u8* buffer = malloc(MAX_OPENPGP_DO_SIZE);
  ------------------
  |  |  172|    208|#define	MAX_OPENPGP_DO_SIZE	8192
  ------------------
  564|    208|		int resp_len = 0;
  565|       |
  566|    208|		if (buffer == NULL)
  ------------------
  |  Branch (566:7): [True: 0, False: 208]
  ------------------
  567|      0|			goto failed;
  568|       |
  569|    208|		memset(&cert_info, 0, sizeof(cert_info));
  570|    208|		memset(&cert_obj,  0, sizeof(cert_obj));
  571|       |
  572|       |		/* try to SELECT DATA. Will only work for OpenPGP >= v3, errors are non-critical */
  573|    208|		sc_card_ctl(card, SC_CARDCTL_OPENPGP_SELECT_DATA, &i);
  574|       |
  575|    208|		sc_format_path(certs[i].path, &cert_info.path);
  576|       |
  577|       |		/* Certificate ID. We use the same ID as the authentication key */
  578|    208|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  579|       |
  580|    208|		resp_len = sc_get_data(card, 0x7F21, buffer, MAX_OPENPGP_DO_SIZE);
  ------------------
  |  |  172|    208|#define	MAX_OPENPGP_DO_SIZE	8192
  ------------------
  581|       |
  582|       |		/* Response length => free buffer and continue with next id */
  583|    208|		if (resp_len == 0) {
  ------------------
  |  Branch (583:7): [True: 57, False: 151]
  ------------------
  584|     57|			free(buffer);
  585|     57|			continue;
  586|     57|		}
  587|       |
  588|       |		/* Catch error during sc_get_data */
  589|    151|		if (resp_len < 0) {
  ------------------
  |  Branch (589:7): [True: 106, False: 45]
  ------------------
  590|    106|			free(buffer);
  591|    106|			goto failed;
  592|    106|		}
  593|       |
  594|       |		/* Assemble certificate info struct, based on `certs` array */
  595|     45|		cert_info.value.len = resp_len;
  596|     45|		cert_info.value.value = buffer;
  597|     45|		cert_info.authority = certs[i].authority;
  598|     45|		cert_obj.flags = certs[i].obj_flags;
  599|       |
  600|       |		/* Object label */
  601|     45|		strlcpy(cert_obj.label, certs[i].label, sizeof(cert_obj.label));
  ------------------
  |  |   43|     45|#define strlcpy _strlcpy
  ------------------
  602|       |
  603|     45|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  604|     45|		if (r < 0) {
  ------------------
  |  Branch (604:7): [True: 0, False: 45]
  ------------------
  605|      0|			free(buffer);
  606|      0|			goto failed;
  607|      0|		}
  608|       |
  609|       |		/* only iterate, for OpenPGP >= v3, thus break on < v3 */
  610|     45|		if (card->type < SC_CARD_TYPE_OPENPGP_V3)
  ------------------
  |  Branch (610:7): [True: 11, False: 34]
  ------------------
  611|     11|			break;
  612|     45|	}
  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|     34|	sc_pkcs15emu_openpgp_add_data(p15card);
  618|       |
  619|    680|failed:
  620|    680|	if (r < 0) {
  ------------------
  |  Branch (620:6): [True: 490, False: 190]
  ------------------
  621|    490|		sc_log(card->ctx,
  ------------------
  |  |   71|    490|#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|    490|				"Failed to initialize OpenPGP emulation: %s\n",
  623|    490|				sc_strerror(r));
  624|    490|		sc_pkcs15_card_clear(p15card);
  625|    490|	}
  626|    680|	sc_file_free(file);
  627|    680|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    680|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    680|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    680|	int _ret = r; \
  |  |  |  |  155|    680|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 671, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  156|    671|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    490|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 490, False: 181]
  |  |  |  |  ------------------
  |  |  |  |  157|    671|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    671|	} 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|    680|	return _ret; \
  |  |  |  |  163|    680|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  628|    680|}
pkcs15-openpgp.c:read_file:
  162|  2.25k|{
  163|  2.25k|	sc_path_t	path;
  164|  2.25k|	sc_file_t	*file;
  165|  2.25k|	int		r;
  166|       |
  167|  2.25k|	sc_format_path(path_name, &path);
  168|  2.25k|	if ((r = sc_select_file(card, &path, &file)) < 0)
  ------------------
  |  Branch (168:6): [True: 527, False: 1.72k]
  ------------------
  169|    527|		return r;
  170|       |
  171|  1.72k|	if (file->size < len)
  ------------------
  |  Branch (171:6): [True: 1.68k, False: 39]
  ------------------
  172|  1.68k|		len = file->size;
  173|       |
  174|  1.72k|	sc_file_free(file);
  175|       |
  176|  1.72k|	return sc_read_binary(card, 0, (u8 *) buf, len, 0);
  177|  2.25k|}
pkcs15-openpgp.c:sc_pkcs15emu_openpgp_add_data:
  635|     34|{
  636|     34|	sc_context_t *ctx = p15card->card->ctx;
  637|     34|	int i, r;
  638|       |
  639|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|       |	/* Optional private use DOs 0101 to 0104 */
  641|    170|	for (i = 1; i <= PGP_NUM_PRIVDO; i++) {
  ------------------
  |  |   46|    170|#define PGP_NUM_PRIVDO       4
  ------------------
  |  Branch (641:14): [True: 136, False: 34]
  ------------------
  642|    136|		sc_pkcs15_data_info_t dat_info;
  643|    136|		sc_pkcs15_object_t dat_obj;
  644|    136|		char name[6 + LEN_MAX_INT_AS_STR];
  645|    136|		char path[7 + LEN_MAX_INT_AS_STR];
  646|    136|		u8 content[254];
  647|    136|		memset(&dat_info, 0, sizeof(dat_info));
  648|    136|		memset(&dat_obj, 0, sizeof(dat_obj));
  649|       |
  650|    136|		snprintf(name, 8, "PrivDO%d", i);
  651|    136|		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|    136|		r = read_file(p15card->card, path, content, sizeof(content));
  657|    136|		if (r <= 0 ) {
  ------------------
  |  Branch (657:7): [True: 89, False: 47]
  ------------------
  658|     89|			sc_log(ctx, "Cannot read DO 010%d or there is no data in it", i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  659|       |			/* Skip */
  660|     89|			continue;
  661|     89|		}
  662|     47|		sc_format_path(path, &dat_info.path);
  663|     47|		strlcpy(dat_obj.label, name, sizeof(dat_obj.label));
  ------------------
  |  |   43|     47|#define strlcpy _strlcpy
  ------------------
  664|     47|		strlcpy(dat_info.app_label, name, sizeof(dat_info.app_label));
  ------------------
  |  |   43|     47|#define strlcpy _strlcpy
  ------------------
  665|       |
  666|       |		/* Add DATA object to slot protected by PIN2 (PW1 with Ref 0x82) */
  667|     47|		dat_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   50|     47|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
              		dat_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE | SC_PKCS15_CO_FLAG_MODIFIABLE;
  ------------------
  |  |   51|     47|#define SC_PKCS15_CO_FLAG_MODIFIABLE	0x00000002
  ------------------
  668|     47|		dat_obj.auth_id.len = 1;
  669|     47|		if (i == 1 || i == 3)
  ------------------
  |  Branch (669:7): [True: 10, False: 37]
  |  Branch (669:17): [True: 8, False: 29]
  ------------------
  670|     18|			dat_obj.auth_id.value[0] = 2;
  671|     29|		else
  672|     29|			dat_obj.auth_id.value[0] = 3;
  673|       |
  674|     47|		sc_log(ctx, "Add %s data object", name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  675|     47|		r = sc_pkcs15emu_add_data_object(p15card, &dat_obj, &dat_info);
  676|     47|		LOG_TEST_RET(ctx, r, "Could not add data object to framework");
  ------------------
  |  |  174|     47|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     47|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     47|	int _ret = (r); \
  |  |  |  |  168|     47|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 47]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  677|     47|	}
  678|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  679|     34|}

sc_pkcs15_decode_aodf_entry:
   85|      8|{
   86|      8|	sc_context_t *ctx = p15card->card->ctx;
   87|      8|	struct sc_pkcs15_auth_info info;
   88|      8|	int r;
   89|      8|	size_t flags_len = sizeof(info.attrs.pin.flags);
   90|      8|	size_t derived_len = sizeof(info.attrs.authkey.derived);
   91|      8|	size_t padchar_len = 1;
   92|      8|	struct sc_asn1_entry asn1_com_ao_attr[2];
   93|      8|	struct sc_asn1_entry asn1_pin_attr[10], asn1_type_pin_attr[2];
   94|      8|	struct sc_asn1_entry asn1_authkey_attr[3], asn1_type_authkey_attr[2];
   95|      8|	struct sc_asn1_entry asn1_auth_type[2];
   96|      8|	struct sc_asn1_entry asn1_auth_type_choice[4];
   97|      8|	struct sc_asn1_pkcs15_object pin_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_pin_attr };
   98|      8|	struct sc_asn1_pkcs15_object authkey_obj = { obj, asn1_com_ao_attr, NULL, asn1_type_authkey_attr };
   99|       |
  100|      8|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_ASN1);
  ------------------
  |  |  148|      8|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|      8|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|      8|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 8]
  |  |  ------------------
  ------------------
  101|       |
  102|      8|	sc_copy_asn1_entry(c_asn1_auth_type, asn1_auth_type);
  103|      8|	sc_copy_asn1_entry(c_asn1_auth_type_choice, asn1_auth_type_choice);
  104|       |
  105|      8|	sc_copy_asn1_entry(c_asn1_com_ao_attr, asn1_com_ao_attr);
  106|       |
  107|      8|	sc_copy_asn1_entry(c_asn1_type_pin_attr, asn1_type_pin_attr);
  108|      8|	sc_copy_asn1_entry(c_asn1_pin_attr, asn1_pin_attr);
  109|       |
  110|      8|	sc_copy_asn1_entry(c_asn1_type_authkey_attr, asn1_type_authkey_attr);
  111|      8|	sc_copy_asn1_entry(c_asn1_authkey_attr, asn1_authkey_attr);
  112|       |
  113|      8|	sc_format_asn1_entry(asn1_auth_type + 0, asn1_auth_type_choice, NULL, 0);
  114|      8|	sc_format_asn1_entry(asn1_auth_type_choice + 0, &pin_obj, NULL, 0);	/* 'pin' */
  115|      8|	sc_format_asn1_entry(asn1_auth_type_choice + 2, &authkey_obj, NULL, 0);	/* 'authKey' */
  116|       |
  117|       |	/* pinAttributes */
  118|      8|	sc_format_asn1_entry(asn1_type_pin_attr + 0, asn1_pin_attr, NULL, 0);
  119|      8|	sc_format_asn1_entry(asn1_pin_attr + 0, &info.attrs.pin.flags, &flags_len, 0);
  120|      8|	sc_format_asn1_entry(asn1_pin_attr + 1, &info.attrs.pin.type, NULL, 0);
  121|      8|	sc_format_asn1_entry(asn1_pin_attr + 2, &info.attrs.pin.min_length, NULL, 0);
  122|      8|	sc_format_asn1_entry(asn1_pin_attr + 3, &info.attrs.pin.stored_length, NULL, 0);
  123|      8|	sc_format_asn1_entry(asn1_pin_attr + 4, &info.attrs.pin.max_length, NULL, 0);
  124|      8|	sc_format_asn1_entry(asn1_pin_attr + 5, &info.attrs.pin.reference, NULL, 0);
  125|      8|	sc_format_asn1_entry(asn1_pin_attr + 6, &info.attrs.pin.pad_char, &padchar_len, 0);
  126|       |
  127|       |	/* authKeyAttributes */
  128|      8|	sc_format_asn1_entry(asn1_type_authkey_attr + 0, asn1_authkey_attr, NULL, 0);
  129|      8|	sc_format_asn1_entry(asn1_authkey_attr + 0, &info.attrs.authkey.derived, &derived_len, 0);
  130|      8|	sc_format_asn1_entry(asn1_authkey_attr + 1, &info.attrs.authkey.skey_id, NULL, 0);
  131|       |
  132|       |	/* We don't support lastPinChange yet. */
  133|      8|	sc_format_asn1_entry(asn1_pin_attr + 8, &info.path, NULL, 0);
  134|       |
  135|      8|	sc_format_asn1_entry(asn1_com_ao_attr + 0, &info.auth_id, NULL, 0);
  136|       |
  137|       |	/* Fill in defaults */
  138|      8|	memset(&info, 0, sizeof(info));
  139|      8|	info.tries_left = -1;
  140|      8|	info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  430|      8|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  141|       |
  142|      8|	r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
  143|      8|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|      8|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (143:6): [True: 1, False: 7]
  ------------------
  144|      1|		return r;
  145|      7|	LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  146|       |
  147|      1|	if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|      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)   {
  ------------------
  |  |  171|      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)   {
  ------------------
  |  |  171|      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))
  ------------------
  |  |  171|      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.09k|{
  299|  7.09k|	struct sc_context *ctx = p15card->card->ctx;
  300|  7.09k|	struct sc_pkcs15_auth_info *auth_info;
  301|  7.09k|	int r;
  302|       |
  303|  7.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  7.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|       |
  305|  7.09k|	if (!pin_obj || !pin_obj->data)
  ------------------
  |  Branch (305:6): [True: 0, False: 7.09k]
  |  Branch (305:18): [True: 0, False: 7.09k]
  ------------------
  306|  7.09k|		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.09k|	auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  308|       |
  309|       |	/* Check the provided pin matches pin requirements */
  310|  7.09k|	r = _validate_pin(p15card, auth_info, pinlen);
  311|       |
  312|  7.09k|	if (r)
  ------------------
  |  Branch (312:6): [True: 6.23k, False: 862]
  ------------------
  313|  7.09k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  6.23k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.23k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.23k|	int _ret = r; \
  |  |  |  |  155|  6.23k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6.23k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  6.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|  6.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 6.23k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  6.23k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  6.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|  6.23k|	return _ret; \
  |  |  |  |  163|  6.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  314|       |
  315|    862|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pincode, pinlen);
  316|       |
  317|    862|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    862|#define SC_SUCCESS				0
  ------------------
  |  Branch (317:6): [True: 265, False: 597]
  ------------------
  318|    265|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  319|       |
  320|    862|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    862|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    862|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    862|	int _ret = r; \
  |  |  |  |  155|    862|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 862, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    862|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    597|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 597, False: 265]
  |  |  |  |  ------------------
  |  |  |  |  157|    862|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    862|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    862|	return _ret; \
  |  |  |  |  163|    862|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  321|    862|}
_sc_pkcs15_verify_pin:
  327|  1.23k|{
  328|  1.23k|	return sc_pkcs15_verify_pin_with_session_pin(p15card, pin_obj, pincode,
  329|  1.23k|			pinlen, NULL, NULL);
  330|  1.23k|}
sc_pkcs15_verify_pin_with_session_pin:
  343|  1.23k|{
  344|  1.23k|	struct sc_context *ctx = p15card->card->ctx;
  345|  1.23k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  346|  1.23k|	int r;
  347|  1.23k|	sc_card_t *card;
  348|  1.23k|	struct sc_pin_cmd_data data;
  349|       |
  350|  1.23k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.23k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.23k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.23k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.23k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|  1.23k|	sc_log(ctx, "PIN(type:%X; method:%X; value(%p:%zu)",
  ------------------
  |  |   71|  1.23k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  352|  1.23k|			auth_info->auth_type, auth_info->auth_method, pincode, pinlen);
  353|  1.23k|	card = p15card->card;
  354|       |
  355|  1.23k|	if (pinlen > SC_MAX_PIN_SIZE) {
  ------------------
  |  |   40|  1.23k|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (355:6): [True: 0, False: 1.23k]
  ------------------
  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.23k|	memset(&data, 0, sizeof(data));
  363|  1.23k|	data.pin_type = auth_info->auth_method;
  364|       |
  365|  1.23k|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|  1.23k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (365:6): [True: 1.23k, False: 0]
  ------------------
  366|  1.23k|		data.pin_reference = auth_info->attrs.pin.reference;
  367|  1.23k|		data.pin1.min_length = auth_info->attrs.pin.min_length;
  368|  1.23k|		data.pin1.max_length = auth_info->attrs.pin.max_length;
  369|  1.23k|		data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  370|  1.23k|		data.pin1.pad_char = auth_info->attrs.pin.pad_char;
  371|  1.23k|		data.pin1.data = pincode;
  372|  1.23k|		data.pin1.len = pinlen;
  373|       |
  374|  1.23k|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|  1.23k|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (374:7): [True: 381, False: 853]
  ------------------
  375|    381|			data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    381|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  376|       |
  377|  1.23k|		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.22k]
  ------------------
  379|     14|			data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|     14|#define SC_PIN_ENCODING_BCD	1
  ------------------
  380|     14|			break;
  381|    853|		case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    853|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (381:3): [True: 853, False: 381]
  ------------------
  382|    853|			data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    853|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  383|    853|			break;
  384|    367|		default:
  ------------------
  |  Branch (384:3): [True: 367, False: 867]
  ------------------
  385|       |			/* assume/hope the card driver knows how to encode the pin */
  386|    367|			data.pin1.encoding = 0;
  387|  1.23k|		}
  388|  1.23k|	}
  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.23k|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|  2.46k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (405:7): [True: 0, False: 1.23k]
  ------------------
  406|  1.23k|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|  1.23k|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (406:8): [True: 0, False: 1.23k]
  ------------------
  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.23k|	if (card->caps & SC_CARD_CAP_SESSION_PIN && sessionpin && sessionpinlen) {
  ------------------
  |  |  563|  2.46k|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
  |  Branch (416:6): [True: 0, False: 1.23k]
  |  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.23k|	} else {
  423|       |		/* perform a standard verify */
  424|  1.23k|		data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|  1.23k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  425|  1.23k|		if (sessionpinlen)
  ------------------
  |  Branch (425:7): [True: 0, False: 1.23k]
  ------------------
  426|      0|			*sessionpinlen = 0;
  427|  1.23k|	}
  428|       |
  429|  1.23k|	r = sc_lock(card);
  430|  1.23k|	LOG_TEST_RET(ctx, r, "sc_lock() 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: 0, False: 1.23k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.23k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.23k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|       |
  432|       |	/* the path in the pin object is optional */
  433|  1.23k|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (433:6): [True: 386, False: 848]
  |  Branch (433:35): [True: 18, False: 830]
  ------------------
  434|    404|		r = sc_select_file(card, &auth_info->path, NULL);
  435|    404|		if (r)
  ------------------
  |  Branch (435:7): [True: 80, False: 324]
  ------------------
  436|     80|			goto out;
  437|    404|	}
  438|       |
  439|  1.15k|	r = sc_pin_cmd(card, &data);
  440|  1.15k|	auth_info->tries_left = data.pin1.tries_left;
  441|  1.15k|	sc_log(ctx, "PIN cmd result %i", r);
  ------------------
  |  |   71|  1.15k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  442|  1.15k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.15k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 610, False: 544]
  ------------------
  443|    610|		sc_pkcs15_pincache_add(p15card, pin_obj, pincode, pinlen);
  444|    610|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|  1.22k|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (444:7): [True: 0, False: 610]
  |  Branch (444:49): [True: 0, False: 0]
  ------------------
  445|      0|			*sessionpinlen = data.pin2.len;
  446|      0|		}
  447|    610|	} else {
  448|    544|		sc_notify_id(card->ctx, &card->reader->atr, p15card,
  449|    544|				NOTIFY_PIN_BAD);
  450|    544|		if (data.cmd == SC_PIN_CMD_GET_SESSION_PIN && sessionpinlen) {
  ------------------
  |  |  419|  1.08k|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (450:7): [True: 0, False: 544]
  |  Branch (450:49): [True: 0, False: 0]
  ------------------
  451|      0|			*sessionpinlen = 0;
  452|      0|		}
  453|    544|	}
  454|       |
  455|  1.15k|	if (auth_info->auth_type == SC_PKCS15_PIN_AUTH_TYPE_PIN
  ------------------
  |  |   94|  2.30k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (455:6): [True: 1.15k, False: 0]
  ------------------
  456|  1.15k|			&& auth_info->auth_method != SC_AC_SESSION
  ------------------
  |  |  159|  2.30k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (456:7): [True: 1.15k, False: 0]
  ------------------
  457|  1.15k|			&& r == SC_SUCCESS
  ------------------
  |  |   28|  2.30k|#define SC_SUCCESS				0
  ------------------
  |  Branch (457:7): [True: 610, False: 544]
  ------------------
  458|    610|			&& (data.flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  421|    610|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (458:7): [True: 0, False: 610]
  ------------------
  459|      0|		sc_notify_id(card->ctx, &card->reader->atr, p15card, NOTIFY_PIN_GOOD);
  460|      0|	}
  461|       |
  462|  1.23k|out:
  463|  1.23k|	sc_unlock(card);
  464|  1.23k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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|    624|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 624, False: 610]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  465|  1.23k|}
sc_pkcs15_change_pin:
  476|  7.09k|{
  477|  7.09k|	struct sc_context *ctx = p15card->card->ctx;
  478|  7.09k|	struct sc_pin_cmd_data data;
  479|  7.09k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  480|  7.09k|	struct sc_card *card;
  481|  7.09k|	int r;
  482|       |
  483|  7.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  7.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  484|  7.09k|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  7.09k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (484:6): [True: 0, False: 7.09k]
  ------------------
  485|  7.09k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  486|       |
  487|       |	/* make sure the pins are in valid range */
  488|  7.09k|	r = _validate_pin(p15card, auth_info, oldpinlen);
  489|  7.09k|	LOG_TEST_RET(ctx, r, "Old PIN value do not conform PIN policy");
  ------------------
  |  |  174|  7.09k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.09k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.09k|	int _ret = (r); \
  |  |  |  |  168|  7.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.23k, False: 862]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.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|  6.23k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.23k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.23k|		return _ret; \
  |  |  |  |  172|  6.23k|	} \
  |  |  |  |  173|  7.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 862]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  490|       |
  491|    862|	r = _validate_pin(p15card, auth_info, newpinlen);
  492|    862|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  174|    862|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    862|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    862|	int _ret = (r); \
  |  |  |  |  168|    862|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 439, False: 423]
  |  |  |  |  ------------------
  |  |  |  |  169|    439|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    439|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    439|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    439|		return _ret; \
  |  |  |  |  172|    439|	} \
  |  |  |  |  173|    862|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 423]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  493|       |
  494|    423|	card = p15card->card;
  495|    423|	r = sc_lock(card);
  496|    423|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    423|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    423|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    423|	int _ret = (r); \
  |  |  |  |  168|    423|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 423]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    423|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 423]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  497|       |	/* the path in the pin object is optional */
  498|    423|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (498:6): [True: 153, False: 270]
  |  Branch (498:35): [True: 12, False: 258]
  ------------------
  499|    165|		r = sc_select_file(card, &auth_info->path, NULL);
  500|    165|		if (r)
  ------------------
  |  Branch (500:7): [True: 35, False: 130]
  ------------------
  501|     35|			goto out;
  502|    165|	}
  503|       |
  504|       |	/* set pin_cmd data */
  505|    388|	memset(&data, 0, sizeof(data));
  506|    388|	data.cmd             = SC_PIN_CMD_CHANGE;
  ------------------
  |  |  416|    388|#define SC_PIN_CMD_CHANGE	1
  ------------------
  507|    388|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|    388|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  508|    388|	data.pin_reference   = auth_info->attrs.pin.reference;
  509|    388|	data.pin1.data       = oldpin;
  510|    388|	data.pin1.len        = oldpinlen;
  511|    388|	data.pin1.pad_char   = auth_info->attrs.pin.pad_char;
  512|    388|	data.pin1.min_length = auth_info->attrs.pin.min_length;
  513|    388|	data.pin1.max_length = auth_info->attrs.pin.max_length;
  514|    388|	data.pin1.pad_length = auth_info->attrs.pin.stored_length;
  515|    388|	data.pin2.data       = newpin;
  516|    388|	data.pin2.len        = newpinlen;
  517|    388|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  518|    388|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  519|    388|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  520|    388|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  521|       |
  522|    388|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    388|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (522:6): [True: 181, False: 207]
  ------------------
  523|    181|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    181|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  524|       |
  525|    388|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (525:10): [True: 274, False: 114]
  ------------------
  526|      8|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      8|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (526:2): [True: 8, False: 380]
  ------------------
  527|      8|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      8|#define SC_PIN_ENCODING_BCD	1
  ------------------
  528|      8|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      8|#define SC_PIN_ENCODING_BCD	1
  ------------------
  529|      8|		break;
  530|    266|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    266|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (530:2): [True: 266, False: 122]
  ------------------
  531|    266|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    266|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  532|    266|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    266|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  533|    266|		break;
  534|    388|	}
  535|       |
  536|    388|	if((!oldpin || !newpin)
  ------------------
  |  Branch (536:6): [True: 0, False: 388]
  |  Branch (536:17): [True: 0, False: 388]
  ------------------
  537|      0|			&& (p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (537:8): [True: 0, False: 0]
  ------------------
  538|      0|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|      0|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (538:8): [True: 0, False: 0]
  ------------------
  539|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  540|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (540:7): [True: 0, False: 0]
  ------------------
  541|      0|			data.pin1.prompt = "Please enter SO PIN";
  542|      0|			data.pin2.prompt = "Please enter new SO PIN";
  543|      0|		}
  544|      0|		else {
  545|      0|			data.pin1.prompt = "Please enter PIN";
  546|      0|			data.pin2.prompt = "Please enter new PIN";
  547|      0|		}
  548|      0|	}
  549|       |
  550|    388|	r = sc_pin_cmd(card, &data);
  551|    388|	auth_info->tries_left = data.pin1.tries_left;
  552|    388|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    388|#define SC_SUCCESS				0
  ------------------
  |  Branch (552:6): [True: 78, False: 310]
  ------------------
  553|     78|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  554|       |
  555|    423|out:
  556|    423|	sc_unlock(card);
  557|    423|	return r;
  558|    388|}
sc_pkcs15_unblock_pin:
  567|  7.09k|{
  568|  7.09k|	struct sc_context *ctx = p15card->card->ctx;
  569|  7.09k|	struct sc_pin_cmd_data data;
  570|  7.09k|	struct sc_pkcs15_object *puk_obj;
  571|  7.09k|	struct sc_pkcs15_auth_info *puk_info = NULL;
  572|  7.09k|	int pukref = 0;
  573|  7.09k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  574|  7.09k|	struct sc_card *card = p15card->card;
  575|  7.09k|	int r;
  576|       |
  577|  7.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  7.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  578|  7.09k|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  7.09k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (578:6): [True: 0, False: 7.09k]
  ------------------
  579|  7.09k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|       |
  581|       |	/* make sure the pins are in valid range */
  582|  7.09k|	r = _validate_pin(p15card, auth_info, newpinlen);
  583|  7.09k|	LOG_TEST_RET(ctx, r, "New PIN value do not conform PIN policy");
  ------------------
  |  |  174|  7.09k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.09k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.09k|	int _ret = (r); \
  |  |  |  |  168|  7.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6.58k, False: 505]
  |  |  |  |  ------------------
  |  |  |  |  169|  6.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|  6.58k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  6.58k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  6.58k|		return _ret; \
  |  |  |  |  172|  6.58k|	} \
  |  |  |  |  173|  7.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 505]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  584|       |
  585|       |	/* get pin_info object of the puk (this is a little bit complicated
  586|       |	 * as we don't have the id of the puk (at least now))
  587|       |	 * note: for compatibility reasons we give no error if no puk object
  588|       |	 * is found */
  589|       |	/* first step: try to get the pkcs15 object of the puk */
  590|    505|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &pin_obj->auth_id, &puk_obj);
  591|    505|	if (r >= 0 && puk_obj) {
  ------------------
  |  Branch (591:6): [True: 216, False: 289]
  |  Branch (591:16): [True: 216, False: 0]
  ------------------
  592|       |		/* second step:  get the pkcs15 info object of the puk */
  593|    216|		puk_info = (struct sc_pkcs15_auth_info *)puk_obj->data;
  594|    216|		pukref = puk_info->attrs.pin.reference;
  595|    216|	}
  596|       |
  597|    505|	if (!puk_info) {
  ------------------
  |  Branch (597:6): [True: 289, False: 216]
  ------------------
  598|    289|		sc_log(ctx, "Unable to get puk object, using pin object instead!");
  ------------------
  |  |   71|    289|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  599|    289|		puk_info = auth_info;
  600|    289|	}
  601|       |	/* make sure the puk is in valid range */
  602|    505|	r = _validate_pin(p15card, puk_info, puklen);
  603|    505|	LOG_TEST_RET(ctx, r, "PIN do not conforms PIN policy");
  ------------------
  |  |  174|    505|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    505|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    505|	int _ret = (r); \
  |  |  |  |  168|    505|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 162, False: 343]
  |  |  |  |  ------------------
  |  |  |  |  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|    505|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 343]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  604|       |
  605|       |	/*
  606|       |	 * With the current card driver interface we have no way of specifying different padding
  607|       |	 * flags for the PIN and the PUK. Therefore reject this case.
  608|       |	 */
  609|    343|	if ((auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING) !=
  ------------------
  |  |   59|    343|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (609:6): [True: 0, False: 343]
  ------------------
  610|    343|	    (puk_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)) {
  ------------------
  |  |   59|    343|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  611|      0|		LOG_TEST_RET(ctx, r, "Padding mismatch for PIN/PUK");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|      0|	}
  613|       |
  614|    343|	r = sc_lock(card);
  615|    343|	LOG_TEST_RET(ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|    343|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    343|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    343|	int _ret = (r); \
  |  |  |  |  168|    343|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 343]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    343|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 343]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  616|       |
  617|       |	/* the path in the pin object is optional */
  618|    343|	if ((auth_info->path.len > 0) || ((auth_info->path.aid.len > 0))) {
  ------------------
  |  Branch (618:6): [True: 149, False: 194]
  |  Branch (618:35): [True: 12, False: 182]
  ------------------
  619|    161|		r = sc_select_file(card, &auth_info->path, NULL);
  620|    161|		if (r)
  ------------------
  |  Branch (620:7): [True: 43, False: 118]
  ------------------
  621|     43|			goto out;
  622|    161|	}
  623|       |
  624|       |	/* set pin_cmd data */
  625|    300|	memset(&data, 0, sizeof(data));
  626|    300|	data.cmd             = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  417|    300|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  627|    300|	data.pin_type        = SC_AC_CHV;
  ------------------
  |  |  151|    300|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  628|    300|	data.pin_reference   = auth_info->attrs.pin.reference;
  629|    300|	data.puk_reference   = pukref;
  630|    300|	data.pin1.data       = puk;
  631|    300|	data.pin1.len        = puklen;
  632|    300|	data.pin1.pad_char   = puk_info->attrs.pin.pad_char;
  633|    300|	data.pin1.min_length = puk_info->attrs.pin.min_length;
  634|    300|	data.pin1.max_length = puk_info->attrs.pin.max_length;
  635|    300|	data.pin1.pad_length = puk_info->attrs.pin.stored_length;
  636|    300|	data.pin2.data       = newpin;
  637|    300|	data.pin2.len        = newpinlen;
  638|    300|	data.pin2.pad_char   = auth_info->attrs.pin.pad_char;
  639|    300|	data.pin2.min_length = auth_info->attrs.pin.min_length;
  640|    300|	data.pin2.max_length = auth_info->attrs.pin.max_length;
  641|    300|	data.pin2.pad_length = auth_info->attrs.pin.stored_length;
  642|       |
  643|    300|	if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_NEEDS_PADDING)
  ------------------
  |  |   59|    300|#define SC_PKCS15_PIN_FLAG_NEEDS_PADDING		0x0020
  ------------------
  |  Branch (643:6): [True: 184, False: 116]
  ------------------
  644|    184|		data.flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  422|    184|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  645|       |
  646|    300|	switch (auth_info->attrs.pin.type) {
  ------------------
  |  Branch (646:10): [True: 199, False: 101]
  ------------------
  647|      7|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      7|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (647:2): [True: 7, False: 293]
  ------------------
  648|      7|		data.pin1.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      7|#define SC_PIN_ENCODING_BCD	1
  ------------------
  649|      7|		break;
  650|    192|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    192|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (650:2): [True: 192, False: 108]
  ------------------
  651|    192|		data.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    192|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  652|    192|		break;
  653|    300|	}
  654|       |
  655|    300|	switch (puk_info->attrs.pin.type) {
  ------------------
  |  Branch (655:10): [True: 198, False: 102]
  ------------------
  656|      7|	case SC_PKCS15_PIN_TYPE_BCD:
  ------------------
  |  |   88|      7|#define SC_PKCS15_PIN_TYPE_BCD				0
  ------------------
  |  Branch (656:2): [True: 7, False: 293]
  ------------------
  657|      7|		data.pin2.encoding = SC_PIN_ENCODING_BCD;
  ------------------
  |  |  426|      7|#define SC_PIN_ENCODING_BCD	1
  ------------------
  658|      7|		break;
  659|    191|	case SC_PKCS15_PIN_TYPE_ASCII_NUMERIC:
  ------------------
  |  |   89|    191|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  |  Branch (659:2): [True: 191, False: 109]
  ------------------
  660|    191|		data.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  425|    191|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  661|    191|		break;
  662|    300|	}
  663|       |
  664|    300|	if((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    600|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (664:6): [True: 0, False: 300]
  ------------------
  665|    300|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)) {
  ------------------
  |  |  560|    300|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (665:8): [True: 0, False: 300]
  ------------------
  666|      0|		data.flags |= SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  667|      0|		if (auth_info->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
  ------------------
  |  |   61|      0|#define SC_PKCS15_PIN_FLAG_SO_PIN			0x0080
  ------------------
  |  Branch (667:7): [True: 0, False: 0]
  ------------------
  668|      0|			data.pin1.prompt = "Please enter PUK";
  669|      0|			data.pin2.prompt = "Please enter new SO PIN";
  670|      0|		}
  671|      0|		else {
  672|      0|			data.pin1.prompt = "Please enter PUK";
  673|      0|			data.pin2.prompt = "Please enter new PIN";
  674|      0|		}
  675|      0|	}
  676|       |
  677|    300|	r = sc_pin_cmd(card, &data);
  678|    300|	auth_info->tries_left = data.pin1.tries_left;
  679|    300|	if (r == SC_SUCCESS)
  ------------------
  |  |   28|    300|#define SC_SUCCESS				0
  ------------------
  |  Branch (679:6): [True: 48, False: 252]
  ------------------
  680|     48|		sc_pkcs15_pincache_add(p15card, pin_obj, newpin, newpinlen);
  681|       |
  682|    343|out:
  683|    343|	sc_unlock(card);
  684|    343|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    343|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    343|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    343|	int _ret = r; \
  |  |  |  |  155|    343|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 343, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    343|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 48]
  |  |  |  |  ------------------
  |  |  |  |  157|    343|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    343|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    343|	return _ret; \
  |  |  |  |  163|    343|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  685|    343|}
sc_pkcs15_get_pin_info:
  689|  7.09k|{
  690|  7.09k|	int r;
  691|  7.09k|	struct sc_pin_cmd_data data;
  692|  7.09k|	struct sc_card *card = p15card->card;
  693|  7.09k|	struct sc_context *ctx = card->ctx;
  694|  7.09k|	struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *) pin_obj->data;
  695|       |
  696|  7.09k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  7.09k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  7.09k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  7.09k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  7.09k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  697|       |
  698|  7.09k|	r = sc_lock(card);
  699|  7.09k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  7.09k|#define SC_SUCCESS				0
  ------------------
  |  Branch (699:6): [True: 0, False: 7.09k]
  ------------------
  700|      0|		return r;
  701|       |
  702|  7.09k|	if (pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|  7.09k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (702:6): [True: 0, False: 7.09k]
  ------------------
  703|      0|		r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  704|      0|		goto out;
  705|      0|	}
  706|       |
  707|       |	/* the path in the pin object is optional */
  708|  7.09k|	if ((pin_info->path.len > 0) || ((pin_info->path.aid.len > 0))) {
  ------------------
  |  Branch (708:6): [True: 794, False: 6.30k]
  |  Branch (708:34): [True: 410, False: 5.89k]
  ------------------
  709|  1.20k|		r = sc_select_file(card, &pin_info->path, NULL);
  710|  1.20k|		if (r)
  ------------------
  |  Branch (710:7): [True: 592, False: 612]
  ------------------
  711|    592|			goto out;
  712|  1.20k|	}
  713|       |
  714|       |	/* Try to update PIN info from card */
  715|  6.50k|	memset(&data, 0, sizeof(data));
  716|  6.50k|	data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  418|  6.50k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  717|  6.50k|	data.pin_type = pin_info->auth_method;
  718|  6.50k|	data.pin_reference = pin_info->attrs.pin.reference;
  719|       |
  720|  6.50k|	r = sc_pin_cmd(card, &data);
  721|  6.50k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  6.50k|#define SC_SUCCESS				0
  ------------------
  |  Branch (721:6): [True: 1.13k, False: 5.37k]
  ------------------
  722|  1.13k|		if (data.pin1.max_tries > 0)
  ------------------
  |  Branch (722:7): [True: 2, False: 1.13k]
  ------------------
  723|      2|			pin_info->max_tries = data.pin1.max_tries;
  724|  1.13k|		pin_info->tries_left = data.pin1.tries_left;
  725|  1.13k|		pin_info->logged_in = data.pin1.logged_in;
  726|  1.13k|	}
  727|       |
  728|  7.09k|out:
  729|  7.09k|	sc_unlock(card);
  730|  7.09k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  7.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.09k|	int _ret = r; \
  |  |  |  |  155|  7.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|  5.96k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.96k, False: 1.13k]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.09k|	return _ret; \
  |  |  |  |  163|  7.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|  7.09k|}
sc_pkcs15_free_auth_info:
  735|  7.63k|{
  736|  7.63k|	free(auth_info);
  737|  7.63k|}
sc_pkcs15_pincache_add:
  743|  1.00k|{
  744|  1.00k|	struct sc_context *ctx = p15card->card->ctx;
  745|  1.00k|	struct sc_pkcs15_auth_info *auth_info = (struct sc_pkcs15_auth_info *)pin_obj->data;
  746|  1.00k|	struct sc_pkcs15_object *obj = NULL;
  747|  1.00k|	int r;
  748|       |
  749|  1.00k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.00k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.00k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  750|       |
  751|  1.00k|	if (!pin || !pinlen)   {
  ------------------
  |  Branch (751:6): [True: 0, False: 1.00k]
  |  Branch (751:14): [True: 0, False: 1.00k]
  ------------------
  752|      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__
  |  |  ------------------
  ------------------
  753|      0|		return;
  754|      0|	}
  755|  1.00k|	else if (!p15card->opts.use_pin_cache)   {
  ------------------
  |  Branch (755:11): [True: 6, False: 995]
  ------------------
  756|      6|		sc_log(ctx, "PIN caching not enabled");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  757|      6|		return;
  758|      6|	}
  759|    995|	else if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)   {
  ------------------
  |  |   94|    995|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (759:11): [True: 0, False: 995]
  ------------------
  760|      0|		sc_log(ctx, "only 'PIN' auth. object can be cached");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  761|      0|		return;
  762|      0|	}
  763|       |
  764|       |	/* If the PIN protects an object with user consent, don't cache it */
  765|       |
  766|    995|	obj = p15card->obj_list;
  767|  6.94k|	while (obj != NULL) {
  ------------------
  |  Branch (767:9): [True: 5.96k, False: 985]
  ------------------
  768|       |		/* Compare 'sc_pkcs15_object.auth_id' with 'sc_pkcs15_pin_info.auth_id'.
  769|       |		 * In accordance with PKCS#15 "6.1.8 CommonObjectAttributes" and
  770|       |		 * "6.1.16 CommonAuthenticationObjectAttributes" with the exception that
  771|       |		 * "CommonObjectAttributes.accessControlRules" are not taken into account. */
  772|       |
  773|  5.96k|		if (sc_pkcs15_compare_id(&obj->auth_id, &auth_info->auth_id)) {
  ------------------
  |  Branch (773:7): [True: 1.39k, False: 4.56k]
  ------------------
  774|       |			/* Caching is refused, if the protected object requires user consent */
  775|  1.39k|			if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (775:8): [True: 1.39k, False: 0]
  ------------------
  776|  1.39k|				if (obj->user_consent > 0) {
  ------------------
  |  Branch (776:9): [True: 10, False: 1.38k]
  ------------------
  777|     10|					sc_log(ctx, "caching refused (user consent)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  778|     10|					return;
  779|     10|				}
  780|  1.39k|			}
  781|  1.39k|		}
  782|       |
  783|  5.95k|		obj = obj->next;
  784|  5.95k|	}
  785|       |
  786|    985|	r = sc_pkcs15_allocate_object_content(ctx, pin_obj, pin, pinlen);
  787|    985|	if (r != SC_SUCCESS)   {
  ------------------
  |  |   28|    985|#define SC_SUCCESS				0
  ------------------
  |  Branch (787:6): [True: 0, False: 985]
  ------------------
  788|      0|		sc_log(ctx, "Failed to allocate object content");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  789|      0|		return;
  790|      0|	}
  791|       |
  792|    985|	pin_obj->usage_counter = 0;
  793|    985|	sc_log(ctx, "PIN(%s) cached", pin_obj->label);
  ------------------
  |  |   71|    985|#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|    985|}
sc_pkcs15_pincache_revalidate:
  799|    483|{
  800|    483|	struct sc_context *ctx = p15card->card->ctx;
  801|    483|	sc_pkcs15_object_t *pin_obj;
  802|    483|	int r;
  803|       |
  804|    483|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    483|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    483|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    483|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    483|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 483]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  805|    483|	if (!p15card->opts.use_pin_cache)
  ------------------
  |  Branch (805:6): [True: 14, False: 469]
  ------------------
  806|     14|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     14|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  807|       |
  808|       |	/*  Apps that do not support CK_ALWAYS_AUTHENTICATE
  809|       |	 *  may need pin_cache_ignore_user_consent = 1 */
  810|    469|	if (!p15card->opts.pin_cache_ignore_user_consent) {
  ------------------
  |  Branch (810:6): [True: 469, False: 0]
  ------------------
  811|    469|	    if (obj->user_consent)
  ------------------
  |  Branch (811:10): [True: 20, False: 449]
  ------------------
  812|     20|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     20|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  813|    469|	}
  814|       |
  815|    449|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|    898|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (815:7): [True: 0, False: 449]
  ------------------
  816|    449|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH))
  ------------------
  |  |  560|    449|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (816:8): [True: 0, False: 449]
  ------------------
  817|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  818|       |
  819|    449|	r = sc_pkcs15_find_pin_by_auth_id(p15card, &obj->auth_id, &pin_obj);
  820|    449|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    449|#define SC_SUCCESS				0
  ------------------
  |  Branch (820:6): [True: 42, False: 407]
  ------------------
  821|     42|		sc_log(ctx, "Could not find pin object for auth_id %s", sc_pkcs15_print_id(&obj->auth_id));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  822|     42|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     42|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  823|     42|	}
  824|       |
  825|    407|	if (pin_obj->usage_counter >= p15card->opts.pin_cache_counter) {
  ------------------
  |  Branch (825:6): [True: 0, False: 407]
  ------------------
  826|      0|		sc_pkcs15_free_object_content(pin_obj);
  827|      0|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|      0|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  828|      0|	}
  829|       |
  830|    407|	if (!pin_obj->content.value || !pin_obj->content.len)
  ------------------
  |  Branch (830:6): [True: 35, False: 372]
  |  Branch (830:33): [True: 0, False: 372]
  ------------------
  831|     35|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     35|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  832|       |
  833|    372|	pin_obj->usage_counter++;
  834|    372|	r = _sc_pkcs15_verify_pin(p15card, pin_obj, pin_obj->content.value, pin_obj->content.len);
  835|    372|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    372|#define SC_SUCCESS				0
  ------------------
  |  Branch (835:6): [True: 27, False: 345]
  ------------------
  836|       |		/* Ensure that wrong PIN isn't used again */
  837|     27|		sc_pkcs15_free_object_content(pin_obj);
  838|       |
  839|     27|		sc_log(ctx, "Verify PIN error %i", r);
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  840|     27|		return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
  ------------------
  |  |   61|     27|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  841|     27|	}
  842|       |
  843|    345|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    345|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    345|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    345|	int _ret = r; \
  |  |  |  |  155|    345|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 345, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    345|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 345]
  |  |  |  |  ------------------
  |  |  |  |  157|    345|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    345|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    345|	return _ret; \
  |  |  |  |  163|    345|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  844|    345|}
pkcs15-pin.c:_validate_pin:
  260|  22.6k|{
  261|  22.6k|	size_t max_length;
  262|  22.6k|	if (p15card == NULL) {
  ------------------
  |  Branch (262:6): [True: 0, False: 22.6k]
  ------------------
  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|  22.6k|	if (auth_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
  ------------------
  |  |   94|  22.6k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  |  Branch (267:6): [True: 0, False: 22.6k]
  ------------------
  268|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  269|       |
  270|       |	/* prevent buffer overflow from hostile card */
  271|  22.6k|	if (auth_info->attrs.pin.stored_length > SC_MAX_PIN_SIZE)
  ------------------
  |  |   40|  22.6k|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (271:6): [True: 0, False: 22.6k]
  ------------------
  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|  22.6k|	if ((p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD
  ------------------
  |  |  376|  45.2k|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (275:7): [True: 0, False: 22.6k]
  ------------------
  276|  22.6k|				|| p15card->card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  560|  22.6k|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (276:8): [True: 0, False: 22.6k]
  ------------------
  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|  22.6k|	max_length = auth_info->attrs.pin.max_length != 0 ? auth_info->attrs.pin.max_length : SC_MAX_PIN_SIZE;
  ------------------
  |  |   40|  23.1k|#define SC_MAX_PIN_SIZE			256 /* OpenPGP card has 254 max */
  ------------------
  |  Branch (281:15): [True: 22.1k, False: 493]
  ------------------
  282|  22.6k|	if (pinlen > max_length || pinlen < auth_info->attrs.pin.min_length)
  ------------------
  |  Branch (282:6): [True: 1.78k, False: 20.8k]
  |  Branch (282:29): [True: 17.8k, False: 2.99k]
  ------------------
  283|  19.6k|		return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|  19.6k|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
  284|       |
  285|  2.99k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.99k|#define SC_SUCCESS				0
  ------------------
  286|  22.6k|}

sc_pkcs15emu_piv_init_ex:
 1419|  12.2k|{
 1420|  12.2k|	sc_card_t   *card = p15card->card;
 1421|  12.2k|	sc_context_t    *ctx = card->ctx;
 1422|       |
 1423|  12.2k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1424|       |
 1425|  12.2k|	if (piv_detect_card(p15card))
  ------------------
  |  Branch (1425:6): [True: 11.1k, False: 1.11k]
  ------------------
 1426|  11.1k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.1k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1427|  1.11k|	return sc_pkcs15emu_piv_init(p15card);
 1428|  12.2k|}
pkcs15-piv.c:piv_detect_card:
  237|  12.2k|{
  238|  12.2k|	sc_card_t *card = p15card->card;
  239|       |
  240|  12.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  241|  12.2k|	if (card->type < SC_CARD_TYPE_PIV_II_BASE
  ------------------
  |  Branch (241:6): [True: 4.65k, False: 7.61k]
  ------------------
  242|  7.61k|		|| card->type >= SC_CARD_TYPE_PIV_II_BASE + 1000)
  ------------------
  |  Branch (242:6): [True: 6.50k, False: 1.11k]
  ------------------
  243|  11.1k|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  11.1k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  244|  1.11k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.11k|#define SC_SUCCESS				0
  ------------------
  245|  12.2k|}
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.07k, False: 34]
  ------------------
  703|  1.07k|		sc_log(card->ctx, "sc_card_ctl rc=%d",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__
  |  |  ------------------
  ------------------
  704|  1.07k|		set_string(&p15card->tokeninfo->serial_number, "00000000");
  705|  1.07k|	} else {
  706|     34|		sc_bin_to_hex(serial.value, serial.len, buf, sizeof(buf), 0);
  707|     34|		set_string(&p15card->tokeninfo->serial_number, buf);
  708|     34|	}
  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: 32, False: 1.07k]
  |  Branch (710:28): [True: 8, False: 24]
  |  Branch (710:55): [True: 6, False: 2]
  |  Branch (710:82): [True: 3, False: 3]
  |  Branch (710:109): [True: 1, False: 2]
  ------------------
  711|     31|	    follows_nist_fascn = 1;
  712|     31|	}
  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.2k|	for (i = 0; objects[i].label; i++) {
  ------------------
  |  Branch (717:14): [True: 41.1k, False: 1.11k]
  ------------------
  718|  41.1k|		struct sc_pkcs15_data_info obj_info;
  719|  41.1k|		struct sc_pkcs15_object    obj_obj;
  720|       |
  721|  41.1k|		memset(&obj_info, 0, sizeof(obj_info));
  722|  41.1k|		memset(&obj_obj, 0, sizeof(obj_obj));
  723|  41.1k|		sc_pkcs15_format_id(objects[i].id, &obj_info.id);
  724|  41.1k|		sc_format_path(objects[i].path, &obj_info.path);
  725|       |
  726|       |		/* See if the object can not be present on the card */
  727|  41.1k|		r = sc_card_ctl(card, SC_CARDCTL_PIV_OBJECT_PRESENT, &obj_info.path);
  728|  41.1k|		if (r == 1)
  ------------------
  |  Branch (728:7): [True: 19.9k, False: 21.1k]
  ------------------
  729|  19.9k|			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.33k, False: 17.7k]
  ------------------
  738|  3.33k|			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|  28.8k|	for (i = 0; i < PIV_NUM_CERTS; i++) {
  ------------------
  |  |  370|  28.8k|#define PIV_NUM_CERTS 25
  ------------------
  |  Branch (762:14): [True: 27.7k, False: 1.11k]
  ------------------
  763|  27.7k|		struct sc_pkcs15_cert_info cert_info;
  764|  27.7k|		struct sc_pkcs15_object    cert_obj;
  765|  27.7k|		sc_pkcs15_der_t   cert_der;
  766|  27.7k|		sc_pkcs15_cert_t *cert_out = NULL;
  767|  27.7k|		int private_obj;
  768|       |
  769|  27.7k|		ckis[i].cert_found = 0;
  770|  27.7k|		ckis[i].key_alg = -1;
  771|  27.7k|		ckis[i].pubkey_found = 0;
  772|  27.7k|		ckis[i].pubkey_from_file = 0;
  773|  27.7k|		ckis[i].pubkey_len = 0;
  774|  27.7k|		ckis[i].pubkey_from_cert = NULL;
  775|  27.7k|		ckis[i].cert_keyUsage = 0;
  776|  27.7k|		ckis[i].cert_keyUsage_present = 0;
  777|  27.7k|		ckis[i].pub_usage = 0;
  778|  27.7k|		ckis[i].priv_usage = 0;
  779|       |
  780|  27.7k|		memset(&cert_info, 0, sizeof(cert_info));
  781|  27.7k|		memset(&cert_obj,  0, sizeof(cert_obj));
  782|       |
  783|  27.7k|		sc_pkcs15_format_id(certs[i].id, &cert_info.id);
  784|  27.7k|		cert_info.authority = certs[i].authority;
  785|  27.7k|		sc_format_path(certs[i].path, &cert_info.path);
  786|       |
  787|  27.7k|		strncpy(cert_obj.label, certs[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  27.7k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  788|  27.7k|		cert_obj.flags = certs[i].obj_flags;
  789|       |
  790|       |		/* See if the cert might be present or not. */
  791|  27.7k|		r = sc_card_ctl(card, SC_CARDCTL_PIV_OBJECT_PRESENT, &cert_info.path);
  792|  27.7k|		if (r == 1) {
  ------------------
  |  Branch (792:7): [True: 18.4k, False: 9.34k]
  ------------------
  793|  18.4k|			sc_log(card->ctx,  "Cert can not be present,i=%d", i);
  ------------------
  |  |   71|  18.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__
  |  |  ------------------
  ------------------
  794|  18.4k|			continue;
  795|  18.4k|		}
  796|       |
  797|  9.34k|		private_obj = cert_obj.flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|  9.34k|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  798|  9.34k|		r = sc_pkcs15_read_file(p15card, &cert_info.path, &cert_der.value, &cert_der.len, private_obj);
  799|       |
  800|  9.34k|		if (r) {
  ------------------
  |  Branch (800:7): [True: 6.89k, False: 2.44k]
  ------------------
  801|  6.89k|			sc_log(card->ctx,  "No cert found,i=%d", i);
  ------------------
  |  |   71|  6.89k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  802|  6.89k|			continue;
  803|  6.89k|		}
  804|       |
  805|  2.44k|		ckis[i].cert_found = 1;
  806|       |		/* cache it using the PKCS15 emulation objects */
  807|       |		/* as it does not change */
  808|  2.44k|		if (cert_der.value) {
  ------------------
  |  Branch (808:7): [True: 2.44k, False: 0]
  ------------------
  809|  2.44k|			cert_info.value.value = cert_der.value;
  810|  2.44k|			cert_info.value.len = cert_der.len;
  811|  2.44k|			if (!p15card->opts.use_file_cache
  ------------------
  |  Branch (811:8): [True: 2.44k, False: 0]
  ------------------
  812|  2.44k|			    || (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.44k|				cert_info.path.len = 0; /* use in mem cert from now on */
  814|  2.44k|			}
  815|  2.44k|		}
  816|       |		/* following will find the cached cert in cert_info */
  817|  2.44k|		r =  sc_pkcs15_read_certificate(p15card, &cert_info, private_obj, &cert_out);
  818|  2.44k|		if (r < 0 || cert_out == NULL || cert_out->key == NULL) {
  ------------------
  |  Branch (818:7): [True: 716, False: 1.73k]
  |  Branch (818:16): [True: 0, False: 1.73k]
  |  Branch (818:36): [True: 0, False: 1.73k]
  ------------------
  819|    716|			sc_log(card->ctx,  "Failed to read/parse the certificate r=%d",r);
  ------------------
  |  |   71|    716|#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|    716|			if (cert_out != NULL)
  ------------------
  |  Branch (820:8): [True: 0, False: 716]
  ------------------
  821|      0|				sc_pkcs15_free_certificate(cert_out);
  822|    716|			free(cert_der.value);
  823|    716|			continue;
  824|    716|		}
  825|       |
  826|       |		/* set the token name to the name of the CN of the first certificate */
  827|  1.73k|		if (!token_name) {
  ------------------
  |  Branch (827:7): [True: 1.71k, False: 18]
  ------------------
  828|  1.71k|			u8 * cn_name = NULL;
  829|  1.71k|			size_t cn_len = 0;
  830|  1.71k|			static const struct sc_object_id cn_oid = {{ 2, 5, 4, 3, -1 }};
  831|  1.71k|			r = sc_pkcs15_get_name_from_dn(card->ctx, cert_out->subject,
  832|  1.71k|				cert_out->subject_len, &cn_oid, &cn_name, &cn_len);
  833|  1.71k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.71k|#define SC_SUCCESS				0
  ------------------
  |  Branch (833:8): [True: 7, False: 1.70k]
  ------------------
  834|      7|				token_name = realloc(cn_name, cn_len + 1);
  835|      7|				if (!token_name) {
  ------------------
  |  Branch (835:9): [True: 0, False: 7]
  ------------------
  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|      7|				token_name[cn_len] = '\0';
  844|      7|				free(p15card->tokeninfo->label);
  845|      7|				p15card->tokeninfo->label = token_name;
  846|      7|			}
  847|  1.71k|		}
  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.73k|		if (follows_nist_fascn == 0) {
  ------------------
  |  Branch (855:7): [True: 1.69k, False: 38]
  ------------------
  856|  1.69k|			struct sc_object_id keyUsage_oid={{2,5,29,15,-1}};
  857|  1.69k|			int r = 0;
  858|       |
  859|  1.69k|			r = sc_pkcs15_get_bitstring_extension(card->ctx, cert_out,
  860|  1.69k|				&keyUsage_oid,
  861|  1.69k|				&ckis[i].cert_keyUsage, NULL);
  862|  1.69k|			if ( r >= 0)
  ------------------
  |  Branch (862:9): [True: 0, False: 1.69k]
  ------------------
  863|      0|				ckis[i].cert_keyUsage_present = 1;
  864|       |				/* TODO if no key usage, we could set all uses */
  865|  1.69k|		}
  866|       |
  867|       |
  868|  1.73k|		ckis[i].key_alg = cert_out->key->algorithm;
  869|  1.73k|		switch (cert_out->key->algorithm) {
  870|    690|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    690|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (870:4): [True: 690, False: 1.04k]
  ------------------
  871|       |				/* save pubkey_len for pub and priv */
  872|    690|				ckis[i].pubkey_len = cert_out->key->u.rsa.modulus.len * 8;
  873|       |				/* See RFC 5280 and PKCS#11 V2.40 */
  874|    690|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (874:9): [True: 0, False: 690]
  ------------------
  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_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
  ------------------
  877|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|      0|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  878|      0|					}
  879|      0|					if (ckis[i].cert_keyUsage & SC_X509_NON_REPUDIATION) {
  ------------------
  |  |  615|      0|#define SC_X509_NON_REPUDIATION       0x0002UL
  ------------------
  |  Branch (879:10): [True: 0, False: 0]
  ------------------
  880|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
              						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | 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_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_VERIFY | SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER;
  ------------------
  |  |  312|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFYRECOVER	0x80
  ------------------
  881|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
              						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION | SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_SIGNRECOVER;
  ------------------
  |  |  308|      0|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  882|      0|					}
  883|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_ENCIPHERMENT) {
  ------------------
  |  |  616|      0|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  ------------------
  |  Branch (883:10): [True: 0, False: 0]
  ------------------
  884|      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
  ------------------
  885|      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
  ------------------
  886|      0|					}
  887|      0|					if (ckis[i].cert_keyUsage & SC_X509_DATA_ENCIPHERMENT) {
  ------------------
  |  |  617|      0|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  ------------------
  |  Branch (887:10): [True: 0, False: 0]
  ------------------
  888|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|      0|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  889|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  890|      0|					}
  891|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_AGREEMENT) {
  ------------------
  |  |  618|      0|#define SC_X509_KEY_AGREEMENT         0x0010UL
  ------------------
  |  Branch (891:10): [True: 0, False: 0]
  ------------------
  892|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  893|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  894|      0|					}
  895|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_CERT_SIGN) {
  ------------------
  |  |  619|      0|#define SC_X509_KEY_CERT_SIGN         0x0020UL
  ------------------
  |  Branch (895:10): [True: 0, False: 0]
  ------------------
  896|      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
  ------------------
  897|      0|						ckis[i].priv_usage |=  SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  898|      0|					}
  899|      0|					if (ckis[i].cert_keyUsage & SC_X509_CRL_SIGN) {
  ------------------
  |  |  620|      0|#define SC_X509_CRL_SIGN              0x0040UL
  ------------------
  |  Branch (899:10): [True: 0, False: 0]
  ------------------
  900|      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
  ------------------
  901|      0|						ckis[i].priv_usage |=  SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  902|      0|					}
  903|      0|					if (ckis[i].cert_keyUsage & SC_X509_ENCIPHER_ONLY) {
  ------------------
  |  |  621|      0|#define SC_X509_ENCIPHER_ONLY         0x0080UL
  ------------------
  |  Branch (903:10): [True: 0, False: 0]
  ------------------
  904|      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
  ------------------
  905|      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
  ------------------
  906|      0|					}
  907|      0|					if (ckis[i].cert_keyUsage & SC_X509_DECIPHER_ONLY) { /* TODO is this correct */
  ------------------
  |  |  622|      0|#define SC_X509_DECIPHER_ONLY         0x0100UL
  ------------------
  |  Branch (907:10): [True: 0, False: 0]
  ------------------
  908|      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
  ------------------
  909|      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
  ------------------
  910|      0|					}
  911|      0|				}
  912|    690|				break;
  913|       |
  914|  1.04k|			case SC_ALGORITHM_EC:
  ------------------
  |  |   70|  1.04k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (914:4): [True: 1.04k, False: 690]
  ------------------
  915|  1.04k|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|  1.04k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (915:4): [True: 0, False: 1.73k]
  ------------------
  916|  1.04k|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|  1.04k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (916:4): [True: 0, False: 1.73k]
  ------------------
  917|  1.04k|				ckis[i].pubkey_len = cert_out->key->u.ec.params.field_length;
  918|  1.04k|				if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (918:9): [True: 0, False: 1.04k]
  ------------------
  919|      0|					if (ckis[i].cert_keyUsage & SC_X509_DIGITAL_SIGNATURE) {
  ------------------
  |  |  614|      0|#define SC_X509_DIGITAL_SIGNATURE     0x0001UL
  ------------------
  |  Branch (919:10): [True: 0, False: 0]
  ------------------
  920|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  921|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  922|      0|					}
  923|      0|					if (ckis[i].cert_keyUsage & SC_X509_NON_REPUDIATION) {
  ------------------
  |  |  615|      0|#define SC_X509_NON_REPUDIATION       0x0002UL
  ------------------
  |  Branch (923:10): [True: 0, False: 0]
  ------------------
  924|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  925|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  926|      0|					}
  927|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_ENCIPHERMENT) {
  ------------------
  |  |  616|      0|#define SC_X509_KEY_ENCIPHERMENT      0x0004UL
  ------------------
  |  Branch (927:10): [True: 0, False: 0]
  ------------------
  928|      0|						ckis[i].pub_usage |= 0;
  929|      0|						ckis[i].priv_usage |= 0;
  930|      0|					}
  931|      0|					if (ckis[i].cert_keyUsage & SC_X509_DATA_ENCIPHERMENT) {
  ------------------
  |  |  617|      0|#define SC_X509_DATA_ENCIPHERMENT     0x0008UL
  ------------------
  |  Branch (931:10): [True: 0, False: 0]
  ------------------
  932|      0|						ckis[i].pub_usage |= 0;
  933|      0|						ckis[i].priv_usage |= 0;
  934|      0|					}
  935|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_AGREEMENT) {
  ------------------
  |  |  618|      0|#define SC_X509_KEY_AGREEMENT         0x0010UL
  ------------------
  |  Branch (935:10): [True: 0, False: 0]
  ------------------
  936|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  937|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_DERIVE;
  ------------------
  |  |  313|      0|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  938|      0|					}
  939|      0|					if (ckis[i].cert_keyUsage & SC_X509_KEY_CERT_SIGN) {
  ------------------
  |  |  619|      0|#define SC_X509_KEY_CERT_SIGN         0x0020UL
  ------------------
  |  Branch (939:10): [True: 0, False: 0]
  ------------------
  940|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  941|      0|						ckis[i].priv_usage |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  942|      0|					}
  943|      0|					if (ckis[i].cert_keyUsage & SC_X509_CRL_SIGN) {
  ------------------
  |  |  620|      0|#define SC_X509_CRL_SIGN              0x0040UL
  ------------------
  |  Branch (943:10): [True: 0, False: 0]
  ------------------
  944|      0|						ckis[i].pub_usage |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  945|      0|						ckis[i].priv_usage |=  SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  946|      0|					}
  947|      0|					if (ckis[i].cert_keyUsage & SC_X509_ENCIPHER_ONLY) {
  ------------------
  |  |  621|      0|#define SC_X509_ENCIPHER_ONLY         0x0080UL
  ------------------
  |  Branch (947:10): [True: 0, False: 0]
  ------------------
  948|      0|						ckis[i].pub_usage |= 0;
  949|      0|						ckis[i].priv_usage |= 0;
  950|      0|					}
  951|      0|					if (ckis[i].cert_keyUsage & SC_X509_DECIPHER_ONLY) {
  ------------------
  |  |  622|      0|#define SC_X509_DECIPHER_ONLY         0x0100UL
  ------------------
  |  Branch (951:10): [True: 0, False: 0]
  ------------------
  952|      0|						ckis[i].pub_usage |= 0;
  953|      0|						ckis[i].priv_usage |= 0;
  954|      0|					}
  955|      0|				}
  956|  1.04k|				break;
  957|       |
  958|      0|			default:
  ------------------
  |  Branch (958:4): [True: 0, False: 1.73k]
  ------------------
  959|      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__
  |  |  ------------------
  ------------------
  960|      0|				ckis[i].pubkey_len = 0; /* set some value for now */
  961|  1.73k|		}
  962|  1.73k|		if (i < PIV_NUM_KEYS) { /* Only save pub key if card can have private key */
  ------------------
  |  |  371|  1.73k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (962:7): [True: 1.71k, False: 15]
  ------------------
  963|  1.71k|			ckis[i].pubkey_from_cert = cert_out->key;
  964|  1.71k|			cert_out->key = NULL;
  965|  1.71k|		}
  966|  1.73k|		sc_pkcs15_free_certificate(cert_out);
  967|       |
  968|  1.73k|		r = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
  969|  1.73k|		if (r < 0) {
  ------------------
  |  Branch (969:7): [True: 0, False: 1.73k]
  ------------------
  970|      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__
  |  |  ------------------
  ------------------
  971|      0|			continue;
  972|      0|		}
  973|  1.73k|	}
  974|       |
  975|       |	/* set pins */
  976|  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__
  |  |  ------------------
  ------------------
  977|  4.44k|	for (i = 0; pins[i].label; i++) {
  ------------------
  |  Branch (977:14): [True: 3.33k, False: 1.11k]
  ------------------
  978|  3.33k|		struct sc_pkcs15_auth_info pin_info;
  979|  3.33k|		struct sc_pkcs15_object   pin_obj;
  980|  3.33k|		const char * label;
  981|  3.33k|		int pin_ref;
  982|       |
  983|       |		/* the SignPIN is only used with minidriver */
  984|  3.33k|		if (pins[i].cardmod && (strcmp(card->ctx->app_name, "cardmod") != 0))
  ------------------
  |  Branch (984:7): [True: 1.11k, False: 2.22k]
  |  Branch (984:26): [True: 1.11k, False: 0]
  ------------------
  985|  1.11k|			continue;
  986|       |
  987|  2.22k|		memset(&pin_info, 0, sizeof(pin_info));
  988|  2.22k|		memset(&pin_obj,  0, sizeof(pin_obj));
  989|       |
  990|  2.22k|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  2.22k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  991|  2.22k|		sc_pkcs15_format_id(pins[i].id, &pin_info.auth_id);
  992|  2.22k|		pin_info.attrs.pin.reference     = pins[i].ref;
  993|  2.22k|		pin_info.attrs.pin.flags         = pins[i].flags;
  994|  2.22k|		pin_info.attrs.pin.type          = pins[i].type;
  995|  2.22k|		pin_info.attrs.pin.min_length    = pins[i].minlen;
  996|  2.22k|		pin_info.attrs.pin.stored_length = pins[i].storedlen;
  997|  2.22k|		pin_info.attrs.pin.max_length    = pins[i].maxlen;
  998|  2.22k|		pin_info.attrs.pin.pad_char      = pins[i].pad_char;
  999|  2.22k|		pin_info.tries_left              = pins[i].tries_left;
 1000|  2.22k|		sc_format_path(pins[i].path, &pin_info.path);
 1001|       |
 1002|  2.22k|		label = pins[i].label;
 1003|  2.22k|		if ((i == 0 || pins[i].cardmod) &&
  ------------------
  |  Branch (1003:8): [True: 1.11k, False: 1.11k]
  |  Branch (1003:18): [True: 0, False: 1.11k]
  ------------------
 1004|  1.11k|			sc_card_ctl(card, SC_CARDCTL_PIV_PIN_PREFERENCE,
  ------------------
  |  Branch (1004:4): [True: 1.11k, False: 0]
  ------------------
 1005|  1.11k|					&pin_ref) == 0 &&
 1006|  1.11k|				pin_ref == 0x00) { /* must be 80 for PIV pin, or 00 for Global PIN */
  ------------------
  |  Branch (1006:5): [True: 5, False: 1.10k]
  ------------------
 1007|      5|			pin_info.attrs.pin.reference = pin_ref;
 1008|      5|			label = "Global PIN";
 1009|      5|		}
 1010|       |
 1011|  2.22k|		strncpy(pin_obj.label, label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  2.22k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1012|  2.22k|		pin_obj.flags = pins[i].obj_flags;
 1013|  2.22k|		if ((i == 0 || pins[i].cardmod)) {
  ------------------
  |  Branch (1013:8): [True: 1.11k, False: 1.11k]
  |  Branch (1013:18): [True: 0, False: 1.11k]
  ------------------
 1014|       |			/*
 1015|       |			 * according to description of "RESET RETRY COUNTER"
 1016|       |			 * command in specs PUK can only unblock PIV PIN
 1017|       |			 */
 1018|  1.11k|			pin_obj.auth_id.len = 1;
 1019|  1.11k|			pin_obj.auth_id.value[0] = 2;
 1020|  1.11k|		}
 1021|       |
 1022|  2.22k|		r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
 1023|  2.22k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add PIN");
  ------------------
  |  |  184|  2.22k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.22k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.22k|	int _ret = (r); \
  |  |  |  |  178|  2.22k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.22k]
  |  |  |  |  ------------------
  |  |  |  |  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.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.22k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1024|  2.22k|	}
 1025|       |
 1026|       |	/* set public keys */
 1027|       |	/* We may only need this during initialization when genkey
 1028|       |	 * gets the pubkey, but it can not be read from the card
 1029|       |	 * at a later time. The piv-tool can stash  pubkey in file
 1030|       |	 */
 1031|  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__
  |  |  ------------------
  ------------------
 1032|  27.3k|	for (i = 0; i < PIV_NUM_KEYS; i++) {
  ------------------
  |  |  371|  27.3k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (1032:14): [True: 26.2k, False: 1.09k]
  ------------------
 1033|  26.2k|		struct sc_pkcs15_pubkey_info pubkey_info;
 1034|  26.2k|		struct sc_pkcs15_object     pubkey_obj;
 1035|  26.2k|		struct sc_pkcs15_pubkey *p15_key = NULL;
 1036|       |
 1037|  26.2k|		memset(&pubkey_info, 0, sizeof(pubkey_info));
 1038|  26.2k|		memset(&pubkey_obj,  0, sizeof(pubkey_obj));
 1039|       |
 1040|       |
 1041|  26.2k|		sc_pkcs15_format_id(pubkeys[i].id, &pubkey_info.id);
 1042|  26.2k|		pubkey_info.native        = 1;
 1043|  26.2k|		pubkey_info.key_reference = pubkeys[i].ref;
 1044|       |
 1045|       |//		sc_format_path(pubkeys[i].path, &pubkey_info.path);
 1046|       |
 1047|  26.2k|		strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  26.2k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1048|       |
 1049|  26.2k|		pubkey_obj.flags = pubkeys[i].obj_flags;
 1050|       |
 1051|  26.2k|		if (pubkeys[i].auth_id)
  ------------------
  |  Branch (1051:7): [True: 0, False: 26.2k]
  ------------------
 1052|      0|			sc_pkcs15_format_id(pubkeys[i].auth_id, &pubkey_obj.auth_id);
 1053|       |
 1054|       |		/* If no cert found, piv-tool may have stashed the pubkey
 1055|       |		 * so we can use it when generating a certificate request
 1056|       |		 * The file is a OpenSSL DER EVP_KEY, which looks like
 1057|       |		 * a certificate subjectPublicKeyInfo.
 1058|       |		 *
 1059|       |		 */
 1060|  26.2k|		if (ckis[i].cert_found == 0 ) { /*  no cert found */
  ------------------
  |  Branch (1060:7): [True: 23.8k, False: 2.41k]
  ------------------
 1061|  23.8k|			sc_cardctl_piv_pubkey_info_t info = {0};
 1062|       |
 1063|  23.8k|			sc_log(card->ctx, "No cert for this pub key i=%d",i);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1064|       |
 1065|       |			/* First try to use yubikey extension to pull missing public key from metadata */
 1066|  23.8k|			info.slot = pubkeys[i].ref;
 1067|  23.8k|			r = sc_card_ctl(card, SC_CARDCTL_PIV_YK_GET_PUBKEY_INFO, &info);
 1068|  23.8k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  23.8k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1068:8): [True: 17, False: 23.8k]
  ------------------
 1069|     17|				struct sc_pkcs15_pubkey pubkey = {0};
 1070|     17|				const unsigned char *p;
 1071|     17|				unsigned int cla, tag;
 1072|     17|				size_t tag_len;
 1073|     17|				int r;
 1074|       |
 1075|     17|				switch (info.algorithm) {
 1076|      1|				case 0x06: // RSA
  ------------------
  |  Branch (1076:5): [True: 1, False: 16]
  ------------------
 1077|      2|				case 0x07:
  ------------------
  |  Branch (1077:5): [True: 1, False: 16]
  ------------------
 1078|      3|				case 0x08:
  ------------------
  |  Branch (1078:5): [True: 1, False: 16]
  ------------------
 1079|      3|					p = info.pubkey.value;
 1080|      3|					r = sc_asn1_read_tag(&p, info.pubkey.len, &cla, &tag, &tag_len);
 1081|      3|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  |  Branch (1081:10): [True: 2, False: 1]
  ------------------
 1082|      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__
  |  |  ------------------
  ------------------
 1083|      2|						goto next_pubkey;
 1084|      2|					}
 1085|      1|					if ((tag | cla) != 0x81) {
  ------------------
  |  Branch (1085:10): [True: 1, False: 0]
  ------------------
 1086|      1|						sc_log(card->ctx, "Unexpected tag %u received, expected 0x81", (tag | cla));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1087|      1|						goto next_pubkey;
 1088|      1|					}
 1089|      0|					pubkey.u.rsa.modulus.data = malloc(tag_len);
 1090|      0|					if (pubkey.u.rsa.modulus.data == NULL) {
  ------------------
  |  Branch (1090:10): [True: 0, False: 0]
  ------------------
 1091|      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__
  |  |  ------------------
  ------------------
 1092|      0|						goto next_pubkey;
 1093|      0|					}
 1094|      0|					memcpy(pubkey.u.rsa.modulus.data, p, tag_len);
 1095|      0|					pubkey.u.rsa.modulus.len = tag_len;
 1096|       |
 1097|      0|					p += tag_len;
 1098|      0|					r = sc_asn1_read_tag(&p, info.pubkey.len - (p - info.pubkey.value), &cla, &tag, &tag_len);
 1099|      0|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1099:10): [True: 0, False: 0]
  ------------------
 1100|      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__
  |  |  ------------------
  ------------------
 1101|      0|						goto next_pubkey;
 1102|      0|					}
 1103|      0|					if ((tag | cla) != 0x82) {
  ------------------
  |  Branch (1103:10): [True: 0, False: 0]
  ------------------
 1104|      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__
  |  |  ------------------
  ------------------
 1105|      0|						goto next_pubkey;
 1106|      0|					}
 1107|      0|					pubkey.u.rsa.exponent.data = malloc(tag_len);
 1108|      0|					if (pubkey.u.rsa.exponent.data == NULL) {
  ------------------
  |  Branch (1108:10): [True: 0, False: 0]
  ------------------
 1109|      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__
  |  |  ------------------
  ------------------
 1110|      0|						goto next_pubkey;
 1111|      0|					}
 1112|      0|					memcpy(pubkey.u.rsa.exponent.data, p, tag_len);
 1113|      0|					pubkey.u.rsa.exponent.len = tag_len;
 1114|       |
 1115|      0|					pubkey.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
 1116|      0|					break;
 1117|      1|				case 0x11: // ECDSA
  ------------------
  |  Branch (1117:5): [True: 1, False: 16]
  ------------------
 1118|      2|				case 0x14:
  ------------------
  |  Branch (1118:5): [True: 1, False: 16]
  ------------------
 1119|      2|					r = yk_copy_pubkey_from_tag(&info, &pubkey.u.ec.ecpointQ, 0x86);
 1120|      2|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      2|#define SC_SUCCESS				0
  ------------------
  |  Branch (1120:10): [True: 2, False: 0]
  ------------------
 1121|      2|						sc_log(card->ctx, "Failed to parse ECDSA public key. %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__
  |  |  ------------------
  ------------------
 1122|      2|						goto next_pubkey;
 1123|      2|					}
 1124|      0|					pubkey.algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
 1125|      0|					break;
 1126|      1|				case 0xE0: // Yubico extension: EDDSA
  ------------------
  |  Branch (1126:5): [True: 1, False: 16]
  ------------------
 1127|      1|					r = yk_copy_pubkey_from_tag(&info, &pubkey.u.ec.ecpointQ, 0x86);
 1128|      1|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (1128:10): [True: 1, False: 0]
  ------------------
 1129|      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__
  |  |  ------------------
  ------------------
 1130|      1|						goto next_pubkey;
 1131|      1|					}
 1132|      0|					pubkey.algorithm = SC_ALGORITHM_EDDSA;
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1133|      0|					break;
 1134|      1|				case 0xE1: // Yubico extension: XEDDSA
  ------------------
  |  Branch (1134:5): [True: 1, False: 16]
  ------------------
 1135|      1|					r = yk_copy_pubkey_from_tag(&info, &pubkey.u.ec.ecpointQ, 0x86);
 1136|      1|					if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (1136:10): [True: 1, False: 0]
  ------------------
 1137|      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__
  |  |  ------------------
  ------------------
 1138|      1|						goto next_pubkey;
 1139|      1|					}
 1140|      0|					pubkey.algorithm = SC_ALGORITHM_XEDDSA;
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1141|      0|					break;
 1142|     10|				default:
  ------------------
  |  Branch (1142:5): [True: 10, False: 7]
  ------------------
 1143|     10|					sc_log(card->ctx, "Got unknown algorithm ID %d", info.algorithm);
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1144|     10|					goto next_pubkey;
 1145|     17|				}
 1146|       |
 1147|      0|				r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, &pubkey,
 1148|      0|						&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1149|      0|				if (r < 0) {
  ------------------
  |  Branch (1149:9): [True: 0, False: 0]
  ------------------
 1150|      0|					goto next_pubkey;
 1151|      0|				}
 1152|      0|				r = sc_pkcs15_pubkey_from_spki_sequence(card->ctx,
 1153|      0|						pubkey_info.direct.spki.value, pubkey_info.direct.spki.len,
 1154|      0|						&p15_key);
 1155|      0|				if (r < 0) {
  ------------------
  |  Branch (1155:9): [True: 0, False: 0]
  ------------------
 1156|      0|					free(p15_key);
 1157|      0|					p15_key = NULL;
 1158|      0|				}
 1159|     17|next_pubkey:
 1160|     17|				sc_pkcs15_erase_pubkey(&pubkey);
 1161|     17|				if (!p15_key)
  ------------------
  |  Branch (1161:9): [True: 17, False: 0]
  ------------------
 1162|     17|					continue;
 1163|  23.8k|			} else {
 1164|  23.8k|				char *filename = NULL;
 1165|       |
 1166|  23.8k|				sc_log(card->ctx, "Failed to get public key. Not a Yubikey? rc=%d", r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1167|       |				/*
 1168|       |				 * If we used the piv-tool or ykman to generate a key,
 1169|       |				 * we would have saved the public key as a file.
 1170|       |				 * This code is only used while signing a request
 1171|       |				 * After the certificate is loaded on the card,
 1172|       |				 * the public key is extracted from the certificate.
 1173|       |				 */
 1174|       |
 1175|  23.8k|				sc_log(card->ctx, "DEE look for env %s",
  ------------------
  |  |   71|  47.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: 23.8k, False: 0]
  |  |  ------------------
  ------------------
 1176|  23.8k|						pubkeys[i].getenvname ? pubkeys[i].getenvname : "NULL");
 1177|       |
 1178|  23.8k|				if (pubkeys[i].getenvname == NULL)
  ------------------
  |  Branch (1178:9): [True: 0, False: 23.8k]
  ------------------
 1179|      0|					continue;
 1180|       |
 1181|  23.8k|				filename = getenv(pubkeys[i].getenvname);
 1182|  23.8k|				sc_log(card->ctx, "DEE look for file %s", filename ? filename : "NULL");
  ------------------
  |  |   71|  47.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: 23.8k]
  |  |  ------------------
  ------------------
 1183|  23.8k|				if (filename == NULL)
  ------------------
  |  Branch (1183:9): [True: 23.8k, False: 0]
  ------------------
 1184|  23.8k|					continue;
 1185|       |
 1186|      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__
  |  |  ------------------
  ------------------
 1187|       |
 1188|      0|				r = sc_pkcs15_pubkey_from_spki_file(card->ctx, filename, &p15_key);
 1189|      0|				if (r < 0) {
  ------------------
  |  Branch (1189:9): [True: 0, False: 0]
  ------------------
 1190|      0|					free(p15_key);
 1191|      0|					continue;
 1192|      0|				}
 1193|       |
 1194|       |				/* Lets also try another method. */
 1195|      0|				r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, p15_key,
 1196|      0|						&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1197|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1198|      0|			}
 1199|       |
 1200|       |			/* Only get here if no cert, and the the above found the
 1201|       |			 * pub key file (actually the SPKI version). This only
 1202|       |			 * happens when trying initializing a card and have set
 1203|       |			 * env PIV_9A_KEY or 9C, 9D, 9E to point at the file.
 1204|       |			 * Or with Yubikey 5.3+ pulling this information from
 1205|       |			 * GET METADATA instruction.
 1206|       |			 *
 1207|       |			 * We will cache it using the PKCS15 emulation objects
 1208|       |			 */
 1209|       |
 1210|      0|			pubkey_info.path.len = 0;
 1211|       |
 1212|      0|			ckis[i].key_alg = p15_key->algorithm;
 1213|      0|			switch (p15_key->algorithm) {
 1214|      0|			case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1214:4): [True: 0, False: 0]
  ------------------
 1215|       |				/* save pubkey_len in pub and priv */
 1216|      0|				ckis[i].pubkey_len = p15_key->u.rsa.modulus.len * 8;
 1217|      0|				break;
 1218|      0|			case SC_ALGORITHM_EC:
  ------------------
  |  |   70|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1218:4): [True: 0, False: 0]
  ------------------
 1219|      0|			case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1219:4): [True: 0, False: 0]
  ------------------
 1220|      0|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1220:4): [True: 0, False: 0]
  ------------------
 1221|      0|				ckis[i].key_alg = p15_key->algorithm;
 1222|      0|				ckis[i].pubkey_len = p15_key->u.ec.params.field_length;
 1223|      0|				break;
 1224|      0|			default:
  ------------------
  |  Branch (1224:4): [True: 0, False: 0]
  ------------------
 1225|      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__
  |  |  ------------------
  ------------------
 1226|      0|				continue;
 1227|      0|			}
 1228|      0|			ckis[i].pubkey_found = 1;
 1229|      0|			ckis[i].pubkey_from_file = 1;
 1230|      0|			pubkey_obj.emulated = p15_key;
 1231|      0|			p15_key = NULL;
 1232|      0|		}
 1233|  2.41k|		else if (ckis[i].pubkey_from_cert)   {
  ------------------
  |  Branch (1233:12): [True: 1.70k, False: 707]
  ------------------
 1234|  1.70k|			r = sc_pkcs15_encode_pubkey_as_spki(card->ctx, ckis[i].pubkey_from_cert,
 1235|  1.70k|				&pubkey_info.direct.spki.value, &pubkey_info.direct.spki.len);
 1236|  1.70k|			LOG_TEST_GOTO_ERR(card->ctx, r, "SPKI encode public key error");
  ------------------
  |  |  184|  1.70k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.70k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.70k|	int _ret = (r); \
  |  |  |  |  178|  1.70k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 20, False: 1.68k]
  |  |  |  |  ------------------
  |  |  |  |  179|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     20|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     20|		goto err; \
  |  |  |  |  182|     20|	} \
  |  |  |  |  183|  1.70k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.68k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1237|       |
 1238|  1.68k|			pubkey_obj.emulated = ckis[i].pubkey_from_cert;
 1239|  1.68k|			ckis[i].pubkey_from_cert = NULL;
 1240|  1.68k|		}
 1241|       |
 1242|  2.39k|		sc_log(card->ctx, "adding pubkey for %d keyalg=%lu", i, ckis[i].key_alg);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
 1243|  2.39k|		switch (ckis[i].key_alg) {
 1244|    657|		case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    657|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1244:3): [True: 657, False: 1.73k]
  ------------------
 1245|    657|			if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1245:8): [True: 0, False: 657]
  ------------------
 1246|      0|				pubkey_info.usage = ckis[i].pub_usage;
 1247|    657|			} else {
 1248|    657|				pubkey_info.usage = pubkeys[i].usage_rsa;
 1249|    657|			}
 1250|    657|			pubkey_info.modulus_length = ckis[i].pubkey_len;
 1251|    657|			strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|    657|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1252|       |
 1253|       |			/* should not fail */
 1254|    657|			r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1255|    657|			LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add RSA pubkey");
  ------------------
  |  |  184|    657|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    657|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    657|	int _ret = (r); \
  |  |  |  |  178|    657|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 657]
  |  |  |  |  ------------------
  |  |  |  |  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|    657|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 657]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1256|       |
 1257|    657|			ckis[i].pubkey_found = 1;
 1258|    657|			break;
 1259|  1.03k|		case SC_ALGORITHM_EC:
  ------------------
  |  |   70|  1.03k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1259:3): [True: 1.03k, False: 1.36k]
  ------------------
 1260|  1.03k|		case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|  1.03k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1260:3): [True: 0, False: 2.39k]
  ------------------
 1261|  1.03k|		case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|  1.03k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1261:3): [True: 0, False: 2.39k]
  ------------------
 1262|  1.03k|			if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1262:8): [True: 0, False: 1.03k]
  ------------------
 1263|      0|				pubkey_info.usage = ckis[i].pub_usage;
 1264|  1.03k|			} else {
 1265|  1.03k|				pubkey_info.usage = pubkeys[i].usage_ec;
 1266|  1.03k|			}
 1267|       |
 1268|  1.03k|			pubkey_info.field_length = ckis[i].pubkey_len;
 1269|  1.03k|			strncpy(pubkey_obj.label, pubkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  1.03k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1270|       |
 1271|       |			/* should not fail */
 1272|       |
 1273|  1.03k|			if (ckis[i].key_alg == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|  1.03k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1273:8): [True: 0, False: 1.03k]
  ------------------
 1274|      0|				r = sc_pkcs15emu_add_eddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1275|  1.03k|			else if (ckis[i].key_alg == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|  1.03k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1275:13): [True: 0, False: 1.03k]
  ------------------
 1276|      0|				r = sc_pkcs15emu_add_xeddsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1277|  1.03k|			else
 1278|  1.03k|				r = sc_pkcs15emu_add_ec_pubkey(p15card, &pubkey_obj, &pubkey_info);
 1279|       |
 1280|  1.03k|			LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add EC pubkey");
  ------------------
  |  |  184|  1.03k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  1.03k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  1.03k|	int _ret = (r); \
  |  |  |  |  178|  1.03k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 1.03k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  1.03k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1281|       |
 1282|  1.03k|			ckis[i].pubkey_found = 1;
 1283|  1.03k|			break;
 1284|    707|		default:
  ------------------
  |  Branch (1284:3): [True: 707, False: 1.68k]
  ------------------
 1285|    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__
  |  |  ------------------
  ------------------
 1286|    707|			continue;
 1287|  2.39k|		}
 1288|  1.68k|		sc_log(card->ctx, "USAGE: cert_keyUsage_present:%d usage:0x%8.8x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1289|  1.68k|				ckis[i].cert_keyUsage_present, pubkey_info.usage);
 1290|  1.68k|	}
 1291|       |
 1292|       |
 1293|       |	/* set private keys */
 1294|  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__
  |  |  ------------------
  ------------------
 1295|  27.2k|	for (i = 0; i < PIV_NUM_KEYS; i++) {
  ------------------
  |  |  371|  27.2k|#define PIV_NUM_KEYS  24
  ------------------
  |  Branch (1295:14): [True: 26.1k, False: 1.09k]
  ------------------
 1296|  26.1k|		struct sc_pkcs15_prkey_info prkey_info;
 1297|  26.1k|		struct sc_pkcs15_object     prkey_obj;
 1298|  26.1k|		u8 pin_policy = prkeys[i].ref;
 1299|       |
 1300|  26.1k|		memset(&prkey_info, 0, sizeof(prkey_info));
 1301|  26.1k|		memset(&prkey_obj,  0, sizeof(prkey_obj));
 1302|       |
 1303|  26.1k|		if (ckis[i].cert_found == 0 && ckis[i].pubkey_found == 0)
  ------------------
  |  Branch (1303:7): [True: 23.7k, False: 2.39k]
  |  Branch (1303:34): [True: 23.7k, False: 0]
  ------------------
 1304|  23.7k|			continue; /* i.e. no cert or pubkey */
 1305|       |
 1306|  2.39k|		sc_pkcs15_format_id(prkeys[i].id, &prkey_info.id);
 1307|  2.39k|		prkey_info.native        = 1;
 1308|  2.39k|		prkey_info.key_reference = prkeys[i].ref;
 1309|  2.39k|		sc_format_path(prkeys[i].path, &prkey_info.path);
 1310|       |
 1311|  2.39k|		strncpy(prkey_obj.label, prkeys[i].label, SC_PKCS15_MAX_LABEL_SIZE - 1);
  ------------------
  |  |   35|  2.39k|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
 1312|  2.39k|		prkey_obj.flags = prkeys[i].obj_flags;
 1313|  2.39k|		prkey_obj.user_consent = prkeys[i].user_consent; /* only Sign key */
 1314|       |
 1315|  2.39k|		r = sc_card_ctl(p15card->card, SC_CARDCTL_PIV_YK_PIN_POLICY, &pin_policy);
 1316|  2.39k|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  2.39k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1316:7): [True: 158, False: 2.23k]
  ------------------
 1317|    158|			switch (pin_policy) {
 1318|     10|			case 0x01:
  ------------------
  |  Branch (1318:4): [True: 10, False: 148]
  ------------------
 1319|     10|				prkey_obj.flags &= ~SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     10|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
 1320|     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__
  |  |  ------------------
  ------------------
 1321|     10|				break;
 1322|      8|			case 0x02:
  ------------------
  |  Branch (1322:4): [True: 8, False: 150]
  ------------------
 1323|      8|				prkey_obj.user_consent = 0;
 1324|      8|				sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1325|      8|				sc_log(card->ctx, "PIN is checked once for the session");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1326|      8|				break;
 1327|      1|			case 0x03:
  ------------------
  |  Branch (1327:4): [True: 1, False: 157]
  ------------------
 1328|      1|				prkey_obj.user_consent = 1;
 1329|      1|				sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1330|      1|				sc_log(card->ctx, "PIN is verified just before operation");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1331|      1|				break;
 1332|    136|			case 0x00:
  ------------------
  |  Branch (1332:4): [True: 136, False: 22]
  ------------------
 1333|    139|			default:
  ------------------
  |  Branch (1333:4): [True: 3, False: 155]
  ------------------
 1334|    139|				sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1335|    139|				break;
 1336|    158|			}
 1337|    158|		} else
 1338|  2.23k|			sc_pkcs15_format_id(prkeys[i].auth_id, &prkey_obj.auth_id);
 1339|       |
 1340|       |		/* If using minidriver, use Sign PIN  for 9C key */
 1341|  2.39k|		if (prkey_obj.user_consent && (strcmp(card->ctx->app_name, "cardmod") == 0))
  ------------------
  |  Branch (1341:7): [True: 300, False: 2.09k]
  |  Branch (1341:33): [True: 0, False: 300]
  ------------------
 1342|      0|			sc_pkcs15_format_id("03", &prkey_obj.auth_id);
 1343|       |
 1344|       |		/*
 1345|       |		 * When no cert is present and a pubkey in a file was found,
 1346|       |		 * means the caller is initializing a card. A sign operation
 1347|       |		 * will be required to sign a certificate request even if
 1348|       |		 * normal usage would not allow it. Set SC_PKCS15_PRKEY_USAGE_SIGN
 1349|       |		 * TODO if code is added to allow key generation and request
 1350|       |		 * sign in the same session, similar code will be needed.
 1351|       |		 * Exclude XEDDSA keys as they are not signing capable
 1352|       |		 */
 1353|       |
 1354|  2.39k|		if (ckis[i].pubkey_from_file == 1) {
  ------------------
  |  Branch (1354:7): [True: 0, False: 2.39k]
  ------------------
 1355|      0|			switch (ckis[i].key_alg) {
 1356|      0|			case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1356:4): [True: 0, False: 0]
  ------------------
 1357|      0|				break;
 1358|      0|			default:
  ------------------
  |  Branch (1358:4): [True: 0, False: 0]
  ------------------
 1359|      0|				prkey_info.usage = SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
 1360|      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__
  |  |  ------------------
  ------------------
 1361|      0|				break;
 1362|      0|			}
 1363|      0|		}
 1364|       |
 1365|  2.39k|		if (ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1365:7): [True: 0, False: 2.39k]
  ------------------
 1366|      0|			prkey_info.usage |= ckis[i].priv_usage;
 1367|       |			/* If retired key and non gov cert has NONREPUDIATION, treat as user_consent */
 1368|      0|			if (i >= 4 && (ckis[i].priv_usage & SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)) {
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  |  Branch (1368:8): [True: 0, False: 0]
  |  Branch (1368:18): [True: 0, False: 0]
  ------------------
 1369|      0|				prkey_obj.user_consent = 1;
 1370|      0|			}
 1371|      0|		}
 1372|       |
 1373|  2.39k|		switch (ckis[i].key_alg) {
 1374|    653|		case SC_ALGORITHM_RSA:
  ------------------
  |  |   69|    653|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1374:3): [True: 653, False: 1.73k]
  ------------------
 1375|    653|			if (!ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1375:8): [True: 653, False: 0]
  ------------------
 1376|    653|				prkey_info.usage |= prkeys[i].usage_rsa;
 1377|    653|			}
 1378|    653|			prkey_info.modulus_length = ckis[i].pubkey_len;
 1379|    653|			r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
 1380|    653|			break;
 1381|  1.03k|		case SC_ALGORITHM_EC:
  ------------------
  |  |   70|  1.03k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1381:3): [True: 1.03k, False: 1.36k]
  ------------------
 1382|  1.03k|		case SC_ALGORITHM_EDDSA:
  ------------------
  |  |   72|  1.03k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1382:3): [True: 0, False: 2.39k]
  ------------------
 1383|  1.03k|		case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   73|  1.03k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1383:3): [True: 0, False: 2.39k]
  ------------------
 1384|  1.03k|			if (!ckis[i].cert_keyUsage_present) {
  ------------------
  |  Branch (1384:8): [True: 1.03k, False: 0]
  ------------------
 1385|  1.03k|				prkey_info.usage |= prkeys[i].usage_ec;
 1386|  1.03k|			}
 1387|  1.03k|			prkey_info.field_length = ckis[i].pubkey_len;
 1388|  1.03k|			sc_log(card->ctx, "DEE added key_alg %2.2lx prkey_obj.flags %8.8x",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1389|  1.03k|					ckis[i].key_alg, prkey_obj.flags);
 1390|       |
 1391|  1.03k|			if (ckis[i].key_alg == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   72|  1.03k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1391:8): [True: 0, False: 1.03k]
  ------------------
 1392|      0|				r = sc_pkcs15emu_add_eddsa_prkey(p15card, &prkey_obj, &prkey_info);
 1393|  1.03k|			else if (ckis[i].key_alg == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   73|  1.03k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1393:13): [True: 0, False: 1.03k]
  ------------------
 1394|      0|				r = sc_pkcs15emu_add_xeddsa_prkey(p15card, &prkey_obj, &prkey_info);
 1395|  1.03k|			else
 1396|  1.03k|				r = sc_pkcs15emu_add_ec_prkey(p15card, &prkey_obj, &prkey_info);
 1397|  1.03k|			break;
 1398|    707|		default:
  ------------------
  |  Branch (1398:3): [True: 707, False: 1.68k]
  ------------------
 1399|    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__
  |  |  ------------------
  ------------------
 1400|    707|			r = 0; /* we just skip this one */
 1401|  2.39k|		}
 1402|  2.39k|		sc_log(card->ctx, "USAGE: cert_keyUsage_present:%d usage:0x%8.8x", ckis[i].cert_keyUsage_present, prkey_info.usage);
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
 1403|  2.39k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Failed to add Private key");
  ------------------
  |  |  184|  2.39k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.39k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.39k|	int _ret = (r); \
  |  |  |  |  178|  2.39k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.39k]
  |  |  |  |  ------------------
  |  |  |  |  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.39k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.39k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1404|  2.39k|	}
 1405|       |
 1406|  1.09k|	p15card->ops.get_guid = piv_get_guid;
 1407|       |
 1408|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1409|     20|err:
 1410|    520|	for (i = 0; i < PIV_NUM_CERTS; i++) {
  ------------------
  |  |  370|    520|#define PIV_NUM_CERTS 25
  ------------------
  |  Branch (1410:14): [True: 500, False: 20]
  ------------------
 1411|    500|		sc_pkcs15_free_pubkey(ckis[i].pubkey_from_cert);
 1412|    500|	}
 1413|     20|	sc_pkcs15_card_clear(p15card);
 1414|     20|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1415|     20|}
pkcs15-piv.c:yk_copy_pubkey_from_tag:
  249|      4|{
  250|      4|	const unsigned char *p;
  251|      4|	unsigned int cla, tag;
  252|      4|	size_t tag_len;
  253|      4|	int r;
  254|       |
  255|      4|	p = info->pubkey.value;
  256|      4|	r = sc_asn1_read_tag(&p, info->pubkey.len, &cla, &tag, &tag_len);
  257|      4|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
  |  Branch (257:6): [True: 1, False: 3]
  ------------------
  258|      1|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      1|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  259|      1|	}
  260|      3|	if ((tag | cla) != tag_exp) {
  ------------------
  |  Branch (260:6): [True: 3, False: 0]
  ------------------
  261|      3|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  262|      3|	}
  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|     34|{
  157|     34|	sc_context_t *ctx = p15card->card->ctx;
  158|     34|	struct sc_pkcs15_prkey_info info;
  159|     34|	int r, i, gostr3410_params[3];
  160|     34|	struct sc_pkcs15_keyinfo_gostparams *keyinfo_gostparams;
  161|     34|	size_t usage_len = sizeof(info.usage);
  162|     34|	size_t af_len = sizeof(info.access_flags);
  163|     34|	struct sc_asn1_entry asn1_com_key_attr[C_ASN1_COM_KEY_ATTR_SIZE];
  164|     34|	struct sc_asn1_entry asn1_com_prkey_attr[C_ASN1_COM_PRKEY_ATTR_SIZE];
  165|     34|	struct sc_asn1_entry asn1_rsakey_attr[C_ASN1_RSAKEY_ATTR_SIZE];
  166|     34|	struct sc_asn1_entry asn1_prk_rsa_attr[C_ASN1_PRK_RSA_ATTR_SIZE];
  167|     34|	struct sc_asn1_entry asn1_gostr3410key_attr[C_ASN1_GOSTR3410KEY_ATTR_SIZE];
  168|     34|	struct sc_asn1_entry asn1_prk_gostr3410_attr[C_ASN1_PRK_GOSTR3410_ATTR_SIZE];
  169|     34|	struct sc_asn1_entry asn1_ecckey_attr[C_ASN1_ECCKEY_ATTR];
  170|     34|	struct sc_asn1_entry asn1_prk_ecc_attr[C_ASN1_PRK_ECC_ATTR];
  171|     34|	struct sc_asn1_entry asn1_prkey[C_ASN1_PRKEY_SIZE];
  172|     34|	struct sc_asn1_entry asn1_supported_algorithms[C_ASN1_SUPPORTED_ALGORITHMS_SIZE];
  173|     34|	struct sc_asn1_pkcs15_object rsa_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_rsa_attr};
  174|     34|	struct sc_asn1_pkcs15_object gostr3410_prkey_obj = {obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_gostr3410_attr};
  175|     34|	struct sc_asn1_pkcs15_object ecc_prkey_obj = { obj, asn1_com_key_attr, asn1_com_prkey_attr, asn1_prk_ecc_attr };
  176|     34|	u8 ec_domain[32];
  177|     34|	size_t ec_domain_len = sizeof(ec_domain);
  178|       |
  179|     34|	sc_copy_asn1_entry(c_asn1_prkey, asn1_prkey);
  180|     34|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  181|       |
  182|     34|	sc_copy_asn1_entry(c_asn1_prk_rsa_attr, asn1_prk_rsa_attr);
  183|     34|	sc_copy_asn1_entry(c_asn1_rsakey_attr, asn1_rsakey_attr);
  184|     34|	sc_copy_asn1_entry(c_asn1_prk_gostr3410_attr, asn1_prk_gostr3410_attr);
  185|     34|	sc_copy_asn1_entry(c_asn1_gostr3410key_attr, asn1_gostr3410key_attr);
  186|     34|	sc_copy_asn1_entry(c_asn1_prk_ecc_attr, asn1_prk_ecc_attr);
  187|     34|	sc_copy_asn1_entry(c_asn1_ecckey_attr, asn1_ecckey_attr);
  188|       |
  189|     34|	sc_copy_asn1_entry(c_asn1_com_prkey_attr, asn1_com_prkey_attr);
  190|     34|	sc_copy_asn1_entry(c_asn1_com_key_attr, asn1_com_key_attr);
  191|       |
  192|     34|	sc_format_asn1_entry(asn1_prkey + 0, &rsa_prkey_obj, NULL, 0);
  193|     34|	sc_format_asn1_entry(asn1_prkey + 1, &ecc_prkey_obj, NULL, 0);
  194|     34|	sc_format_asn1_entry(asn1_prkey + 2, &gostr3410_prkey_obj, NULL, 0);
  195|       |
  196|     34|	sc_format_asn1_entry(asn1_prk_rsa_attr + 0, asn1_rsakey_attr, NULL, 0);
  197|     34|	sc_format_asn1_entry(asn1_prk_gostr3410_attr + 0, asn1_gostr3410key_attr, NULL, 0);
  198|     34|	sc_format_asn1_entry(asn1_prk_ecc_attr + 0, asn1_ecckey_attr, NULL, 0);
  199|       |
  200|     34|	sc_format_asn1_entry(asn1_rsakey_attr + 0, &info.path, NULL, 0);
  201|     34|	sc_format_asn1_entry(asn1_rsakey_attr + 1, &info.modulus_length, NULL, 0);
  202|       |
  203|     34|	sc_format_asn1_entry(asn1_gostr3410key_attr + 0, &info.path, NULL, 0);
  204|     34|	sc_format_asn1_entry(asn1_gostr3410key_attr + 1, &gostr3410_params[0], NULL, 0);
  205|     34|	sc_format_asn1_entry(asn1_gostr3410key_attr + 2, &gostr3410_params[1], NULL, 0);
  206|     34|	sc_format_asn1_entry(asn1_gostr3410key_attr + 3, &gostr3410_params[2], NULL, 0);
  207|       |
  208|     34|	sc_format_asn1_entry(asn1_ecckey_attr + 0, &info.path, NULL, 0);
  209|     34|	sc_format_asn1_entry(asn1_ecckey_attr + 1, &info.field_length, NULL, 0);
  210|     34|	sc_format_asn1_entry(asn1_ecckey_attr + 3, ec_domain, &ec_domain_len, 0);
  211|       |
  212|     34|	sc_format_asn1_entry(asn1_com_key_attr + 0, &info.id, NULL, 0);
  213|     34|	sc_format_asn1_entry(asn1_com_key_attr + 1, &info.usage, &usage_len, 0);
  214|     34|	sc_format_asn1_entry(asn1_com_key_attr + 2, &info.native, NULL, 0);
  215|     34|	sc_format_asn1_entry(asn1_com_key_attr + 3, &info.access_flags, &af_len, 0);
  216|     34|	sc_format_asn1_entry(asn1_com_key_attr + 4, &info.key_reference, NULL, 0);
  217|       |
  218|    578|	for (i=0; i<SC_MAX_SUPPORTED_ALGORITHMS && (asn1_supported_algorithms + i)->name; i++)
  ------------------
  |  |   61|  1.15k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (218:12): [True: 544, False: 34]
  |  Branch (218:45): [True: 544, False: 0]
  ------------------
  219|    544|		sc_format_asn1_entry(asn1_supported_algorithms + i, &info.algo_refs[i], NULL, 0);
  220|     34|	sc_format_asn1_entry(asn1_com_key_attr + 5, asn1_supported_algorithms, NULL, 0);
  221|       |
  222|     34|	sc_format_asn1_entry(asn1_com_prkey_attr + 0, &info.subject.value, &info.subject.len, 0);
  223|       |
  224|       |	/* Fill in defaults */
  225|     34|	memset(&info, 0, sizeof(info));
  226|     34|	info.key_reference = -1;
  227|     34|	info.native = 1;
  228|     34|	memset(gostr3410_params, 0, sizeof(gostr3410_params));
  229|       |
  230|     34|	r = sc_asn1_decode_choice(ctx, asn1_prkey, *buf, *buflen, buf, buflen);
  231|     34|	if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|     34|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (231:6): [True: 11, False: 23]
  ------------------
  232|     11|		goto err;
  233|     23|	LOG_TEST_GOTO_ERR(ctx, r, "PrKey DF ASN.1 decoding failed");
  ------------------
  |  |  184|     23|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     23|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     23|	int _ret = (r); \
  |  |  |  |  178|     23|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 16, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|      7|	if (asn1_prkey[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|      7|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (234:6): [True: 0, False: 7]
  ------------------
  235|      0|		obj->type = SC_PKCS15_TYPE_PRKEY_RSA;
  ------------------
  |  |  419|      0|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  236|      0|	}
  237|      7|	else if (asn1_prkey[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|      7|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (237:11): [True: 0, False: 7]
  ------------------
  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)) {
  ------------------
  |  |  171|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              		if (!(asn1_ecckey_attr[1].flags & SC_ASN1_PRESENT) && (asn1_ecckey_attr[3].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  171|      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|      7|	else if (asn1_prkey[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|      7|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:11): [True: 0, False: 7]
  ------------------
  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|      7|	else {
  294|      7|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      7|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  295|      7|		LOG_TEST_GOTO_ERR(ctx, r, "Neither RSA or GOSTR3410 or ECC key in PrKDF entry.");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  296|      7|	}
  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|     34|err:
  359|     34|	if (r < 0) {
  ------------------
  |  Branch (359:6): [True: 34, False: 0]
  ------------------
  360|       |		/* This might have allocated something. If so, clear it now */
  361|     34|		free(info.subject.value);
  362|     34|		sc_pkcs15_free_key_params(&info.params);
  363|     34|	}
  364|       |
  365|     34|	return r;
  366|      0|}
sc_pkcs15_free_prkey_info:
  612|  5.63k|{
  613|  5.63k|	if (!key)
  ------------------
  |  Branch (613:6): [True: 0, False: 5.63k]
  ------------------
  614|      0|		return;
  615|       |
  616|  5.63k|	if (key->subject.value)
  ------------------
  |  Branch (616:6): [True: 223, False: 5.41k]
  ------------------
  617|    223|		free(key->subject.value);
  618|       |
  619|  5.63k|	sc_pkcs15_free_key_params(&key->params);
  620|       |
  621|  5.63k|	sc_aux_data_free(&key->aux_data);
  622|       |
  623|  5.63k|	free(key);
  624|  5.63k|}

sc_pkcs15emu_pteid_init_ex:
  349|  10.0k|{
  350|  10.0k|	int r=SC_SUCCESS;
  ------------------
  |  |   28|  10.0k|#define SC_SUCCESS				0
  ------------------
  351|  10.0k|	sc_context_t *ctx = p15card->card->ctx;
  352|  10.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  10.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  353|       |
  354|       |	/* check for proper card */
  355|  10.0k|	r = pteid_detect_card(p15card->card);
  356|  10.0k|	if (r == SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  10.0k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (356:6): [True: 9.30k, False: 706]
  ------------------
  357|  10.0k|		LOG_FUNC_RETURN(ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  164|  9.30k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.30k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.30k|	int _ret = r; \
  |  |  |  |  155|  9.30k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|  9.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.30k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.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|  9.30k|	return _ret; \
  |  |  |  |  163|  9.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|       |	/* ok: initialize and return */
  359|    706|	LOG_FUNC_RETURN(ctx, sc_pkcs15emu_pteid_init(p15card));
  ------------------
  |  |  164|    706|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    706|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    706|	int _ret = r; \
  |  |  |  |  155|    706|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 706, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    706|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    526|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 526, False: 180]
  |  |  |  |  ------------------
  |  |  |  |  157|    706|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    706|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    706|	return _ret; \
  |  |  |  |  163|    706|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|    706|}
pkcs15-pteid.c:pteid_detect_card:
  342|  10.7k|{
  343|  10.7k|	if (card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID)
  ------------------
  |  Branch (343:6): [True: 1.41k, False: 9.30k]
  ------------------
  344|  1.41k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.41k|#define SC_SUCCESS				0
  ------------------
  345|  9.30k|	return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.30k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  346|  10.7k|}
pkcs15-pteid.c:sc_pkcs15emu_pteid_init:
  143|    706|{
  144|    706|	u8 buf[1024];
  145|    706|	sc_pkcs15_df_t *df;
  146|    706|	sc_pkcs15_object_t *p15_obj;
  147|    706|	sc_path_t path;
  148|    706|	struct sc_file *file = NULL;
  149|    706|	size_t len;
  150|    706|	int rv;
  151|    706|	int i;
  152|       |
  153|    706|	sc_context_t *ctx = p15card->card->ctx;
  154|    706|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    706|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    706|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    706|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    706|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 706]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Check for correct card atr */
  157|    706|	if (pteid_detect_card(p15card->card) != SC_SUCCESS)
  ------------------
  |  |   28|    706|#define SC_SUCCESS				0
  ------------------
  |  Branch (157:6): [True: 0, False: 706]
  ------------------
  158|      0|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|      0|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  159|       |
  160|    706|	sc_log(p15card->card->ctx, "Selecting application DF");
  ------------------
  |  |   71|    706|#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|    706|	sc_format_path("4F00", &path);
  162|    706|	rv = sc_select_file(p15card->card, &path, &file);
  163|    706|	if (rv != SC_SUCCESS || !file)
  ------------------
  |  |   28|  1.41k|#define SC_SUCCESS				0
  ------------------
  |  Branch (163:6): [True: 408, False: 298]
  |  Branch (163:26): [True: 0, False: 298]
  ------------------
  164|    408|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    408|#define SC_ERROR_INTERNAL			-1400
  ------------------
  165|       |	/* set the application DF */
  166|    298|	sc_file_free(p15card->file_app);
  167|    298|	p15card->file_app = file;
  168|       |
  169|       |	/* Load TokenInfo */
  170|    298|	len = sizeof(buf);
  171|    298|	rv = dump_ef(p15card->card, "4F005032", buf, &len);
  172|    298|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    298|#define SC_SUCCESS				0
  ------------------
  |  Branch (172:6): [True: 20, False: 278]
  ------------------
  173|     20|		sc_log(ctx, "Reading of EF.TOKENINFO failed: %d", 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__
  |  |  ------------------
  ------------------
  174|     20|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  175|     20|	}
  176|    278|	rv = sc_pkcs15_parse_tokeninfo(p15card->card->ctx, p15card->tokeninfo,
  177|    278|				       buf, len);
  178|    278|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    278|#define SC_SUCCESS				0
  ------------------
  |  Branch (178:6): [True: 33, False: 245]
  ------------------
  179|     33|		sc_log(ctx, "Decoding of EF.TOKENINFO failed: %d", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  180|     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|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     33|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     33|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     33|	return _ret; \
  |  |  |  |  163|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|     33|	}
  182|       |
  183|    245|	p15card->tokeninfo->flags |= SC_PKCS15_TOKEN_PRN_GENERATION
  ------------------
  |  |  597|    245|#define SC_PKCS15_TOKEN_PRN_GENERATION			0x04
  ------------------
  184|    245|				  | SC_PKCS15_TOKEN_EID_COMPLIANT
  ------------------
  |  |  598|    245|#define SC_PKCS15_TOKEN_EID_COMPLIANT			0x08
  ------------------
  185|    245|				  | SC_PKCS15_TOKEN_READONLY;
  ------------------
  |  |  595|    245|#define SC_PKCS15_TOKEN_READONLY			0x01
  ------------------
  186|       |
  187|       |	/* Load ODF */
  188|    245|	len = sizeof(buf);
  189|    245|	rv = dump_ef(p15card->card, "4F005031", buf, &len);
  190|    245|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    245|#define SC_SUCCESS				0
  ------------------
  |  Branch (190:6): [True: 45, False: 200]
  ------------------
  191|     45|		sc_log(ctx, "Reading of ODF failed: %d", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  192|     45|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     45|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     45|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     45|	int _ret = r; \
  |  |  |  |  155|     45|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     45|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     45|	return _ret; \
  |  |  |  |  163|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|     45|	}
  194|    200|	rv = parse_odf(buf, len, p15card);
  195|    200|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    200|#define SC_SUCCESS				0
  ------------------
  |  Branch (195:6): [True: 20, False: 180]
  ------------------
  196|     20|		sc_log(ctx, "Decoding of ODF failed: %d", 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__
  |  |  ------------------
  ------------------
  197|     20|		sc_pkcs15_card_clear(p15card);
  198|     20|		LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|     20|	}
  200|       |
  201|       |	/* Decode EF.PrKDF, EF.PuKDF, EF.CDF and EF.AODF */
  202|  1.95k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (202:30): [True: 1.77k, False: 180]
  ------------------
  203|  1.77k|		if (df->type == SC_PKCS15_PRKDF) {
  ------------------
  |  |  488|  1.77k|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (203:7): [True: 137, False: 1.63k]
  ------------------
  204|    137|			rv = sc_pkcs15_parse_df(p15card, df);
  205|    137|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    137|#define SC_SUCCESS				0
  ------------------
  |  Branch (205:8): [True: 108, False: 29]
  ------------------
  206|    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__
  |  |  ------------------
  ------------------
  207|    108|				       "Decoding of EF.PrKDF (%s) failed: %d",
  208|    108|				       sc_print_path(&df->path), rv);
  209|    108|			}
  210|    137|		}
  211|  1.77k|		if (df->type == SC_PKCS15_PUKDF) {
  ------------------
  |  |  489|  1.77k|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (211:7): [True: 1.16k, False: 604]
  ------------------
  212|  1.16k|			rv = sc_pkcs15_parse_df(p15card, df);
  213|  1.16k|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|  1.16k|#define SC_SUCCESS				0
  ------------------
  |  Branch (213:8): [True: 1.08k, False: 84]
  ------------------
  214|  1.08k|				sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  215|  1.08k|				       "Decoding of EF.PuKDF (%s) failed: %d",
  216|  1.08k|				       sc_print_path(&df->path), rv);
  217|  1.08k|			}
  218|  1.16k|		}
  219|  1.77k|		if (df->type == SC_PKCS15_CDF) {
  ------------------
  |  |  492|  1.77k|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (219:7): [True: 351, False: 1.42k]
  ------------------
  220|    351|			rv = sc_pkcs15_parse_df(p15card, df);
  221|    351|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    351|#define SC_SUCCESS				0
  ------------------
  |  Branch (221:8): [True: 331, False: 20]
  ------------------
  222|    331|				sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  223|    331|				       "Decoding of EF.CDF (%s) failed: %d",
  224|    331|				       sc_print_path(&df->path), rv);
  225|    331|			}
  226|    351|		}
  227|  1.77k|		if (df->type == SC_PKCS15_AODF) {
  ------------------
  |  |  496|  1.77k|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (227:7): [True: 65, False: 1.70k]
  ------------------
  228|     65|			rv = sc_pkcs15_parse_df(p15card, df);
  229|     65|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|     65|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:8): [True: 63, False: 2]
  ------------------
  230|     63|				sc_log(ctx,
  ------------------
  |  |   71|     63|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  231|     63|				       "Decoding of EF.AODF (%s) failed: %d",
  232|     63|				       sc_print_path(&df->path), rv);
  233|     63|			}
  234|     65|		}
  235|  1.77k|	}
  236|       |
  237|    180|	p15_obj = p15card->obj_list;
  238|    180|	while (p15_obj != NULL) {
  ------------------
  |  Branch (238:9): [True: 0, False: 180]
  ------------------
  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|  1.08k|	for (i = 0; i < 5; i++) {
  ------------------
  |  Branch (295:14): [True: 900, False: 180]
  ------------------
  296|    900|		static const char *object_labels[5] = {
  297|    900|			"Trace",
  298|    900|			"Citizen Data",
  299|    900|			"Citizen Address Data",
  300|    900|			"SOd",
  301|    900|			"Citizen Notepad",
  302|    900|		};
  303|    900|		static const char *object_authids[5] = {NULL, NULL, "3", NULL, NULL};
  304|    900|		static const char *object_paths[5] = {
  305|    900|			"3f000003",
  306|    900|			"3f005f00ef02",
  307|    900|			"3f005f00ef05",
  308|    900|			"3f005f00ef06",
  309|    900|			"3f005f00ef07",
  310|    900|		};
  311|    900|		static const int object_flags[5] = {
  312|    900|			0,
  313|    900|			0,
  314|    900|			SC_PKCS15_CO_FLAG_PRIVATE,
  ------------------
  |  |   50|    900|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  315|    900|			0,
  316|    900|			0,
  317|    900|		};
  318|    900|		struct sc_pkcs15_data_info obj_info;
  319|    900|		struct sc_pkcs15_object obj_obj;
  320|       |
  321|    900|		memset(&obj_info, 0, sizeof(obj_info));
  322|    900|		memset(&obj_obj, 0, sizeof(obj_obj));
  323|       |
  324|    900|		sc_format_path(object_paths[i], &obj_info.path);
  325|    900|		strlcpy(obj_info.app_label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   43|    900|#define strlcpy _strlcpy
  ------------------
              		strlcpy(obj_info.app_label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   35|    900|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  326|    900|		if (object_authids[i] != NULL)
  ------------------
  |  Branch (326:7): [True: 180, False: 720]
  ------------------
  327|    180|			sc_pkcs15_format_id(object_authids[i], &obj_obj.auth_id);
  328|    900|		strlcpy(obj_obj.label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   43|    900|#define strlcpy _strlcpy
  ------------------
              		strlcpy(obj_obj.label, object_labels[i], SC_PKCS15_MAX_LABEL_SIZE);
  ------------------
  |  |   35|    900|#define SC_PKCS15_MAX_LABEL_SIZE	255
  ------------------
  329|    900|		obj_obj.flags = object_flags[i];
  330|       |
  331|    900|		rv = sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, &obj_obj, &obj_info);
  ------------------
  |  |  442|    900|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  332|    900|		if (rv != SC_SUCCESS){
  ------------------
  |  |   28|    900|#define SC_SUCCESS				0
  ------------------
  |  Branch (332:7): [True: 0, False: 900]
  ------------------
  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|    900|	}
  337|       |
  338|    180|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    180|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    180|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    180|	int _ret = r; \
  |  |  |  |  155|    180|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 180, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    180|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 180]
  |  |  |  |  ------------------
  |  |  |  |  157|    180|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    180|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    180|	return _ret; \
  |  |  |  |  163|    180|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  339|    180|}
pkcs15-pteid.c:dump_ef:
   55|    543|{
   56|    543|	int rv;
   57|    543|	sc_file_t *file = NULL;
   58|    543|	sc_path_t scpath;
   59|    543|	sc_format_path(path, &scpath);
   60|    543|	rv = sc_select_file(card, &scpath, &file);
   61|    543|	if (rv < 0) {
  ------------------
  |  Branch (61:6): [True: 50, False: 493]
  ------------------
   62|     50|		sc_file_free(file);
   63|     50|		return rv;
   64|     50|	}
   65|    493|	if (file->size > *buf_len) {
  ------------------
  |  Branch (65:6): [True: 13, False: 480]
  ------------------
   66|     13|		sc_file_free(file);
   67|     13|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     13|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
   68|     13|	}
   69|    480|	rv = sc_read_binary(card, 0, buf, file->size, 0);
   70|    480|	sc_file_free(file);
   71|    480|	if (rv < 0)
  ------------------
  |  Branch (71:6): [True: 2, False: 478]
  ------------------
   72|      2|		return rv;
   73|    478|	*buf_len = rv;
   74|       |
   75|    478|	return SC_SUCCESS;
  ------------------
  |  |   28|    478|#define SC_SUCCESS				0
  ------------------
   76|    480|}
pkcs15-pteid.c:parse_odf:
  105|    200|{
  106|    200|	const u8 *p = buf;
  107|    200|	size_t left = buflen;
  108|    200|	int r, i, type;
  109|    200|	sc_path_t path;
  110|    200|	struct sc_asn1_entry asn1_obj_or_path[] = {
  111|    200|		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  198|    200|#define SC_ASN1_PATH			256
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  165|    200|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{"path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0,
  ------------------
  |  |  186|    200|#define SC_ASN1_SEQUENCE                16
  ------------------
  112|    200|		 &path, NULL},
  113|    200|		{NULL, 0, 0, 0, NULL, NULL}
  114|    200|	};
  115|    200|	struct sc_asn1_entry asn1_odf[10];
  116|       |
  117|    200|	sc_path_t path_prefix;
  118|       |
  119|    200|	sc_format_path("3F004F00", &path_prefix);
  120|       |
  121|    200|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  122|  2.00k|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (122:14): [True: 1.80k, False: 200]
  ------------------
  123|  1.80k|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  124|  2.03k|	while (left > 0) {
  ------------------
  |  Branch (124:9): [True: 1.94k, False: 97]
  ------------------
  125|  1.94k|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left,
  126|  1.94k|					  &p, &left);
  127|  1.94k|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  1.94k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (127:7): [True: 83, False: 1.85k]
  ------------------
  128|     83|			break;
  129|  1.85k|		if (r < 0)
  ------------------
  |  Branch (129:7): [True: 20, False: 1.83k]
  ------------------
  130|     20|			return r;
  131|  1.83k|		type = r;
  132|  1.83k|		r = sc_pkcs15_make_absolute_path(&path_prefix, &path);
  133|  1.83k|		if (r < 0)
  ------------------
  |  Branch (133:7): [True: 0, False: 1.83k]
  ------------------
  134|      0|			return r;
  135|  1.83k|		r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  136|  1.83k|		if (r)
  ------------------
  |  Branch (136:7): [True: 0, False: 1.83k]
  ------------------
  137|      0|			return r;
  138|  1.83k|	}
  139|    180|	return 0;
  140|    200|}

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

sc_pkcs15emu_sc_hsm_decode_cvc:
  433|     75|{
  434|     75|	sc_card_t *card = p15card->card;
  435|     75|	struct sc_asn1_entry asn1_req[C_ASN1_REQ_SIZE];
  436|     75|	struct sc_asn1_entry asn1_authreq[C_ASN1_AUTHREQ_SIZE];
  437|     75|	struct sc_asn1_entry asn1_cvc[C_ASN1_CVC_SIZE];
  438|     75|	struct sc_asn1_entry asn1_cvcert[C_ASN1_CVCERT_SIZE];
  439|     75|	struct sc_asn1_entry asn1_cvc_body[C_ASN1_CVC_BODY_SIZE];
  440|     75|	struct sc_asn1_entry asn1_cvc_pubkey[C_ASN1_CVC_PUBKEY_SIZE];
  441|     75|	unsigned int cla = 0, tag = 0;
  442|     75|	size_t taglen;
  443|     75|	const u8 *tbuf;
  444|     75|	int r;
  445|       |
  446|     75|	memset(cvc, 0, sizeof(*cvc));
  447|     75|	sc_copy_asn1_entry(c_asn1_req, asn1_req);
  448|     75|	sc_copy_asn1_entry(c_asn1_cvc, asn1_cvc);
  449|       |
  450|     75|	r = sc_pkcs15emu_sc_hsm_format_asn1_cvcert(
  451|     75|			asn1_cvcert, C_ASN1_CVCERT_SIZE,
  ------------------
  |  |  242|     75|#define C_ASN1_CVCERT_SIZE 3
  ------------------
  452|     75|			asn1_cvc_body, C_ASN1_CVC_BODY_SIZE,
  ------------------
  |  |  233|     75|#define C_ASN1_CVC_BODY_SIZE 5
  ------------------
  453|     75|			asn1_cvc_pubkey, C_ASN1_CVC_PUBKEY_SIZE,
  ------------------
  |  |  219|     75|#define C_ASN1_CVC_PUBKEY_SIZE 10
  ------------------
  454|     75|			cvc);
  455|     75|	LOG_TEST_RET(card->ctx, r, "sc_asn1_entry array too small");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  456|       |
  457|     75|	sc_format_asn1_entry(asn1_cvc, asn1_cvcert, NULL, 0);
  458|       |
  459|     75|	r = sc_pkcs15emu_sc_hsm_format_asn1_req(
  460|     75|			asn1_authreq, C_ASN1_AUTHREQ_SIZE,
  ------------------
  |  |  255|     75|#define C_ASN1_AUTHREQ_SIZE 4
  ------------------
  461|     75|			asn1_cvcert, cvc);
  462|     75|	LOG_TEST_RET(card->ctx, r, "sc_asn1_entry array too small");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  463|       |
  464|     75|	sc_format_asn1_entry(asn1_req, asn1_authreq, NULL, 0);
  465|       |
  466|       |/*	sc_asn1_print_tags(*buf, *buflen); */
  467|       |
  468|     75|	tbuf = *buf;
  469|     75|	r = sc_asn1_read_tag(&tbuf, *buflen, &cla, &tag, &taglen);
  470|     75|	LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");
  ------------------
  |  |  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: 45, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  169|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     45|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     45|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     45|		return _ret; \
  |  |  |  |  172|     45|	} \
  |  |  |  |  173|     75|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  471|       |
  472|       |	/*  Determine if we deal with an authenticated request, plain request or certificate */
  473|     30|	if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
  ------------------
  |  |  210|     30|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
              	if ((cla == (SC_ASN1_TAG_APPLICATION|SC_ASN1_TAG_CONSTRUCTED)) && (tag == 7)) {
  ------------------
  |  |  214|     30|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (473:6): [True: 14, False: 16]
  |  Branch (473:68): [True: 3, False: 11]
  ------------------
  474|      3|		r = sc_asn1_decode(card->ctx, asn1_req, *buf, *buflen, buf, buflen);
  475|     27|	} else {
  476|     27|		r = sc_asn1_decode(card->ctx, asn1_cvc, *buf, *buflen, buf, buflen);
  477|     27|	}
  478|       |
  479|     30|	LOG_TEST_RET(card->ctx, r, "Could not decode card verifiable certificate");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|     54|{
 1026|     54|	if (cvc->outerSignature) {
  ------------------
  |  Branch (1026:6): [True: 0, False: 54]
  ------------------
 1027|      0|		free(cvc->outerSignature);
 1028|      0|		cvc->outerSignature = NULL;
 1029|      0|	}
 1030|     54|	if (cvc->signature) {
  ------------------
  |  Branch (1030:6): [True: 0, False: 54]
  ------------------
 1031|      0|		free(cvc->signature);
 1032|      0|		cvc->signature = NULL;
 1033|      0|	}
 1034|     54|	if (cvc->primeOrModulus) {
  ------------------
  |  Branch (1034:6): [True: 0, False: 54]
  ------------------
 1035|      0|		free(cvc->primeOrModulus);
 1036|      0|		cvc->primeOrModulus = NULL;
 1037|      0|	}
 1038|     54|	if (cvc->coefficientAorExponent) {
  ------------------
  |  Branch (1038:6): [True: 0, False: 54]
  ------------------
 1039|      0|		free(cvc->coefficientAorExponent);
 1040|      0|		cvc->coefficientAorExponent = NULL;
 1041|      0|	}
 1042|     54|	if (cvc->coefficientB) {
  ------------------
  |  Branch (1042:6): [True: 0, False: 54]
  ------------------
 1043|      0|		free(cvc->coefficientB);
 1044|      0|		cvc->coefficientB = NULL;
 1045|      0|	}
 1046|     54|	if (cvc->basePointG) {
  ------------------
  |  Branch (1046:6): [True: 0, False: 54]
  ------------------
 1047|      0|		free(cvc->basePointG);
 1048|      0|		cvc->basePointG = NULL;
 1049|      0|	}
 1050|     54|	if (cvc->order) {
  ------------------
  |  Branch (1050:6): [True: 0, False: 54]
  ------------------
 1051|      0|		free(cvc->order);
 1052|      0|		cvc->order = NULL;
 1053|      0|	}
 1054|     54|	if (cvc->publicPoint) {
  ------------------
  |  Branch (1054:6): [True: 0, False: 54]
  ------------------
 1055|      0|		free(cvc->publicPoint);
 1056|      0|		cvc->publicPoint = NULL;
 1057|      0|	}
 1058|     54|	if (cvc->cofactor) {
  ------------------
  |  Branch (1058:6): [True: 0, False: 54]
  ------------------
 1059|      0|		free(cvc->cofactor);
 1060|       |		cvc->cofactor = NULL;
 1061|      0|	}
 1062|     54|}
sc_pkcs15emu_sc_hsm_init_ex:
 1612|  9.68k|{
 1613|  9.68k|	if (p15card->card->type != SC_CARD_TYPE_SC_HSM
  ------------------
  |  Branch (1613:6): [True: 9.68k, False: 0]
  ------------------
 1614|  9.68k|			&& p15card->card->type != SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1614:7): [True: 9.68k, False: 0]
  ------------------
 1615|  9.68k|			&& p15card->card->type != SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1615:7): [True: 9.42k, False: 255]
  ------------------
 1616|  9.42k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.42k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1617|  9.42k|	}
 1618|    255|	return sc_pkcs15emu_sc_hsm_init(p15card);
 1619|  9.68k|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_format_asn1_cvcert:
  365|     75|{
  366|     75|	if ((asn1_cvc_pubkey_len < C_ASN1_CVC_PUBKEY_SIZE) ||
  ------------------
  |  |  219|     75|#define C_ASN1_CVC_PUBKEY_SIZE 10
  ------------------
  |  Branch (366:6): [True: 0, False: 75]
  ------------------
  367|     75|		(asn1_cvc_body_len < C_ASN1_CVC_BODY_SIZE) ||
  ------------------
  |  |  233|     75|#define C_ASN1_CVC_BODY_SIZE 5
  ------------------
  |  Branch (367:3): [True: 0, False: 75]
  ------------------
  368|     75|		(asn1_cvcert_len < C_ASN1_CVCERT_SIZE)) {
  ------------------
  |  |  242|     75|#define C_ASN1_CVCERT_SIZE 3
  ------------------
  |  Branch (368:3): [True: 0, False: 75]
  ------------------
  369|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  370|      0|	}
  371|       |
  372|     75|	sc_copy_asn1_entry(c_asn1_cvc_pubkey, asn1_cvc_pubkey);
  373|     75|	sc_copy_asn1_entry(c_asn1_cvc_body, asn1_cvc_body);
  374|     75|	sc_copy_asn1_entry(c_asn1_cvcert, asn1_cvcert);
  375|       |
  376|     75|	sc_format_asn1_entry(asn1_cvc_pubkey    , &cvc->pukoid, NULL, 0);
  377|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 1, &cvc->primeOrModulus, &cvc->primeOrModuluslen, 0);
  378|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 2, &cvc->coefficientAorExponent, &cvc->coefficientAorExponentlen, 0);
  379|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 3, &cvc->coefficientB, &cvc->coefficientBlen, 0);
  380|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 4, &cvc->basePointG, &cvc->basePointGlen, 0);
  381|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 5, &cvc->order, &cvc->orderlen, 0);
  382|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 6, &cvc->publicPoint, &cvc->publicPointlen, 0);
  383|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 7, &cvc->cofactor, &cvc->cofactorlen, 0);
  384|     75|	sc_format_asn1_entry(asn1_cvc_pubkey + 8, &cvc->modulusSize, NULL, 0);
  385|       |
  386|     75|	sc_format_asn1_entry(asn1_cvc_body    , &cvc->cpi, NULL, 0);
  387|     75|	cvc->carLen = sizeof(cvc->car);
  388|     75|	sc_format_asn1_entry(asn1_cvc_body + 1, &cvc->car, &cvc->carLen, 0);
  389|     75|	sc_format_asn1_entry(asn1_cvc_body + 2, asn1_cvc_pubkey, NULL, 0);
  390|     75|	cvc->chrLen = sizeof(cvc->chr);
  391|     75|	sc_format_asn1_entry(asn1_cvc_body + 3, &cvc->chr, &cvc->chrLen, 0);
  392|       |
  393|     75|	sc_format_asn1_entry(asn1_cvcert    , asn1_cvc_body, NULL, 0);
  394|     75|	sc_format_asn1_entry(asn1_cvcert + 1, &cvc->signature, &cvc->signatureLen, 0);
  395|     75|	return SC_SUCCESS;
  ------------------
  |  |   28|     75|#define SC_SUCCESS				0
  ------------------
  396|     75|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_format_asn1_req:
  413|     75|{
  414|     75|	if (asn1_authreq_len < C_ASN1_AUTHREQ_SIZE) {
  ------------------
  |  |  255|     75|#define C_ASN1_AUTHREQ_SIZE 4
  ------------------
  |  Branch (414:6): [True: 0, False: 75]
  ------------------
  415|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  416|      0|	}
  417|       |
  418|     75|	sc_copy_asn1_entry(c_asn1_authreq, asn1_authreq);
  419|       |
  420|     75|	sc_format_asn1_entry(asn1_authreq    , asn1_cvcert, NULL, 0);
  421|     75|	cvc->outerCARLen = sizeof(cvc->outer_car);
  422|     75|	sc_format_asn1_entry(asn1_authreq + 1, &cvc->outer_car, &cvc->outerCARLen, 0);
  423|     75|	sc_format_asn1_entry(asn1_authreq + 2, &cvc->outerSignature, &cvc->outerSignatureLen, 0);
  424|     75|	return SC_SUCCESS;
  ------------------
  |  |   28|     75|#define SC_SUCCESS				0
  ------------------
  425|     75|}
pkcs15-sc-hsm.c:sc_pkcs15emu_sc_hsm_init:
 1350|    255|{
 1351|    255|	sc_card_t *card = p15card->card;
 1352|    255|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1353|    255|	sc_file_t *file = NULL;
 1354|    255|	sc_path_t path;
 1355|    255|	u8 filelist[MAX_EXT_APDU_LENGTH];
 1356|    255|	int filelistlength;
 1357|    255|	int r, i;
 1358|    255|	sc_cvc_t devcert;
 1359|    255|	struct sc_app_info *appinfo;
 1360|    255|	struct sc_pkcs15_auth_info pin_info;
 1361|    255|	struct sc_pkcs15_object pin_obj;
 1362|    255|	struct sc_pin_cmd_data pindata;
 1363|    255|	u8 efbin[1024];
 1364|    255|	u8 *ptr;
 1365|    255|	size_t len;
 1366|       |
 1367|    255|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    255|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    255|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    255|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    255|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 255]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1368|       |
 1369|    255|	appinfo = calloc(1, sizeof(struct sc_app_info));
 1370|       |
 1371|    255|	if (appinfo == NULL) {
  ------------------
  |  Branch (1371:6): [True: 0, False: 255]
  ------------------
 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|    255|	appinfo->aid = sc_hsm_aid;
 1376|       |
 1377|    255|	appinfo->ddo.aid = sc_hsm_aid;
 1378|    255|	p15card->app = appinfo;
 1379|       |
 1380|    255|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    255|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1381|    255|	r = sc_select_file(card, &path, &file);
 1382|    255|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|    255|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    255|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    255|	int _ret = (r); \
  |  |  |  |  168|    255|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 191, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  169|    191|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    191|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    191|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    191|		return _ret; \
  |  |  |  |  172|    191|	} \
  |  |  |  |  173|    255|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1383|       |
 1384|     64|	p15card->card->version.hw_major = 24;	/* JCOP 2.4.1r3 */
 1385|     64|	p15card->card->version.hw_minor = 13;
 1386|     64|	if (file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1386:6): [True: 64, False: 0]
  |  Branch (1386:14): [True: 5, False: 59]
  |  Branch (1386:33): [True: 3, False: 2]
  ------------------
 1387|      3|		p15card->card->version.fw_major = file->prop_attr[file->prop_attr_len - 2];
 1388|      3|		p15card->card->version.fw_minor = file->prop_attr[file->prop_attr_len - 1];
 1389|      3|	}
 1390|       |
 1391|     64|	sc_file_free(file);
 1392|       |
 1393|       |	/* Read device certificate to determine serial number */
 1394|     64|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (1394:6): [True: 0, False: 64]
  |  Branch (1394:27): [True: 0, False: 0]
  ------------------
 1395|      0|		ptr = priv->EF_C_DevAut;
 1396|      0|		len = priv->EF_C_DevAut_len;
 1397|     64|	} else {
 1398|     64|		len = sizeof efbin;
 1399|     64|		r = read_file(p15card, (u8 *) "\x2F\x02", efbin, &len, 1);
 1400|     64|		LOG_TEST_RET(card->ctx, r, "Skipping optional EF.C_DevAut");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1401|       |
 1402|     64|		if (len > 0) {
  ------------------
  |  Branch (1402:7): [True: 33, False: 31]
  ------------------
 1403|       |			/* save EF_C_DevAut for further use */
 1404|     33|			ptr = realloc(priv->EF_C_DevAut, len);
 1405|     33|			if (ptr) {
  ------------------
  |  Branch (1405:8): [True: 33, False: 0]
  ------------------
 1406|     33|				memcpy(ptr, efbin, len);
 1407|     33|				priv->EF_C_DevAut = ptr;
 1408|     33|				priv->EF_C_DevAut_len = len;
 1409|     33|			}
 1410|     33|		}
 1411|       |
 1412|     64|		ptr = efbin;
 1413|     64|	}
 1414|       |
 1415|     64|	memset(&devcert, 0 ,sizeof(devcert));
 1416|     64|	r = sc_pkcs15emu_sc_hsm_decode_cvc(p15card, (const u8 **)&ptr, &len, &devcert);
 1417|     64|	LOG_TEST_RET(card->ctx, r, "Could not decode EF.C_DevAut");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 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|     64|{
  294|     64|	sc_path_t path;
  295|     64|	int r;
  296|       |
  297|     64|	sc_path_set(&path, SC_PATH_TYPE_FILE_ID, fid, 2, 0, 0);
  ------------------
  |  |  117|     64|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  298|       |	/* look this up with our AID */
  299|     64|	path.aid = sc_hsm_aid;
  300|       |	/* we don't have a pre-known size of the file */
  301|     64|	path.count = -1;
  302|     64|	if (!p15card->opts.use_file_cache || !efbin
  ------------------
  |  Branch (302:6): [True: 64, False: 0]
  |  Branch (302:39): [True: 0, False: 0]
  ------------------
  303|     64|			|| 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|     64|		path.aid.len = 0;
  306|     64|		r = sc_select_file(p15card->card, &path, NULL);
  307|     64|		if (r < 0) {
  ------------------
  |  Branch (307:7): [True: 19, False: 45]
  ------------------
  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|     45|		} else {
  310|     45|			r = sc_read_binary(p15card->card, 0, efbin, *len, 0);
  311|     45|		}
  312|       |
  313|     64|		if (r < 0) {
  ------------------
  |  Branch (313:7): [True: 27, False: 37]
  ------------------
  314|     27|			sc_log(p15card->card->ctx, "Could not read EF");
  ------------------
  |  |   71|     27|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|     27|			if (!optional) {
  ------------------
  |  Branch (315:8): [True: 0, False: 27]
  ------------------
  316|      0|				return r;
  317|      0|			}
  318|       |			/* optional files are saved as empty files to avoid card
  319|       |			 * transactions. Parsing the file's data will reveal that they were
  320|       |			 * missing. */
  321|     27|			*len = 0;
  322|     37|		} else {
  323|     37|			*len = r;
  324|     37|		}
  325|       |
  326|     64|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (326:7): [True: 0, False: 64]
  ------------------
  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|     64|	}
  332|       |
  333|     64|	return SC_SUCCESS;
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  334|     64|}

sc_pkcs15_decipher:
  283|   176k|{
  284|   176k|	sc_context_t *ctx = p15card->card->ctx;
  285|   176k|	int r;
  286|   176k|	sc_algorithm_info_t *alg_info = NULL;
  287|   176k|	sc_security_env_t senv;
  288|   176k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  289|   176k|	unsigned long pad_flags = 0, sec_flags = 0;
  290|       |
  291|   176k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   176k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   176k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   176k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   176k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 176k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|       |
  293|   176k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  306|   176k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|   176k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (293:6): [True: 108k, False: 68.4k]
  ------------------
  294|   176k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for decryption");
  ------------------
  |  |  174|   108k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   108k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   108k|	int _ret = (r); \
  |  |  |  |  168|   108k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 108k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   108k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   108k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   108k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   108k|		return _ret; \
  |  |  |  |  172|   108k|	} \
  |  |  |  |  173|   108k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  295|       |
  296|  68.4k|	r = format_senv(p15card, obj, &senv, &alg_info);
  297|  68.4k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  68.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  68.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  68.4k|	int _ret = (r); \
  |  |  |  |  168|  68.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 59.0k, False: 9.48k]
  |  |  |  |  ------------------
  |  |  |  |  169|  59.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  59.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  59.0k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  59.0k|		return _ret; \
  |  |  |  |  172|  59.0k|	} \
  |  |  |  |  173|  68.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9.48k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  298|  9.48k|	senv.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   47|  9.48k|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  299|       |
  300|  9.48k|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  301|  9.48k|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|  9.48k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.48k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.48k|	int _ret = (r); \
  |  |  |  |  168|  9.48k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.83k, False: 4.64k]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.83k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.83k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.83k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.83k|		return _ret; \
  |  |  |  |  172|  4.83k|	} \
  |  |  |  |  173|  9.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.64k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  302|  4.64k|	senv.algorithm_flags = sec_flags;
  303|       |
  304|  4.64k|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  305|  4.64k|			outlen);
  306|  4.64k|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|  4.64k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.64k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.64k|	int _ret = (r); \
  |  |  |  |  168|  4.64k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4.18k, False: 465]
  |  |  |  |  ------------------
  |  |  |  |  169|  4.18k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.18k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  4.18k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  4.18k|		return _ret; \
  |  |  |  |  172|  4.18k|	} \
  |  |  |  |  173|  4.64k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 465]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Strip any padding */
  309|    465|	if (pad_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) {
  ------------------
  |  |  110|    465|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (309:6): [True: 183, False: 282]
  ------------------
  310|    183|		unsigned int s = r;
  311|    183|		unsigned int key_size = (unsigned int)alg_info->key_length;
  312|    183|		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|    183|	}
  315|    282|#ifdef ENABLE_OPENSSL
  316|    282|	else if (pad_flags & SC_ALGORITHM_RSA_PAD_OAEP) {
  ------------------
  |  |  108|    282|#define SC_ALGORITHM_RSA_PAD_OAEP	0x00000020 /* PKCS#1 v2.0 OAEP */
  ------------------
  |  Branch (316:11): [True: 0, False: 282]
  ------------------
  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|    465|#endif
  334|       |	/* do not log error code to prevent side channel attack */
  335|    465|	return r;
  336|    465|}
sc_pkcs15_derive:
  349|  44.1k|{
  350|  44.1k|	sc_context_t *ctx = p15card->card->ctx;
  351|  44.1k|	int r;
  352|  44.1k|	sc_algorithm_info_t *alg_info = NULL;
  353|  44.1k|	sc_security_env_t senv;
  354|  44.1k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  355|  44.1k|	unsigned long pad_flags = 0, sec_flags = 0;
  356|       |
  357|  44.1k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  44.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  44.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  44.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  44.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 44.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  358|       |
  359|  44.1k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DERIVE)))
  ------------------
  |  |  313|  44.1k|#define SC_PKCS15_PRKEY_USAGE_DERIVE		0x100
  ------------------
  |  Branch (359:6): [True: 24.1k, False: 20.0k]
  ------------------
  360|  44.1k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for derivation");
  ------------------
  |  |  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: 24.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  24.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|  24.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  24.1k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  24.1k|		return _ret; \
  |  |  |  |  172|  24.1k|	} \
  |  |  |  |  173|  24.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  361|       |
  362|  20.0k|	switch (obj->type) {
  363|    668|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|    668|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (363:3): [True: 668, False: 19.3k]
  ------------------
  364|    668|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|    668|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (364:3): [True: 0, False: 20.0k]
  ------------------
  365|    668|			if (out == NULL || *poutlen < BYTES4BITS(prkey->field_length)) {
  ------------------
  |  |  145|    668|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  |  Branch (365:8): [True: 0, False: 668]
  |  Branch (365:23): [True: 0, False: 668]
  ------------------
  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|    668|			break;
  371|  19.3k|		default:
  ------------------
  |  Branch (371:3): [True: 19.3k, False: 668]
  ------------------
  372|  19.3k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED,"Key type not supported");
  ------------------
  |  |  174|  19.3k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  19.3k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  19.3k|	int _ret = (r); \
  |  |  |  |  168|  19.3k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  19.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|  19.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  19.3k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  19.3k|		return _ret; \
  |  |  |  |  172|  19.3k|	} \
  |  |  |  |  173|  19.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|  20.0k|	}
  374|       |
  375|    668|	r = format_senv(p15card, obj, &senv, &alg_info);
  376|    668|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|    668|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    668|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    668|	int _ret = (r); \
  |  |  |  |  168|    668|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 139, False: 529]
  |  |  |  |  ------------------
  |  |  |  |  169|    139|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    139|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    139|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    139|		return _ret; \
  |  |  |  |  172|    139|	} \
  |  |  |  |  173|    668|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 529]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    529|	senv.operation = SC_SEC_OPERATION_DERIVE;
  ------------------
  |  |   50|    529|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  378|       |
  379|    529|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  380|    529|	LOG_TEST_RET(ctx, r, "cannot encode security operation flags");
  ------------------
  |  |  174|    529|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    529|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    529|	int _ret = (r); \
  |  |  |  |  168|    529|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 529]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    529|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 529]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  381|    529|	senv.algorithm_flags = sec_flags;
  382|       |
  383|    529|	r = use_key(p15card, obj, &senv, sc_decipher, in, inlen, out,
  384|    529|			*poutlen);
  385|    529|	LOG_TEST_RET(ctx, r, "use_key() failed");
  ------------------
  |  |  174|    529|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    529|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    529|	int _ret = (r); \
  |  |  |  |  168|    529|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 528, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|    528|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    528|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    528|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    528|		return _ret; \
  |  |  |  |  172|    528|	} \
  |  |  |  |  173|    529|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  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|      1|	*poutlen = r;
  390|      1|	LOG_FUNC_RETURN(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: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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|	} 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|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|      1|}
sc_pkcs15_unwrap:
  405|   176k|{
  406|   176k|	sc_context_t *ctx = p15card->card->ctx;
  407|   176k|	int r;
  408|   176k|	sc_algorithm_info_t *alg_info = NULL;
  409|   176k|	sc_security_env_t senv;
  410|   176k|	const struct sc_pkcs15_prkey_info *src_prkey = (const struct sc_pkcs15_prkey_info *) key->data;
  411|   176k|	const struct sc_pkcs15_skey_info *src_skey = (const struct sc_pkcs15_skey_info *) key->data;
  412|   176k|	const struct sc_pkcs15_skey_info *tkey = (const struct sc_pkcs15_skey_info *) target_key->data;
  413|   176k|	unsigned long pad_flags = 0, sec_flags = 0;
  414|   176k|	u8 *out = 0;
  415|   176k|	size_t poutlen = 0;
  416|   176k|	sc_path_t path, target_file_id;
  417|   176k|	sc_sec_env_param_t senv_param;
  418|       |
  419|   176k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   176k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   176k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   176k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   176k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 176k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|       |
  421|   176k|	if (key->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|   176k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (421:6): [True: 18.0k, False: 158k]
  ------------------
  422|  18.0k|		if (!(src_prkey->usage & (SC_PKCS15_PRKEY_USAGE_UNWRAP)))
  ------------------
  |  |  310|  18.0k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  |  Branch (422:7): [True: 14.0k, False: 3.99k]
  ------------------
  423|  18.0k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for unwrapping");
  ------------------
  |  |  174|  14.0k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  14.0k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  14.0k|	int _ret = (r); \
  |  |  |  |  168|  14.0k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 14.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  14.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  14.0k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  14.0k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  14.0k|		return _ret; \
  |  |  |  |  172|  14.0k|	} \
  |  |  |  |  173|  14.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  424|  18.0k|	}
  425|   158k|	else if ((key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  416|   158k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	else if ((key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY) {
  ------------------
  |  |  432|   158k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (425:11): [True: 0, False: 158k]
  ------------------
  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|   158k|	else
  430|   158k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Key type not supported");
  ------------------
  |  |  174|   158k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   158k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   158k|	int _ret = (r); \
  |  |  |  |  168|   158k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 158k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   158k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   158k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   158k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   158k|		return _ret; \
  |  |  |  |  172|   158k|	} \
  |  |  |  |  173|   158k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|       |
  432|  3.99k|	r = format_senv(p15card, key, &senv, &alg_info);
  433|  3.99k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  3.99k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.99k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.99k|	int _ret = (r); \
  |  |  |  |  168|  3.99k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 232, False: 3.76k]
  |  |  |  |  ------------------
  |  |  |  |  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.99k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.76k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  434|  3.76k|	senv.operation = SC_SEC_OPERATION_UNWRAP;
  ------------------
  |  |   52|  3.76k|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  435|       |
  436|  3.76k|	memset(&path, 0, sizeof(sc_path_t));
  437|  3.76k|	memset(&target_file_id, 0, sizeof(sc_path_t));
  438|       |
  439|  3.76k|	if (!tkey->path.len && tkey->path.aid.len) {
  ------------------
  |  Branch (439:6): [True: 3.76k, False: 0]
  |  Branch (439:25): [True: 0, False: 3.76k]
  ------------------
  440|       |		/* Target key is a SDO allocated in application DF */
  441|      0|		target_file_id = tkey->path;
  442|      0|	}
  443|  3.76k|	else if (tkey->path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (443:11): [True: 0, False: 3.76k]
  |  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.76k|	else if (tkey->path.len > 2) {
  ------------------
  |  Branch (450:11): [True: 0, False: 3.76k]
  ------------------
  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.76k|	else {
  457|  3.76k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid unwrapping target key path");
  ------------------
  |  |  174|  3.76k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.76k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.76k|	int _ret = (r); \
  |  |  |  |  168|  3.76k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.76k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.76k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.76k|		return _ret; \
  |  |  |  |  172|  3.76k|	} \
  |  |  |  |  173|  3.76k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  458|  3.76k|	}
  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|   176k|		const u8 *param, size_t paramlen) {
  491|   176k|	sc_context_t *ctx = p15card->card->ctx;
  492|   176k|	int r;
  493|   176k|	sc_algorithm_info_t *alg_info = NULL;
  494|   176k|	sc_security_env_t senv;
  495|   176k|	const struct sc_pkcs15_prkey_info *src_prkey = (const struct sc_pkcs15_prkey_info *) key->data;
  496|   176k|	const struct sc_pkcs15_skey_info *src_skey = (const struct sc_pkcs15_skey_info *) key->data;
  497|   176k|	const struct sc_pkcs15_prkey_info *target_prkey = (const struct sc_pkcs15_prkey_info *) target_key->data;
  498|   176k|	const struct sc_pkcs15_skey_info *target_skey = (const struct sc_pkcs15_skey_info *) target_key->data;
  499|   176k|	unsigned long pad_flags = 0, sec_flags = 0;
  500|   176k|	sc_path_t tkey_path;
  501|   176k|	sc_path_t path, target_file_id;
  502|   176k|	sc_sec_env_param_t senv_param;
  503|       |
  504|   176k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   176k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   176k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   176k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   176k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 176k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  505|       |
  506|   176k|	switch (key->type) {
  507|  18.0k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  18.0k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (507:3): [True: 18.0k, False: 158k]
  ------------------
  508|  18.0k|			if (!(src_prkey->usage & (SC_PKCS15_PRKEY_USAGE_WRAP)))
  ------------------
  |  |  309|  18.0k|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  |  Branch (508:8): [True: 16.4k, False: 1.61k]
  ------------------
  509|  18.0k|				LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for wrapping");
  ------------------
  |  |  174|  16.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  16.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  16.4k|	int _ret = (r); \
  |  |  |  |  168|  16.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  16.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|  16.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  16.4k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  16.4k|		return _ret; \
  |  |  |  |  172|  16.4k|	} \
  |  |  |  |  173|  16.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  510|  1.61k|			break;
  511|  1.61k|		case SC_PKCS15_TYPE_SKEY_DES:
  ------------------
  |  |  434|      0|#define SC_PKCS15_TYPE_SKEY_DES			0x302
  ------------------
  |  Branch (511:3): [True: 0, False: 176k]
  ------------------
  512|      0|		case SC_PKCS15_TYPE_SKEY_3DES:
  ------------------
  |  |  436|      0|#define SC_PKCS15_TYPE_SKEY_3DES		0x304
  ------------------
  |  Branch (512:3): [True: 0, False: 176k]
  ------------------
  513|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (513:3): [True: 0, False: 176k]
  ------------------
  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|   158k|		default:
  ------------------
  |  Branch (517:3): [True: 158k, False: 18.0k]
  ------------------
  518|   158k|			LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Wrapping key type not supported");
  ------------------
  |  |  174|   158k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   158k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   158k|	int _ret = (r); \
  |  |  |  |  168|   158k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 158k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   158k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   158k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   158k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   158k|		return _ret; \
  |  |  |  |  172|   158k|	} \
  |  |  |  |  173|   158k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  519|   176k|	}
  520|       |
  521|  1.61k|	if (!(target_key->type == SC_PKCS15_TYPE_PRKEY_RSA ||
  ------------------
  |  |  419|  3.22k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (521:8): [True: 0, False: 1.61k]
  ------------------
  522|  1.61k|			(target_key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)) {
  ------------------
  |  |  416|  1.61k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              			(target_key->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY)) {
  ------------------
  |  |  432|  1.61k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (522:4): [True: 1.61k, 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|  1.61k|	r = format_senv(p15card, key, &senv, &alg_info);
  527|  1.61k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|  1.61k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.61k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.61k|	int _ret = (r); \
  |  |  |  |  168|  1.61k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 40, False: 1.57k]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.61k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.57k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  528|  1.57k|	senv.operation = SC_SEC_OPERATION_WRAP;
  ------------------
  |  |   51|  1.57k|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  529|       |
  530|  1.57k|	memset(&path, 0, sizeof (sc_path_t));
  531|  1.57k|	memset(&target_file_id, 0, sizeof (sc_path_t));
  532|       |
  533|  1.57k|	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: 1.57k]
  ------------------
  535|      0|			tkey_path = target_prkey->path;
  536|      0|			break;
  537|  1.57k|		default: /* we already know it is a secret key */
  ------------------
  |  Branch (537:3): [True: 1.57k, False: 0]
  ------------------
  538|  1.57k|			tkey_path = target_skey->path;
  539|  1.57k|			break;
  540|  1.57k|	}
  541|       |
  542|  1.57k|	if (!tkey_path.len && tkey_path.aid.len) {
  ------------------
  |  Branch (542:6): [True: 1.57k, False: 0]
  |  Branch (542:24): [True: 0, False: 1.57k]
  ------------------
  543|       |		/* Target key is a SDO allocated in application DF */
  544|      0|		target_file_id = tkey_path;
  545|  1.57k|	} else if (tkey_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (545:13): [True: 0, False: 1.57k]
  |  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|  1.57k|	} else if (tkey_path.len > 2) {
  ------------------
  |  Branch (551:13): [True: 0, False: 1.57k]
  ------------------
  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|  1.57k|	else {
  558|  1.57k|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "invalid unwrapping target key path");
  ------------------
  |  |  174|  1.57k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.57k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.57k|	int _ret = (r); \
  |  |  |  |  168|  1.57k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.57k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.57k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.57k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.57k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.57k|		return _ret; \
  |  |  |  |  172|  1.57k|	} \
  |  |  |  |  173|  1.57k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|  1.57k|	}
  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|   794k|{
  598|   794k|	sc_context_t *ctx = p15card->card->ctx;
  599|   794k|	int r;
  600|   794k|	sc_security_env_t senv;
  601|   794k|	sc_algorithm_info_t *alg_info;
  602|   794k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  603|   794k|	u8 *buf = NULL, *tmp;
  604|   794k|	size_t modlen = 0, buflen = 0;
  605|   794k|	unsigned long pad_flags = 0, sec_flags = 0;
  606|       |
  607|   794k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|   794k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   794k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   794k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   794k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 794k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|   794k|	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  307|   794k|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              	if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
  ------------------
  |  |  308|   794k|#define SC_PKCS15_PRKEY_USAGE_SIGNRECOVER	0x08
  ------------------
  |  Branch (609:6): [True: 541k, False: 253k]
  ------------------
  610|   794k|					SC_PKCS15_PRKEY_USAGE_NONREPUDIATION)))
  ------------------
  |  |  314|   794k|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  611|   794k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This key cannot be used for signing");
  ------------------
  |  |  174|   541k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   541k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   541k|	int _ret = (r); \
  |  |  |  |  168|   541k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 541k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   541k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   541k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   541k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   541k|		return _ret; \
  |  |  |  |  172|   541k|	} \
  |  |  |  |  173|   541k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  612|       |
  613|   253k|	r = format_senv(p15card, obj, &senv, &alg_info);
  614|   253k|	LOG_TEST_RET(ctx, r, "Could not initialize security environment");
  ------------------
  |  |  174|   253k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   253k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   253k|	int _ret = (r); \
  |  |  |  |  168|   253k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 204k, False: 48.7k]
  |  |  |  |  ------------------
  |  |  |  |  169|   204k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   204k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   204k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   204k|		return _ret; \
  |  |  |  |  172|   204k|	} \
  |  |  |  |  173|   253k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  615|  48.7k|	senv.operation = SC_SEC_OPERATION_SIGN;
  ------------------
  |  |   48|  48.7k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  616|       |
  617|  48.7k|	switch (obj->type) {
  618|  42.8k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  42.8k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (618:3): [True: 42.8k, False: 5.88k]
  ------------------
  619|  42.8k|			modlen = BYTES4BITS(prkey->modulus_length);
  ------------------
  |  |  145|  42.8k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  620|  42.8k|			break;
  621|      0|		case SC_PKCS15_TYPE_PRKEY_GOSTR3410:
  ------------------
  |  |  420|      0|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (621:3): [True: 0, False: 48.7k]
  ------------------
  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|  5.88k|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  5.88k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (624:3): [True: 5.88k, False: 42.8k]
  ------------------
  625|  5.88k|		case SC_PKCS15_TYPE_PRKEY_EDDSA:
  ------------------
  |  |  422|  5.88k|#define SC_PKCS15_TYPE_PRKEY_EDDSA		0x105
  ------------------
  |  Branch (625:3): [True: 0, False: 48.7k]
  ------------------
  626|  5.88k|		case SC_PKCS15_TYPE_PRKEY_XEDDSA:
  ------------------
  |  |  423|  5.88k|#define SC_PKCS15_TYPE_PRKEY_XEDDSA		0x106
  ------------------
  |  Branch (626:3): [True: 0, False: 48.7k]
  ------------------
  627|  5.88k|			modlen = BYTES4BITS(prkey->field_length) * 2;  /* 2*nLen */
  ------------------
  |  |  145|  5.88k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  628|  5.88k|			break;
  629|      0|		default:
  ------------------
  |  Branch (629:3): [True: 0, False: 48.7k]
  ------------------
  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|  48.7k|	}
  632|       |
  633|       |	/* Probably never happens, but better make sure */
  634|  48.7k|	if (outlen < modlen)
  ------------------
  |  Branch (634:6): [True: 0, False: 48.7k]
  ------------------
  635|  48.7k|		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|  48.7k|	buflen = inlen + modlen;
  638|  48.7k|	buf = sc_mem_secure_alloc(buflen);
  639|  48.7k|	if (buf == NULL)
  ------------------
  |  Branch (639:6): [True: 0, False: 48.7k]
  ------------------
  640|  48.7k|		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|  48.7k|	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|  48.7k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_GOSTR3410) {
  ------------------
  |  |  420|  48.7k|#define SC_PKCS15_TYPE_PRKEY_GOSTR3410		0x103
  ------------------
  |  Branch (646:6): [True: 0, False: 48.7k]
  ------------------
  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|  48.7k|	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|  48.7k|	sc_log(ctx, "supported algorithm flags 0x%lX, private key usage 0x%X", alg_info->flags, prkey->usage);
  ------------------
  |  |   71|  48.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__
  |  |  ------------------
  ------------------
  661|  48.7k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA) {
  ------------------
  |  |  419|  48.7k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (661:6): [True: 42.8k, False: 5.88k]
  ------------------
  662|  42.8k|		if ((alg_info->flags & SC_ALGORITHM_NEED_USAGE) &&
  ------------------
  |  |   95|  42.8k|#define SC_ALGORITHM_NEED_USAGE		0x40000000
  ------------------
  |  Branch (662:7): [True: 0, False: 42.8k]
  ------------------
  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|				r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|      0|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  672|      0|				LOG_TEST_GOTO_ERR(ctx, r, "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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  673|      0|			}
  674|       |
  675|       |			/* XXX Assuming RSA key here */
  676|      0|			r = sc_pkcs1_encode(ctx, flags, in, inlen, buf, &tmplen, prkey->modulus_length, pMechanism);
  677|       |
  678|       |			/* no padding needed - already done */
  679|      0|			flags &= ~SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  103|      0|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  680|       |			/* instead use raw rsa */
  681|      0|			flags |= SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  682|       |
  683|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  684|       |
  685|      0|			r = sc_pkcs15_decipher(p15card, obj, flags, buf, modlen, out, outlen, NULL);
  686|      0|			goto err;
  687|      0|		}
  688|       |
  689|       |
  690|       |		/* If the card doesn't support the requested algorithm, we normally add the
  691|       |		 * padding here in software and ask the card to do a raw signature.  There's
  692|       |		 * one exception to that, where we might be able to get the signature to
  693|       |		 * succeed by stripping padding if the card only offers higher-level
  694|       |		 * signature operations.  The only thing we can strip is the DigestInfo
  695|       |		 * block from PKCS1 padding. */
  696|  42.8k|		if ((flags == (SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_HASH_NONE)) &&
  ------------------
  |  |  109|  42.8k|#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|  42.8k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (696:7): [True: 0, False: 42.8k]
  ------------------
  697|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_RAW) &&
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (697:4): [True: 0, False: 0]
  ------------------
  698|      0|			!(alg_info->flags & SC_ALGORITHM_RSA_HASH_NONE) &&
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  |  Branch (698:4): [True: 0, False: 0]
  ------------------
  699|      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 (699:4): [True: 0, False: 0]
  ------------------
  700|      0|			unsigned int algo;
  701|      0|			size_t tmplen = buflen;
  702|       |
  703|      0|			r = sc_pkcs1_strip_digest_info_prefix(&algo, tmp, inlen, tmp, &tmplen);
  704|      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 (704:8): [True: 0, False: 0]
  |  Branch (704:27): [True: 0, False: 0]
  ------------------
  705|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  706|      0|				goto err;
  707|      0|			}
  708|      0|			flags &= ~SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  133|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  709|      0|			flags |= algo;
  710|      0|			inlen = tmplen;
  711|      0|		}
  712|  42.8k|	}
  713|       |
  714|       |
  715|       |	/* ECDSA software hash has already been done, or is not needed, or card will do hash */
  716|       |	/* if card can not do the hash, will use SC_ALGORITHM_ECDSA_RAW */
  717|  48.7k|	if (obj->type == SC_PKCS15_TYPE_PRKEY_EC) {
  ------------------
  |  |  421|  48.7k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (717:6): [True: 5.88k, False: 42.8k]
  ------------------
  718|  5.88k|		if ((alg_info->flags & SC_ALGORITHM_ECDSA_RAW)
  ------------------
  |  |  174|  5.88k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (718:7): [True: 5.88k, False: 0]
  ------------------
  719|  5.88k|				&& !(flags & SC_ALGORITHM_ECDSA_HASHES & alg_info->flags)) {
  ------------------
  |  |  181|  5.88k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (719:8): [True: 5.88k, False: 0]
  ------------------
  720|  5.88k|			sc_log(ctx, "ECDSA using SC_ALGORITHM_ECDSA_RAW flags before 0x%8.8lx", flags);
  ------------------
  |  |   71|  5.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__
  |  |  ------------------
  ------------------
  721|  5.88k|				flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  174|  5.88k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  722|  5.88k|				flags &= ~SC_ALGORITHM_ECDSA_HASHES;
  ------------------
  |  |  181|  5.88k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|  5.88k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|  5.88k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|  5.88k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  723|  5.88k|		}
  724|  5.88k|	}
  725|       |
  726|  48.7k|	r = sc_get_encoding_flags(ctx, flags, alg_info->flags, &pad_flags, &sec_flags);
  727|  48.7k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  48.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (727:6): [True: 31.3k, False: 17.4k]
  ------------------
  728|  31.3k|		goto err;
  729|  31.3k|	}
  730|       |	/* senv now has flags card or driver will do */
  731|  17.4k|	senv.algorithm_flags = sec_flags;
  732|       |
  733|  17.4k|	sc_log(ctx, "DEE flags:0x%8.8lx alg_info->flags:0x%8.8lx pad:0x%8.8lx sec:0x%8.8lx",
  ------------------
  |  |   71|  17.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__
  |  |  ------------------
  ------------------
  734|  17.4k|		flags, alg_info->flags, pad_flags, sec_flags);
  735|       |
  736|       |	/* add the padding bytes (if necessary) */
  737|  17.4k|	if (pad_flags != 0) {
  ------------------
  |  Branch (737:6): [True: 6.43k, False: 10.9k]
  ------------------
  738|  6.43k|		size_t tmplen = buflen;
  739|       |
  740|       |		/* XXX Assuming RSA key here */
  741|  6.43k|		r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
  742|  6.43k|		    prkey->modulus_length, pMechanism);
  743|  6.43k|		LOG_TEST_GOTO_ERR(ctx, r, "Unable to add padding");
  ------------------
  |  |  184|  6.43k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  6.43k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  6.43k|	int _ret = (r); \
  |  |  |  |  178|  6.43k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 6.43k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|  6.43k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.43k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  6.43k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  6.43k|		goto err; \
  |  |  |  |  182|  6.43k|	} \
  |  |  |  |  183|  6.43k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  744|      0|		inlen = tmplen;
  745|      0|	}
  746|  10.9k|	else if ( senv.algorithm == SC_ALGORITHM_RSA &&
  ------------------
  |  |   69|  21.9k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (746:12): [True: 8.38k, False: 2.61k]
  ------------------
  747|  8.38k|	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  103|  8.38k|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
              	          (flags & SC_ALGORITHM_RSA_PADS) == SC_ALGORITHM_RSA_PAD_NONE) {
  ------------------
  |  |  104|  8.38k|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
  |  Branch (747:12): [True: 1.27k, False: 7.10k]
  ------------------
  748|       |		/* Add zero-padding if input is shorter than the modulus */
  749|  1.27k|		if (inlen < modlen) {
  ------------------
  |  Branch (749:7): [True: 885, False: 389]
  ------------------
  750|    885|			if (modlen > buflen) {
  ------------------
  |  Branch (750:8): [True: 0, False: 885]
  ------------------
  751|      0|				r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  752|      0|				goto err;
  753|      0|			}
  754|    885|			memmove(tmp+modlen-inlen, tmp, inlen);
  755|    885|			memset(tmp, 0, modlen-inlen);
  756|    885|		}
  757|  1.27k|		inlen = modlen;
  758|  1.27k|	}
  759|       |	/* PKCS#11 MECHANISMS V2.30: 6.3.1 EC Signatures
  760|       |	 * If the length of the hash value is larger than the bit length of n, only
  761|       |	 * the leftmost bits of the hash up to the length of n will be used. Any
  762|       |	 * truncation is done by the token.
  763|       |	 * But if card is going to do the hash, pass in all the data
  764|       |	 */
  765|  9.72k|	else if (senv.algorithm == SC_ALGORITHM_EC &&
  ------------------
  |  |   70|  19.4k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (765:11): [True: 2.61k, False: 7.10k]
  ------------------
  766|  2.61k|			(senv.algorithm_flags & SC_ALGORITHM_ECDSA_HASHES) == 0) {
  ------------------
  |  |  181|  2.61k|#define SC_ALGORITHM_ECDSA_HASHES		(SC_ALGORITHM_ECDSA_HASH_SHA1 | \
  |  |  ------------------
  |  |  |  |  176|  2.61k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  2.61k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  182|  2.61k|							SC_ALGORITHM_ECDSA_HASH_SHA224 | \
  |  |  ------------------
  |  |  |  |  177|  2.61k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  |  |  ------------------
  |  |  |  |  |  |  141|  2.61k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  183|  2.61k|							SC_ALGORITHM_ECDSA_HASH_SHA256 | \
  |  |  ------------------
  |  |  |  |  178|  2.61k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  |  |  ------------------
  |  |  |  |  |  |  138|  2.61k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|  2.61k|							SC_ALGORITHM_ECDSA_HASH_SHA384 | \
  |  |  ------------------
  |  |  |  |  179|  2.61k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|  2.61k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|  2.61k|							SC_ALGORITHM_ECDSA_HASH_SHA512)
  |  |  ------------------
  |  |  |  |  180|  2.61k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  |  |  ------------------
  |  |  |  |  |  |  140|  2.61k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (766:4): [True: 2.61k, False: 0]
  ------------------
  767|  2.61k|		inlen = MIN(inlen, BYTES4BITS(prkey->field_length));
  ------------------
  |  |   69|  2.61k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 2.44k, False: 168]
  |  |  ------------------
  ------------------
  768|  2.61k|	}
  769|       |
  770|       |
  771|  10.9k|	r = use_key(p15card, obj, &senv, sc_compute_signature, tmp, inlen,
  772|  10.9k|			out, outlen);
  773|  10.9k|	LOG_TEST_GOTO_ERR(ctx, r, "use_key() failed");
  ------------------
  |  |  184|  10.9k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  10.9k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  10.9k|	int _ret = (r); \
  |  |  |  |  178|  10.9k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 10.4k, False: 579]
  |  |  |  |  ------------------
  |  |  |  |  179|  10.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|  10.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  10.4k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  10.4k|		goto err; \
  |  |  |  |  182|  10.4k|	} \
  |  |  |  |  183|  10.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 579]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  774|       |
  775|       |	/* Some cards may return RSA signature as integer without leading zero bytes */
  776|       |	/* Already know outlen >= modlen and r >= 0 */
  777|    579|	if (obj->type == SC_PKCS15_TYPE_PRKEY_RSA && (unsigned)r < modlen) {
  ------------------
  |  |  419|  1.15k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (777:6): [True: 579, False: 0]
  |  Branch (777:47): [True: 500, False: 79]
  ------------------
  778|    500|		memmove(out + modlen - r, out, r);
  779|    500|		memset(out, 0, modlen - r);
  780|    500|		r = (int)modlen;
  781|    500|	}
  782|       |
  783|  48.7k|err:
  784|  48.7k|	sc_mem_secure_clear_free(buf, buflen);
  ------------------
  |  | 1580|  48.7k|#define sc_mem_secure_clear_free(ptr, len) do { \
  |  | 1581|  48.7k|	sc_mem_clear(ptr, len); \
  |  | 1582|  48.7k|	sc_mem_secure_free(ptr, len); \
  |  | 1583|  48.7k|} while (0);
  |  |  ------------------
  |  |  |  Branch (1583:10): [Folded, False: 48.7k]
  |  |  ------------------
  ------------------
  785|       |
  786|  48.7k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  48.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  48.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  48.7k|	int _ret = r; \
  |  |  |  |  155|  48.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 48.1k, False: 566]
  |  |  |  |  ------------------
  |  |  |  |  156|  48.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|  48.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 48.1k, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|  48.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  48.1k|	} 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|  48.7k|	return _ret; \
  |  |  |  |  163|  48.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  787|  48.7k|}
pkcs15-sec.c:format_senv:
  175|   328k|{
  176|   328k|	sc_context_t *ctx = p15card->card->ctx;
  177|   328k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
  178|   328k|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
  179|       |
  180|   328k|	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|   328k|	memcpy(senv_out->supported_algos, &p15card->tokeninfo->supported_algos, sizeof(senv_out->supported_algos));
  185|       |
  186|   328k|	if (!((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY || (obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_SKEY))
  ------------------
  |  |  416|   328k|#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|   656k|#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|   241k|#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|   241k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (186:8): [True: 87.0k, False: 241k]
  |  Branch (186:75): [True: 0, False: 241k]
  ------------------
  187|   328k|		LOG_TEST_RET(ctx, SC_ERROR_NOT_ALLOWED, "This is not a private or secret key");
  ------------------
  |  |  174|   241k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   241k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   241k|	int _ret = (r); \
  |  |  |  |  168|   241k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 241k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|   241k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|   241k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|   241k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|   241k|		return _ret; \
  |  |  |  |  172|   241k|	} \
  |  |  |  |  173|   241k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  188|       |
  189|       |	/* If the key is not native, we can't operate with it. */
  190|  87.0k|	if (!prkey->native)
  ------------------
  |  Branch (190:6): [True: 0, False: 87.0k]
  ------------------
  191|  87.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|  87.0k|	switch (obj->type) {
  194|  79.8k|		case SC_PKCS15_TYPE_PRKEY_RSA:
  ------------------
  |  |  419|  79.8k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  |  Branch (194:3): [True: 79.8k, False: 7.25k]
  ------------------
  195|  79.8k|			*alg_info_out = sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
  196|  79.8k|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (196:8): [True: 22.1k, False: 57.6k]
  ------------------
  197|  22.1k|				sc_log(ctx, "Card does not support RSA with key length %zu",
  ------------------
  |  |   71|  22.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  198|  22.1k|						prkey->modulus_length);
  199|  22.1k|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  22.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  22.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  22.1k|	int _ret = r; \
  |  |  |  |  155|  22.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 22.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  22.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|  22.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 22.1k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  22.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.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|  22.1k|	return _ret; \
  |  |  |  |  163|  22.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  200|  22.1k|			}
  201|  57.6k|			senv_out->algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   69|  57.6k|#define SC_ALGORITHM_RSA		0
  ------------------
  202|  57.6k|			senv_out->key_size_bits = prkey->modulus_length;
  203|  57.6k|			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: 87.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: 87.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: 87.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.25k|		case SC_PKCS15_TYPE_PRKEY_EC:
  ------------------
  |  |  421|  7.25k|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  |  Branch (238:3): [True: 7.25k, False: 79.8k]
  ------------------
  239|  7.25k|			*alg_info_out = sc_card_find_ec_alg(p15card->card, prkey->field_length, NULL);
  240|  7.25k|			if (*alg_info_out == NULL) {
  ------------------
  |  Branch (240:8): [True: 841, False: 6.41k]
  ------------------
  241|    841|				sc_log(ctx, "Card does not support EC with field_size %zu",
  ------------------
  |  |   71|    841|#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|    841|						prkey->field_length);
  243|    841|				LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    841|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    841|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    841|	int _ret = r; \
  |  |  |  |  155|    841|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 841, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    841|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    841|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 841, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    841|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    841|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    841|	return _ret; \
  |  |  |  |  163|    841|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|    841|			}
  245|  6.41k|			senv_out->algorithm = SC_ALGORITHM_EC;
  ------------------
  |  |   70|  6.41k|#define SC_ALGORITHM_EC		2
  ------------------
  246|  6.41k|			senv_out->key_size_bits = prkey->field_length;
  247|       |
  248|  6.41k|			senv_out->flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   56|  6.41k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  249|  6.41k|			senv_out->algorithm_ref = prkey->field_length;
  250|  6.41k|			break;
  251|      0|		case SC_PKCS15_TYPE_SKEY_GENERIC:
  ------------------
  |  |  433|      0|#define SC_PKCS15_TYPE_SKEY_GENERIC		0x301
  ------------------
  |  Branch (251:3): [True: 0, False: 87.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: 87.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|  87.0k|	}
  267|  64.1k|	senv_out->flags |= SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   60|  64.1k|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  268|       |
  269|       |	/* optional keyReference attribute (the default value is -1) */
  270|  64.1k|	if (prkey->key_reference >= 0) {
  ------------------
  |  Branch (270:6): [True: 63.9k, False: 166]
  ------------------
  271|  63.9k|		senv_out->key_ref_len = 1;
  272|  63.9k|		senv_out->key_ref[0] = prkey->key_reference & 0xFF;
  273|  63.9k|		senv_out->flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   58|  63.9k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  274|  63.9k|	}
  275|       |
  276|  64.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  64.1k|#define SC_SUCCESS				0
  ------------------
  277|  87.0k|}
pkcs15-sec.c:use_key:
  133|  16.1k|{
  134|  16.1k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  16.1k|#define SC_SUCCESS				0
  ------------------
  135|  16.1k|	int revalidated_cached_pin = 0;
  136|  16.1k|	sc_path_t path;
  137|  16.1k|	LOG_TEST_RET(p15card->card->ctx, get_file_path(obj, &path), "Failed to get key file path.");
  ------------------
  |  |  174|  16.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  16.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  16.1k|	int _ret = (r); \
  |  |  |  |  168|  16.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 16.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  138|       |
  139|  16.1k|	r = sc_lock(p15card->card);
  140|  16.1k|	LOG_TEST_RET(p15card->card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  16.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  16.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  16.1k|	int _ret = (r); \
  |  |  |  |  168|  16.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 16.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  141|       |
  142|  16.5k|	do {
  143|  16.5k|		if (path.len != 0 || path.aid.len != 0) {
  ------------------
  |  Branch (143:7): [True: 3.78k, False: 12.7k]
  |  Branch (143:24): [True: 388, False: 12.3k]
  ------------------
  144|  4.17k|			r = select_key_file(p15card, obj, senv);
  145|  4.17k|			if (r < 0) {
  ------------------
  |  Branch (145:8): [True: 2.51k, False: 1.66k]
  ------------------
  146|  2.51k|				sc_log(p15card->card->ctx,
  ------------------
  |  |   71|  2.51k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  147|  2.51k|						"Unable to select private key file");
  148|  2.51k|			}
  149|  4.17k|		}
  150|  16.5k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  16.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (150:7): [True: 14.0k, False: 2.51k]
  ------------------
  151|  14.0k|			r = sc_set_security_env(p15card->card, senv, 0);
  152|       |
  153|  16.5k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  16.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (153:7): [True: 9.61k, False: 6.90k]
  ------------------
  154|  9.61k|			r = card_command(p15card->card, in, inlen, out, outlen);
  155|       |
  156|  16.5k|		if (revalidated_cached_pin)
  ------------------
  |  Branch (156:7): [True: 345, False: 16.1k]
  ------------------
  157|       |			/* only re-validate once */
  158|    345|			break;
  159|  16.1k|		if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|  16.1k|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (159:7): [True: 483, False: 15.6k]
  ------------------
  160|    483|			r = sc_pkcs15_pincache_revalidate(p15card, obj);
  161|    483|			if (r < 0)
  ------------------
  |  Branch (161:8): [True: 138, False: 345]
  ------------------
  162|    138|				break;
  163|    345|			revalidated_cached_pin = 1;
  164|    345|		}
  165|  16.1k|	} while (revalidated_cached_pin);
  ------------------
  |  Branch (165:11): [True: 345, False: 15.6k]
  ------------------
  166|       |
  167|  16.1k|	sc_unlock(p15card->card);
  168|       |
  169|  16.1k|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|  16.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.1k|	int _ret = r; \
  |  |  |  |  155|  16.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 15.5k, False: 667]
  |  |  |  |  ------------------
  |  |  |  |  156|  15.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  15.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 15.1k, False: 378]
  |  |  |  |  ------------------
  |  |  |  |  157|  15.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  15.5k|	} else { \
  |  |  |  |  159|    667|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    667|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    667|	} \
  |  |  |  |  162|  16.1k|	return _ret; \
  |  |  |  |  163|  16.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  170|  16.1k|}
pkcs15-sec.c:get_file_path:
   57|  20.3k|{
   58|  20.3k|	if (!path)
  ------------------
  |  Branch (58:6): [True: 0, False: 20.3k]
  ------------------
   59|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
   60|       |
   61|  20.3k|	const struct sc_pkcs15_prkey_info *prkey = (const struct sc_pkcs15_prkey_info *) obj->data;
   62|  20.3k|	const struct sc_pkcs15_skey_info *skey = (const struct sc_pkcs15_skey_info *) obj->data;
   63|       |
   64|  20.3k|	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  416|  20.3k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
              	if ((obj->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY) {
  ------------------
  |  |  418|  20.3k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (64:6): [True: 20.3k, False: 0]
  ------------------
   65|  20.3k|		*path = prkey->path;
   66|  20.3k|	}
   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|  20.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  20.3k|#define SC_SUCCESS				0
  ------------------
   74|  20.3k|}
pkcs15-sec.c:select_key_file:
   80|  4.17k|{
   81|  4.17k|	sc_context_t *ctx = p15card->card->ctx;
   82|  4.17k|	sc_path_t orig_path;
   83|  4.17k|	sc_path_t path, file_id;
   84|  4.17k|	int r;
   85|       |
   86|  4.17k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  4.17k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  4.17k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  4.17k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  4.17k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 4.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   87|       |
   88|  4.17k|	LOG_TEST_RET(ctx, get_file_path(key, &orig_path), "Could not get key file path.");
  ------------------
  |  |  174|  4.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.17k|	int _ret = (r); \
  |  |  |  |  168|  4.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 4.17k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   89|  4.17k|	memset(&path, 0, sizeof(sc_path_t));
   90|  4.17k|	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|  4.17k|	if (!orig_path.len && orig_path.aid.len) {
  ------------------
  |  Branch (96:6): [True: 388, False: 3.78k]
  |  Branch (96:24): [True: 388, False: 0]
  ------------------
   97|       |		/* Private key is a SDO allocated in application DF */
   98|    388|		path = orig_path;
   99|    388|	}
  100|  3.78k|	else if (orig_path.len == 2 && p15card->file_app != NULL) {
  ------------------
  |  Branch (100:11): [True: 0, False: 3.78k]
  |  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.78k|	else if (orig_path.len > 2) {
  ------------------
  |  Branch (108:11): [True: 3.78k, False: 0]
  ------------------
  109|  3.78k|		path = orig_path;
  110|  3.78k|		memcpy(file_id.value, orig_path.value + orig_path.len - 2, 2);
  111|  3.78k|		file_id.len = 2;
  112|  3.78k|		file_id.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  3.78k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  113|  3.78k|		senv->file_ref = file_id;
  114|  3.78k|		senv->flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   57|  3.78k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  115|  3.78k|	}
  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|  4.17k|	r = sc_select_file(p15card->card, &path, NULL);
  121|  4.17k|	LOG_TEST_RET(ctx, r, "sc_select_file() failed");
  ------------------
  |  |  174|  4.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  4.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  4.17k|	int _ret = (r); \
  |  |  |  |  168|  4.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.51k, False: 1.66k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.51k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.51k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.51k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.51k|		return _ret; \
  |  |  |  |  172|  2.51k|	} \
  |  |  |  |  173|  4.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.66k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  122|       |
  123|  1.66k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.66k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|  1.66k|}

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

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

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

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

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

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

sc_pkcs15_parse_tokeninfo:
  145|    938|{
  146|    938|	int r;
  147|    938|	size_t ii;
  148|    938|	u8 serial[128];
  149|    938|	size_t serial_len = sizeof(serial);
  150|    938|	u8 mnfid[SC_PKCS15_MAX_LABEL_SIZE];
  151|    938|	size_t mnfid_len  = sizeof(mnfid) - 1;
  152|    938|	u8 label[SC_PKCS15_MAX_LABEL_SIZE];
  153|    938|	size_t label_len = sizeof(label) - 1;
  154|    938|	u8 last_update[32], profile_indication[SC_PKCS15_MAX_LABEL_SIZE];
  155|    938|	size_t lupdate_len = sizeof(last_update) - 1, pi_len = sizeof(profile_indication) - 1;
  156|    938|	size_t flags_len   = sizeof(ti->flags);
  157|    938|	u8 preferred_language[64];
  158|    938|	size_t lang_length = sizeof(preferred_language) - 1;
  159|    938|	struct sc_asn1_entry asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1],
  160|    938|			asn1_algo_infos[SC_MAX_SUPPORTED_ALGORITHMS][7],
  161|    938|			asn1_algo_infos_parameters[SC_MAX_SUPPORTED_ALGORITHMS][3];
  162|    938|	size_t reference_len = sizeof(ti->supported_algos[0].reference);
  163|    938|	size_t mechanism_len = sizeof(ti->supported_algos[0].mechanism);
  164|    938|	size_t parameter_len = sizeof(ti->supported_algos[0].parameters);
  165|    938|	size_t operations_len = sizeof(ti->supported_algos[0].operations);
  166|    938|	size_t algo_ref_len = sizeof(ti->supported_algos[0].algo_ref);
  167|       |
  168|    938|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  169|    938|	struct sc_asn1_entry asn1_profile_indication[C_ASN1_PROFILE_INDICATION_SIZE];
  170|    938|	struct sc_asn1_entry asn1_toki_attrs[C_ASN1_TOKI_ATTRS_SIZE], asn1_tokeninfo[3], asn1_twlabel[3];
  171|       |
  172|    938|	memset(last_update, 0, sizeof(last_update));
  173|    938|	memset(label, 0, sizeof(label));
  174|    938|	memset(profile_indication, 0, sizeof(profile_indication));
  175|    938|	memset(mnfid, 0, sizeof(mnfid));
  176|       |
  177|    938|	sc_copy_asn1_entry(c_asn1_twlabel, asn1_twlabel);
  178|    938|	sc_copy_asn1_entry(c_asn1_toki_attrs, asn1_toki_attrs);
  179|    938|	sc_copy_asn1_entry(c_asn1_tokeninfo, asn1_tokeninfo);
  180|    938|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  181|    938|	sc_format_asn1_entry(asn1_twlabel, label, &label_len, 0);
  182|    938|	sc_copy_asn1_entry(c_asn1_profile_indication, asn1_profile_indication);
  183|       |
  184|  15.9k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++) {
  ------------------
  |  |   61|  15.9k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (184:13): [True: 15.0k, False: 938]
  ------------------
  185|  15.0k|		sc_copy_asn1_entry(c_asn1_algorithm_info, asn1_algo_infos[ii]);
  186|  15.0k|		sc_copy_asn1_entry(c_asn1_algorithm_info_parameters,
  187|  15.0k|			asn1_algo_infos_parameters[ii]);
  188|  15.0k|	}
  189|    938|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  190|       |
  191|  15.9k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++)   {
  ------------------
  |  |   61|  15.9k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (191:13): [True: 15.0k, False: 938]
  ------------------
  192|  15.0k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 0, &ti->supported_algos[ii].reference, &reference_len, 0);
  193|  15.0k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 0);
  194|  15.0k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
  195|  15.0k|			asn1_algo_infos_parameters[ii], NULL, 0);
  196|  15.0k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
  197|  15.0k|			NULL, NULL, 0);
  198|  15.0k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
  199|  15.0k|			&ti->supported_algos[ii].parameters, &parameter_len, 0);
  200|  15.0k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 3, &ti->supported_algos[ii].operations, &operations_len, 0);
  201|  15.0k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 4, &ti->supported_algos[ii].algo_id, NULL, 1);
  202|  15.0k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 5, &ti->supported_algos[ii].algo_ref, &algo_ref_len, 0);
  203|  15.0k|		sc_format_asn1_entry(asn1_supported_algorithms + ii, asn1_algo_infos[ii], NULL, 0);
  204|  15.0k|	}
  205|       |
  206|    938|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  207|    938|	sc_format_asn1_entry(asn1_last_update + 1, &ti->last_update.path, NULL, 0);
  208|       |
  209|    938|	sc_format_asn1_entry(asn1_profile_indication + 0, &ti->profile_indication.oid, NULL, 0);
  210|    938|	sc_format_asn1_entry(asn1_profile_indication + 1, profile_indication, &pi_len, 0);
  211|       |
  212|    938|	sc_format_asn1_entry(asn1_toki_attrs + 0, &ti->version, NULL, 0);
  213|    938|	sc_format_asn1_entry(asn1_toki_attrs + 1, serial, &serial_len, 0);
  214|    938|	sc_format_asn1_entry(asn1_toki_attrs + 2, mnfid, &mnfid_len, 0);
  215|    938|	sc_format_asn1_entry(asn1_toki_attrs + 3, label, &label_len, 0);
  216|    938|	sc_format_asn1_entry(asn1_toki_attrs + 4, asn1_twlabel, NULL, 0);
  217|    938|	sc_format_asn1_entry(asn1_toki_attrs + 5, &ti->flags, &flags_len, 0);
  218|    938|	sc_format_asn1_entry(asn1_toki_attrs + 6, &ti->seInfo, &ti->num_seInfo, 0);
  219|    938|	sc_format_asn1_entry(asn1_toki_attrs + 7, NULL, NULL, 0);
  220|    938|	sc_format_asn1_entry(asn1_toki_attrs + 8, asn1_supported_algorithms, NULL, 0);
  221|    938|	sc_format_asn1_entry(asn1_toki_attrs + 9, NULL, NULL, 0);
  222|    938|	sc_format_asn1_entry(asn1_toki_attrs + 10, NULL, NULL, 0);
  223|    938|	sc_format_asn1_entry(asn1_toki_attrs + 11, asn1_last_update, NULL, 0);
  224|    938|	sc_format_asn1_entry(asn1_toki_attrs + 12, preferred_language, &lang_length, 0);
  225|    938|	sc_format_asn1_entry(asn1_toki_attrs + 13, asn1_profile_indication, NULL, 0);
  226|    938|	sc_format_asn1_entry(asn1_tokeninfo, asn1_toki_attrs, NULL, 0);
  227|       |
  228|    938|	r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
  229|    938|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    938|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:6): [True: 483, False: 455]
  ------------------
  230|       |		/* The decoding could have allocated something we need to free */
  231|    483|		sc_pkcs15_clear_tokeninfo(ti);
  232|    483|		LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
  ------------------
  |  |  174|    483|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    483|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    483|	int _ret = (r); \
  |  |  |  |  168|    483|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 483, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    483|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    483|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    483|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    483|		return _ret; \
  |  |  |  |  172|    483|	} \
  |  |  |  |  173|    483|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|    483|	}
  234|       |
  235|    455|	if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0)   {
  ------------------
  |  |  171|    910|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (235:6): [True: 270, False: 185]
  |  Branch (235:52): [True: 259, False: 11]
  ------------------
  236|    259|		free(ti->serial_number);
  237|    259|		ti->serial_number = malloc(serial_len * 2 + 1);
  238|    259|		if (ti->serial_number == NULL)
  ------------------
  |  Branch (238:7): [True: 0, False: 259]
  ------------------
  239|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  240|    259|		sc_bin_to_hex(serial, serial_len, ti->serial_number, serial_len * 2 + 1, 0);
  241|    259|		sc_log(ctx, "TokenInfo.serialNunmber '%s'", ti->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  242|    259|	}
  243|       |
  244|    455|	if (ti->manufacturer_id == NULL) {
  ------------------
  |  Branch (244:6): [True: 455, False: 0]
  ------------------
  245|    455|		if (asn1_toki_attrs[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  171|    455|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (245:7): [True: 105, False: 350]
  ------------------
  246|    105|			ti->manufacturer_id = strdup((char *) mnfid);
  247|    350|		else
  248|    350|			ti->manufacturer_id = strdup("(unknown)");
  249|    455|		if (ti->manufacturer_id == NULL)
  ------------------
  |  Branch (249:7): [True: 0, False: 455]
  ------------------
  250|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  251|    455|	}
  252|    455|	if (ti->label == NULL) {
  ------------------
  |  Branch (252:6): [True: 455, False: 0]
  ------------------
  253|    455|		if (asn1_toki_attrs[3].flags & SC_ASN1_PRESENT ||
  ------------------
  |  |  171|    910|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (253:7): [True: 7, False: 448]
  ------------------
  254|    448|		    asn1_toki_attrs[4].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  171|    448|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (254:7): [True: 0, False: 448]
  ------------------
  255|      7|			ti->label = strdup((char *) label);
  256|    448|		else
  257|    448|			ti->label = strdup("(unknown)");
  258|    455|		if (ti->label == NULL)
  ------------------
  |  Branch (258:7): [True: 0, False: 455]
  ------------------
  259|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  260|    455|	}
  261|    455|	if (asn1_toki_attrs[11].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|    455|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (261:6): [True: 172, False: 283]
  ------------------
  262|    172|		if (asn1_last_update[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|    172|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (262:7): [True: 38, False: 134]
  ------------------
  263|     38|			sc_log(ctx, "LastUpdate.generalizedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  264|     38|			ti->last_update.gtime = strdup((char *)last_update);
  265|     38|			if (ti->last_update.gtime == NULL)
  ------------------
  |  Branch (265:8): [True: 0, False: 38]
  ------------------
  266|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  267|     38|		}
  268|    134|		else if (asn1_last_update[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  171|    134|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (268:12): [True: 99, False: 35]
  ------------------
  269|     99|			sc_log(ctx, "LastUpdate.referencedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  270|     99|		}
  271|    172|	}
  272|    455|	if (asn1_toki_attrs[12].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|    455|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:6): [True: 5, False: 450]
  ------------------
  273|      5|		preferred_language[lang_length] = 0;
  274|      5|		ti->preferred_language = strdup((char *)preferred_language);
  275|      5|		if (ti->preferred_language == NULL)
  ------------------
  |  Branch (275:7): [True: 0, False: 5]
  ------------------
  276|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  277|      5|	}
  278|       |
  279|    455|	sc_init_oid(&ti->profile_indication.oid);
  280|    455|	if (asn1_toki_attrs[13].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|    455|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (280:6): [True: 106, False: 349]
  ------------------
  281|    106|		if (asn1_profile_indication[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|    106|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (281:7): [True: 3, False: 103]
  ------------------
  282|      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__
  |  |  ------------------
  ------------------
  283|      3|		}
  284|    103|		else if (asn1_profile_indication[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  171|    103|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (284:12): [True: 100, False: 3]
  ------------------
  285|    100|			sc_log(ctx, "ProfileIndication.name present");
  ------------------
  |  |   71|    100|#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|    100|			ti->profile_indication.name = strdup((char *)profile_indication);
  287|    100|			if (ti->profile_indication.name == NULL)
  ------------------
  |  Branch (287:8): [True: 0, False: 100]
  ------------------
  288|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  289|    100|		}
  290|    106|	}
  291|       |
  292|    455|	sc_log(ctx, "LastUpdate.path '%s'", sc_print_path(&ti->last_update.path));
  ------------------
  |  |   71|    455|#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|    455|	sc_log(ctx, "ProfileIndication.name '%s'",  ti->profile_indication.name);
  ------------------
  |  |   71|    455|#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|    455|	return SC_SUCCESS;
  ------------------
  |  |   28|    455|#define SC_SUCCESS				0
  ------------------
  295|    455|}
sc_pkcs15_get_lastupdate:
  541|  3.80k|{
  542|  3.80k|	struct sc_context *ctx  = p15card->card->ctx;
  543|  3.80k|	struct sc_file *file = NULL;
  544|  3.80k|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  545|  3.80k|	unsigned char *content, last_update[32] = {0};
  546|  3.80k|	size_t lupdate_len = sizeof(last_update) - 1;
  547|  3.80k|	int r, content_len;
  548|  3.80k|	size_t size;
  549|       |
  550|  3.80k|	if (p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (550:6): [True: 334, False: 3.46k]
  ------------------
  551|    334|		goto done;
  552|       |
  553|  3.46k|	if (!p15card->tokeninfo->last_update.path.len)
  ------------------
  |  Branch (553:6): [True: 2.79k, False: 671]
  ------------------
  554|  2.79k|		return NULL;
  555|       |
  556|    671|	r = sc_select_file(p15card->card, &p15card->tokeninfo->last_update.path, &file);
  557|    671|	if (r < 0)
  ------------------
  |  Branch (557:6): [True: 583, False: 88]
  ------------------
  558|    583|		return NULL;
  559|       |
  560|     88|	size = file->size ? file->size : 1024;
  ------------------
  |  Branch (560:9): [True: 70, False: 18]
  ------------------
  561|     88|	sc_file_free(file);
  562|       |
  563|     88|	content = calloc(1, size);
  564|     88|	if (!content)
  ------------------
  |  Branch (564:6): [True: 0, False: 88]
  ------------------
  565|      0|		return NULL;
  566|       |
  567|     88|	r = sc_read_binary(p15card->card, 0, content, size, 0);
  568|     88|	if (r < 0) {
  ------------------
  |  Branch (568:6): [True: 36, False: 52]
  ------------------
  569|     36|		free(content);
  570|     36|		return NULL;
  571|     36|	}
  572|     52|	content_len = r;
  573|       |
  574|     52|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  575|     52|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  576|       |
  577|     52|	r = sc_asn1_decode(ctx, asn1_last_update, content, content_len, NULL, NULL);
  578|     52|	free(content);
  579|     52|	if (r < 0)
  ------------------
  |  Branch (579:6): [True: 24, False: 28]
  ------------------
  580|     24|		return NULL;
  581|       |
  582|     28|	if (asn1_last_update[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|     28|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (582:6): [True: 2, False: 26]
  ------------------
  583|      2|		p15card->tokeninfo->last_update.gtime = strdup((char *)last_update);
  584|      2|		if (!p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (584:7): [True: 0, False: 2]
  ------------------
  585|      0|			return NULL;
  586|      2|	}
  587|    362|done:
  588|    362|	sc_log(ctx, "lastUpdate.gtime '%s'", p15card->tokeninfo->last_update.gtime);
  ------------------
  |  |   71|    362|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  589|    362|	return p15card->tokeninfo->last_update.gtime;
  590|     28|}
sc_pkcs15_card_new:
  719|  13.0k|{
  720|  13.0k|	struct sc_pkcs15_card *p15card;
  721|       |
  722|  13.0k|	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
  723|  13.0k|	if (p15card == NULL)
  ------------------
  |  Branch (723:6): [True: 0, False: 13.0k]
  ------------------
  724|      0|		return NULL;
  725|       |
  726|  13.0k|	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  727|  13.0k|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (727:6): [True: 0, False: 13.0k]
  ------------------
  728|      0|		free(p15card);
  729|      0|		return NULL;
  730|      0|	}
  731|       |
  732|  13.0k|	p15card->magic = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  13.0k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  733|  13.0k|	return p15card;
  734|  13.0k|}
sc_pkcs15_tokeninfo_new:
  739|  9.14k|{
  740|  9.14k|	struct sc_pkcs15_tokeninfo *tokeninfo;
  741|       |
  742|  9.14k|	tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  743|  9.14k|	if (tokeninfo == NULL) {
  ------------------
  |  Branch (743:6): [True: 0, False: 9.14k]
  ------------------
  744|      0|		return NULL;
  745|      0|	}
  746|       |
  747|  9.14k|	sc_init_oid(&tokeninfo->profile_indication.oid);
  748|       |
  749|  9.14k|	return tokeninfo;
  750|  9.14k|}
sc_pkcs15_free_tokeninfo:
  781|  23.6k|{
  782|  23.6k|	if (!tokeninfo)
  ------------------
  |  Branch (782:6): [True: 1.41k, False: 22.1k]
  ------------------
  783|  1.41k|		return;
  784|       |
  785|  22.1k|	sc_pkcs15_clear_tokeninfo(tokeninfo);
  786|  22.1k|	free(tokeninfo);
  787|  22.1k|}
sc_pkcs15_free_app:
  791|  41.3k|{
  792|  41.3k|	if (p15card && p15card->app) {
  ------------------
  |  Branch (792:6): [True: 41.3k, False: 0]
  |  Branch (792:17): [True: 720, False: 40.6k]
  ------------------
  793|    720|		free(p15card->app->label);
  794|    720|		free(p15card->app->ddo.value);
  795|    720|		free(p15card->app);
  796|       |		p15card->app = NULL;
  797|    720|	}
  798|  41.3k|}
sc_pkcs15_card_free:
  803|  13.0k|{
  804|  13.0k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC)
  ------------------
  |  |  519|  13.0k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (804:6): [True: 0, False: 13.0k]
  |  Branch (804:25): [True: 0, False: 13.0k]
  ------------------
  805|      0|		return;
  806|       |
  807|  13.0k|	if (p15card->ops.clear)
  ------------------
  |  Branch (807:6): [True: 837, False: 12.2k]
  ------------------
  808|    837|		p15card->ops.clear(p15card);
  809|       |
  810|       |	/* For more complicated MD data a dedicated release procedure
  811|       |	 * has to be implemented. */
  812|  13.0k|	if (p15card->md_data)
  ------------------
  |  Branch (812:6): [True: 0, False: 13.0k]
  ------------------
  813|      0|		free(p15card->md_data);
  814|       |
  815|  13.0k|	sc_pkcs15_free_app(p15card);
  816|  13.0k|	sc_pkcs15_remove_objects(p15card);
  817|  13.0k|	sc_pkcs15_remove_dfs(p15card);
  818|  13.0k|	sc_pkcs15_free_unusedspace(p15card);
  819|  13.0k|	p15card->unusedspace_read = 0;
  820|       |
  821|  13.0k|	sc_file_free(p15card->file_app);
  822|  13.0k|	sc_file_free(p15card->file_tokeninfo);
  823|  13.0k|	sc_file_free(p15card->file_odf);
  824|  13.0k|	sc_file_free(p15card->file_unusedspace);
  825|       |
  826|  13.0k|	p15card->magic = 0;
  827|  13.0k|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  828|  13.0k|	sc_pkcs15_free_app(p15card);
  829|  13.0k|	free(p15card);
  830|  13.0k|}
sc_pkcs15_card_clear:
  835|  14.8k|{
  836|  14.8k|	if (p15card == NULL)
  ------------------
  |  Branch (836:6): [True: 0, False: 14.8k]
  ------------------
  837|      0|		return;
  838|       |
  839|  14.8k|	if (p15card->ops.clear)
  ------------------
  |  Branch (839:6): [True: 683, False: 14.1k]
  ------------------
  840|    683|		p15card->ops.clear(p15card);
  841|       |
  842|  14.8k|	p15card->flags = 0;
  843|  14.8k|	p15card->tokeninfo->version = 0;
  844|  14.8k|	p15card->tokeninfo->flags   = 0;
  845|       |
  846|  14.8k|	sc_pkcs15_remove_objects(p15card);
  847|  14.8k|	sc_pkcs15_remove_dfs(p15card);
  848|       |
  849|  14.8k|	p15card->df_list = NULL;
  850|  14.8k|	sc_file_free(p15card->file_app);
  851|  14.8k|	p15card->file_app = NULL;
  852|  14.8k|	sc_file_free(p15card->file_tokeninfo);
  853|  14.8k|	p15card->file_tokeninfo = NULL;
  854|  14.8k|	sc_file_free(p15card->file_odf);
  855|  14.8k|	p15card->file_odf = NULL;
  856|  14.8k|	sc_file_free(p15card->file_unusedspace);
  857|  14.8k|	p15card->file_unusedspace = NULL;
  858|       |
  859|  14.8k|	free(p15card->tokeninfo->label);
  860|  14.8k|	p15card->tokeninfo->label = NULL;
  861|  14.8k|	free(p15card->tokeninfo->serial_number);
  862|  14.8k|	p15card->tokeninfo->serial_number = NULL;
  863|  14.8k|	free(p15card->tokeninfo->manufacturer_id);
  864|  14.8k|	p15card->tokeninfo->manufacturer_id = NULL;
  865|  14.8k|	free(p15card->tokeninfo->last_update.gtime);
  866|  14.8k|	p15card->tokeninfo->last_update.gtime = NULL;
  867|  14.8k|	free(p15card->tokeninfo->preferred_language);
  868|  14.8k|	p15card->tokeninfo->preferred_language = NULL;
  869|  14.8k|	free(p15card->tokeninfo->profile_indication.name);
  870|  14.8k|	p15card->tokeninfo->profile_indication.name = NULL;
  871|  14.8k|	if (p15card->tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (871:6): [True: 4, False: 14.8k]
  ------------------
  872|      4|		size_t i;
  873|     10|		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (873:15): [True: 6, False: 4]
  ------------------
  874|      6|			free(p15card->tokeninfo->seInfo[i]);
  875|      4|		free(p15card->tokeninfo->seInfo);
  876|      4|		p15card->tokeninfo->seInfo     = NULL;
  877|      4|		p15card->tokeninfo->num_seInfo = 0;
  878|      4|	}
  879|       |
  880|  14.8k|	sc_pkcs15_free_app(p15card);
  881|  14.8k|}
sc_find_app:
  886|  12.3k|{
  887|  12.3k|	int ii;
  888|       |
  889|  12.3k|	if (card->app_count <= 0)
  ------------------
  |  Branch (889:6): [True: 11.9k, False: 422]
  ------------------
  890|  11.9k|		return NULL;
  891|       |
  892|    422|	if (!aid || !aid->len)
  ------------------
  |  Branch (892:6): [True: 422, False: 0]
  |  Branch (892:14): [True: 0, False: 0]
  ------------------
  893|    422|		return card->app[0];
  894|       |
  895|      0|	for (ii=0; ii < card->app_count; ii++) {
  ------------------
  |  Branch (895:13): [True: 0, False: 0]
  ------------------
  896|      0|		if (card->app[ii]->aid.len != aid->len)
  ------------------
  |  Branch (896:7): [True: 0, False: 0]
  ------------------
  897|      0|			continue;
  898|      0|		if (memcmp(card->app[ii]->aid.value, aid->value, aid->len))
  ------------------
  |  Branch (898:7): [True: 0, False: 0]
  ------------------
  899|      0|			continue;
  900|      0|		return card->app[ii];
  901|      0|	}
  902|      0|	return NULL;
  903|      0|}
sc_pkcs15_bind_internal_odf:
  983|    586|{
  984|    586|	struct sc_path tmppath;
  985|    586|	struct sc_card    *card = p15card->card;
  986|    586|	struct sc_context *ctx = card->ctx;
  987|    586|	struct sc_pkcs15_df *df;
  988|    586|	unsigned char *buf = NULL;
  989|    586|	size_t len;
  990|    586|	int    err, ok = 0;
  991|       |
  992|    586|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    586|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    586|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    586|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    586|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 586]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  993|    586|	if (p15card->file_odf == NULL) {
  ------------------
  |  Branch (993:6): [True: 586, False: 0]
  ------------------
  994|       |		/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
  995|    586|		sc_format_path("5031", &tmppath);
  996|    586|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
  997|    586|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    586|#define SC_SUCCESS				0
  ------------------
  |  Branch (997:7): [True: 0, False: 586]
  ------------------
  998|      0|			sc_log(ctx, "Cannot make absolute path to EF(ODF); error:%i", err);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  999|      0|			goto end;
 1000|      0|		}
 1001|    586|		sc_log(ctx, "absolute path to EF(ODF) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|    586|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1002|    586|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1003|    586|	}
 1004|      0|	else {
 1005|      0|		tmppath = p15card->file_odf->path;
 1006|      0|		sc_file_free(p15card->file_odf);
 1007|      0|		p15card->file_odf = NULL;
 1008|      0|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1009|      0|	}
 1010|       |
 1011|    586|	if (err != SC_SUCCESS) {
  ------------------
  |  |   28|    586|#define SC_SUCCESS				0
  ------------------
  |  Branch (1011:6): [True: 344, False: 242]
  ------------------
 1012|    344|		sc_log(ctx, "EF(ODF) not found in '%s'", sc_print_path(&tmppath));
  ------------------
  |  |   71|    344|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1013|    344|		goto end;
 1014|    344|	}
 1015|       |
 1016|    242|	len = p15card->file_odf->size;
 1017|    242|	if (!len) {
  ------------------
  |  Branch (1017:6): [True: 108, False: 134]
  ------------------
 1018|    108|		sc_log(ctx, "EF(ODF) is empty");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1019|    108|		goto end;
 1020|    108|	}
 1021|    134|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    134|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1021:6): [True: 31, False: 103]
  ------------------
 1022|     31|		sc_log(ctx, "EF(ODF) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1023|     31|		goto end;
 1024|     31|	}
 1025|    103|	buf = malloc(len);
 1026|    103|	if(buf == NULL) {
  ------------------
  |  Branch (1026:5): [True: 0, False: 103]
  ------------------
 1027|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1028|      0|		goto end;
 1029|      0|	}
 1030|       |
 1031|    103|	err = -1; /* file state: not in cache */
 1032|    103|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1032:6): [True: 60, False: 43]
  ------------------
 1033|     60|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1034|     60|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|     60|#define SC_SUCCESS				0
  ------------------
  |  Branch (1034:7): [True: 2, False: 58]
  ------------------
 1035|      2|			err = (int)len;
 1036|     60|	}
 1037|    103|	if (err < 0) {
  ------------------
  |  Branch (1037:6): [True: 101, False: 2]
  ------------------
 1038|    101|		err = sc_read_binary(card, 0, buf, len, 0);
 1039|    101|		if (err < 2) {
  ------------------
  |  Branch (1039:7): [True: 69, False: 32]
  ------------------
 1040|     69|			if (err < 0) {
  ------------------
  |  Branch (1040:8): [True: 57, False: 12]
  ------------------
 1041|     57|				sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1042|     57|			} else {
 1043|     12|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  132|     12|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1044|     12|				sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1045|     12|			}
 1046|     69|			goto end;
 1047|     69|		}
 1048|       |		/* sc_read_binary may return less than requested */
 1049|     32|		len = err;
 1050|       |
 1051|     32|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1051:7): [True: 22, False: 10]
  ------------------
 1052|     22|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1053|     22|		}
 1054|     32|	}
 1055|       |
 1056|     34|	if (parse_odf(buf, len, p15card)) {
  ------------------
  |  Branch (1056:6): [True: 18, False: 16]
  ------------------
 1057|     18|		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  132|     18|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1058|     18|		sc_log(ctx, "Unable to parse ODF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1059|     18|		goto end;
 1060|     18|	}
 1061|     16|	free(buf);
 1062|     16|	buf = NULL;
 1063|       |
 1064|     16|	sc_log(ctx, "The following DFs were found:");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1065|    101|	for (df = p15card->df_list; df; df = df->next)
  ------------------
  |  Branch (1065:30): [True: 85, False: 16]
  ------------------
 1066|     85|		sc_log(ctx, "  DF type %u, path %s, index %u, count %d", df->type,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1067|     16|				sc_print_path(&df->path), df->path.index, df->path.count);
 1068|       |
 1069|     16|	ok = 1;
 1070|    586|end:
 1071|    586|	if (buf != NULL)
  ------------------
  |  Branch (1071:6): [True: 87, False: 499]
  ------------------
 1072|     87|		free(buf);
 1073|    586|	if (!ok) {
  ------------------
  |  Branch (1073:6): [True: 570, False: 16]
  ------------------
 1074|    570|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|    570|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    570|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    570|	int _ret = r; \
  |  |  |  |  155|    570|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 570, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    570|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    431|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 431, False: 139]
  |  |  |  |  ------------------
  |  |  |  |  157|    570|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    570|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    570|	return _ret; \
  |  |  |  |  163|    570|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1075|    570|	}
 1076|       |
 1077|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1078|     16|}
sc_pkcs15_bind_internal_tokeninfo:
 1082|  12.0k|{
 1083|  12.0k|	struct sc_path tmppath;
 1084|  12.0k|	struct sc_card *card = p15card->card;
 1085|  12.0k|	struct sc_context *ctx = card->ctx;
 1086|  12.0k|	struct sc_pkcs15_tokeninfo tokeninfo;
 1087|  12.0k|	unsigned char *buf = NULL;
 1088|  12.0k|	size_t len;
 1089|  12.0k|	int err, ok = 0;
 1090|       |
 1091|  12.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1092|       |
 1093|  12.0k|	if (p15card->file_tokeninfo == NULL) {
  ------------------
  |  Branch (1093:6): [True: 12.0k, False: 6]
  ------------------
 1094|  12.0k|		sc_format_path("5032", &tmppath);
 1095|  12.0k|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1096|  12.0k|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|  12.0k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1096:7): [True: 3, False: 12.0k]
  ------------------
 1097|      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__
  |  |  ------------------
  ------------------
 1098|      3|			goto end;
 1099|      3|		}
 1100|  12.0k|		sc_log(ctx, "absolute path to EF(TokenInfo) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|  12.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1101|  12.0k|	}
 1102|      6|	else {
 1103|      6|		tmppath = p15card->file_tokeninfo->path;
 1104|      6|		sc_file_free(p15card->file_tokeninfo);
 1105|      6|		p15card->file_tokeninfo = NULL;
 1106|      6|	}
 1107|       |
 1108|  12.0k|	err = sc_select_file(card, &tmppath, &p15card->file_tokeninfo);
 1109|  12.0k|	if (err)   {
  ------------------
  |  Branch (1109:6): [True: 10.9k, False: 1.06k]
  ------------------
 1110|  10.9k|		sc_log(ctx, "cannot select EF(TokenInfo) file: %s", sc_strerror(err));
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
 1111|  10.9k|		goto end;
 1112|  10.9k|	}
 1113|       |
 1114|  1.06k|	len = p15card->file_tokeninfo->size;
 1115|  1.06k|	if (!len) {
  ------------------
  |  Branch (1115:6): [True: 436, False: 626]
  ------------------
 1116|    436|		sc_log(ctx, "EF(TokenInfo) is empty");
  ------------------
  |  |   71|    436|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1117|    436|		goto end;
 1118|    436|	}
 1119|    626|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  220|    626|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1119:6): [True: 65, False: 561]
  ------------------
 1120|     65|		sc_log(ctx, "EF(TokenInfo) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1121|     65|		goto end;
 1122|     65|	}
 1123|    561|	buf = malloc(len);
 1124|    561|	if(buf == NULL) {
  ------------------
  |  Branch (1124:5): [True: 0, False: 561]
  ------------------
 1125|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1126|      0|		goto end;
 1127|      0|	}
 1128|       |
 1129|    561|	err = -1; /* file state: not in cache */
 1130|    561|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1130:6): [True: 199, False: 362]
  ------------------
 1131|    199|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1132|    199|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    199|#define SC_SUCCESS				0
  ------------------
  |  Branch (1132:7): [True: 1, False: 198]
  ------------------
 1133|      1|			err = (int)len;
 1134|    199|	}
 1135|    561|	if (err < 0) {
  ------------------
  |  Branch (1135:6): [True: 560, False: 1]
  ------------------
 1136|    560|		err = sc_read_binary(card, 0, buf, len, 0);
 1137|    560|		if (err <= 2) {
  ------------------
  |  Branch (1137:7): [True: 342, False: 218]
  ------------------
 1138|    342|			if (err < 0)   {
  ------------------
  |  Branch (1138:8): [True: 301, False: 41]
  ------------------
 1139|    301|				sc_log(ctx, "read EF(TokenInfo) file error: %s", sc_strerror(err));
  ------------------
  |  |   71|    301|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1140|    301|			} else {
 1141|     41|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  132|     41|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1142|     41|				sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
  ------------------
  |  |   71|     41|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1143|     41|			}
 1144|    342|			goto end;
 1145|    342|		}
 1146|       |		/* sc_read_binary may return less than requested */
 1147|    218|		len = err;
 1148|       |
 1149|    218|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1149:7): [True: 120, False: 98]
  ------------------
 1150|    120|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1151|    120|		}
 1152|    218|	}
 1153|       |
 1154|    219|	memset(&tokeninfo, 0, sizeof(tokeninfo));
 1155|    219|	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 1156|    219|	if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    219|#define SC_SUCCESS				0
  ------------------
  |  Branch (1156:6): [True: 134, False: 85]
  ------------------
 1157|    134|		sc_log(ctx, "cannot parse TokenInfo content: %s", sc_strerror(err));
  ------------------
  |  |   71|    134|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1158|    134|		goto end;
 1159|    134|	}
 1160|       |
 1161|     85|	sc_pkcs15_clear_tokeninfo(p15card->tokeninfo);
 1162|     85|	*(p15card->tokeninfo) = tokeninfo;
 1163|       |
 1164|     85|	if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
  ------------------
  |  Branch (1164:6): [True: 47, False: 38]
  |  Branch (1164:44): [True: 46, False: 1]
  ------------------
 1165|     46|		sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
 1166|     46|	}
 1167|       |
 1168|     85|	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
  ------------------
  |  Branch (1168:6): [True: 47, False: 38]
  |  Branch (1168:44): [True: 15, False: 32]
  ------------------
 1169|     15|		char *serial = calloc(1, card->serialnr.len*2 + 1);
 1170|     15|		size_t ii;
 1171|     15|		if (!serial) {
  ------------------
  |  Branch (1171:7): [True: 0, False: 15]
  ------------------
 1172|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1173|      0|			goto end;
 1174|      0|		}
 1175|       |
 1176|    191|		for(ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (1176:12): [True: 176, False: 15]
  ------------------
 1177|    176|			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 1178|       |
 1179|     15|		p15card->tokeninfo->serial_number = serial;
 1180|     15|		sc_log(ctx, "p15card->tokeninfo->serial_number %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1181|     15|	}
 1182|       |
 1183|     85|	ok = 1;
 1184|  12.0k|end:
 1185|  12.0k|	if (buf != NULL)
  ------------------
  |  Branch (1185:6): [True: 561, False: 11.4k]
  ------------------
 1186|    561|		free(buf);
 1187|  12.0k|	if (!ok) {
  ------------------
  |  Branch (1187:6): [True: 11.9k, False: 85]
  ------------------
 1188|  11.9k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  11.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.9k|	int _ret = r; \
  |  |  |  |  155|  11.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.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|  11.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.4k, False: 501]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.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|  11.9k|	return _ret; \
  |  |  |  |  163|  11.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1189|  11.9k|	}
 1190|       |
 1191|     85|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     85|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 85]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1192|     85|}
sc_pkcs15_bind_internal:
 1196|  12.3k|{
 1197|  12.3k|	struct sc_card *card = p15card->card;
 1198|  12.3k|	struct sc_context *ctx = card->ctx;
 1199|  12.3k|	const struct sc_app_info *info = NULL;
 1200|  12.3k|	int err, ok = 0;
 1201|       |
 1202|  12.3k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|       |	/* Enumerate apps now */
 1204|  12.3k|	if (card->app_count < 0) {
  ------------------
  |  Branch (1204:6): [True: 11.4k, False: 915]
  ------------------
 1205|  11.4k|		err = sc_enum_apps(card);
 1206|  11.4k|		if (err != SC_SUCCESS)
  ------------------
  |  |   28|  11.4k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1206:7): [True: 11.1k, False: 298]
  ------------------
 1207|  11.1k|			sc_log(ctx, "unable to enumerate apps: %s", sc_strerror(err));
  ------------------
  |  |   71|  11.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__
  |  |  ------------------
  ------------------
 1208|  11.4k|	}
 1209|  12.3k|	sc_file_free(p15card->file_app);
 1210|  12.3k|	p15card->file_app = sc_file_new();
 1211|  12.3k|	if (p15card->file_app == NULL) {
  ------------------
  |  Branch (1211:6): [True: 0, False: 12.3k]
  ------------------
 1212|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1213|      0|		goto end;
 1214|      0|	}
 1215|       |
 1216|  12.3k|	sc_format_path("3F005015", &p15card->file_app->path);
 1217|       |
 1218|  12.3k|	info = sc_find_app(card, aid);
 1219|  12.3k|	if (info) {
  ------------------
  |  Branch (1219:6): [True: 422, False: 11.9k]
  ------------------
 1220|    422|		sc_log(ctx, "bind to application('%s',aid:'%s')", info->label, sc_dump_hex(info->aid.value, info->aid.len));
  ------------------
  |  |   71|    422|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1221|    422|		sc_pkcs15_free_app(p15card);
 1222|    422|		p15card->app = sc_dup_app_info(info);
 1223|    422|		if (!p15card->app) {
  ------------------
  |  Branch (1223:7): [True: 0, False: 422]
  ------------------
 1224|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1225|      0|			goto end;
 1226|      0|		}
 1227|       |
 1228|    422|		if (info->path.len)
  ------------------
  |  Branch (1228:7): [True: 374, False: 48]
  ------------------
 1229|    374|			p15card->file_app->path = info->path;
 1230|       |
 1231|    422|		if (info->ddo.value && info->ddo.len)
  ------------------
  |  Branch (1231:7): [True: 52, False: 370]
  |  Branch (1231:26): [True: 48, False: 4]
  ------------------
 1232|     48|			parse_ddo(p15card, info->ddo.value, info->ddo.len);
 1233|       |
 1234|  11.9k|	} else if (aid) {
  ------------------
  |  Branch (1234:13): [True: 0, False: 11.9k]
  ------------------
 1235|      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__
  |  |  ------------------
  ------------------
 1236|      0|		err = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1237|      0|		goto end;
 1238|      0|	}
 1239|  12.3k|	sc_log(ctx, "application path '%s'", sc_print_path(&p15card->file_app->path));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1240|       |
 1241|       |	/* Check if pkcs15 directory exists */
 1242|  12.3k|	err = sc_select_file(card, &p15card->file_app->path, NULL);
 1243|       |
 1244|       |	/* If the above test failed on cards without EF(DIR),
 1245|       |	 * try to continue read ODF from 3F005031. -aet
 1246|       |	 */
 1247|  12.3k|	if ((err != SC_SUCCESS) && (card->app_count < 1)) {
  ------------------
  |  |   28|  12.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1247:6): [True: 10.6k, False: 1.76k]
  |  Branch (1247:29): [True: 10.2k, False: 309]
  ------------------
 1248|  10.2k|		sc_format_path("3F00", &p15card->file_app->path);
 1249|  10.2k|		err = SC_SUCCESS;
  ------------------
  |  |   28|  10.2k|#define SC_SUCCESS				0
  ------------------
 1250|  10.2k|	}
 1251|       |
 1252|  12.3k|	if (err < 0) {
  ------------------
  |  Branch (1252:6): [True: 309, False: 12.0k]
  ------------------
 1253|    309|		sc_log(ctx, "Cannot select application path");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1254|    309|		goto end;
 1255|    309|	}
 1256|       |
 1257|  12.0k|	err = sc_pkcs15_bind_internal_tokeninfo(p15card);
 1258|  12.0k|	if (err < 0) {
  ------------------
  |  Branch (1258:6): [True: 11.4k, False: 586]
  ------------------
 1259|  11.4k|		sc_log(ctx, "Cannot bind tokeninfo");
  ------------------
  |  |   71|  11.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__
  |  |  ------------------
  ------------------
 1260|  11.4k|		goto end;
 1261|  11.4k|	}
 1262|       |
 1263|    586|	err = sc_pkcs15_bind_internal_odf(p15card);
 1264|    586|	if (err < 0) {
  ------------------
  |  Branch (1264:6): [True: 431, False: 155]
  ------------------
 1265|    431|		sc_log(ctx, "Cannot bind ODF");
  ------------------
  |  |   71|    431|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1266|    431|		goto end;
 1267|    431|	}
 1268|       |
 1269|    155|	ok = 1;
 1270|  12.3k|end:
 1271|  12.3k|	if (!ok) {
  ------------------
  |  Branch (1271:6): [True: 12.2k, False: 155]
  ------------------
 1272|  12.2k|		sc_pkcs15_card_clear(p15card);
 1273|  12.2k|		if (err == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  12.2k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (1273:7): [True: 1.29k, False: 10.9k]
  ------------------
 1274|  1.29k|			err = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  1.29k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1275|  12.2k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  12.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.2k|	int _ret = r; \
  |  |  |  |  155|  12.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.2k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.2k|	return _ret; \
  |  |  |  |  163|  12.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1276|  12.2k|	}
 1277|       |
 1278|    155|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    155|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    155|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    155|	int _ret = r; \
  |  |  |  |  155|    155|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 155, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    155|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 155]
  |  |  |  |  ------------------
  |  |  |  |  157|    155|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    155|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    155|	return _ret; \
  |  |  |  |  163|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1279|    155|}
pkcs15_get_default_use_file_cache:
 1282|  13.0k|{
 1283|       |	/* enable file caching by default for cards with static content to avoid
 1284|       |	 * synchronization problems.
 1285|       |	 *
 1286|       |	 * The following list was initialized with the cards that can't be modified
 1287|       |	 * with OpenSC i.e. which don't have a profile/driver for pkcs15-init. */
 1288|  13.0k|	const char *card_drivers_with_file_cache[] = {
 1289|  13.0k|			"atrust-acos",
 1290|  13.0k|			"belpic",
 1291|  13.0k|			"cac1",
 1292|  13.0k|			"cac",
 1293|  13.0k|			"cedulauy",
 1294|  13.0k|			"coolkey",
 1295|  13.0k|			"edo",
 1296|  13.0k|			"esteid2018",
 1297|  13.0k|			"esteid2025",
 1298|  13.0k|			"flex",
 1299|  13.0k|			"cyberflex",
 1300|  13.0k|			"gemsafeV1",
 1301|  13.0k|			"idprime",
 1302|  13.0k|			"itacns",
 1303|  13.0k|			"jpki",
 1304|  13.0k|			"MaskTech",
 1305|  13.0k|			"mcrd",
 1306|  13.0k|			"myeid",
 1307|  13.0k|			"npa",
 1308|  13.0k|			"nqapplet",
 1309|  13.0k|			"tcos",
 1310|  13.0k|			"dtrust",
 1311|  13.0k|			"lteid",
 1312|  13.0k|	};
 1313|       |
 1314|  13.0k|	if (NULL == card || NULL == card->driver || NULL == card->driver->short_name)
  ------------------
  |  Branch (1314:6): [True: 0, False: 13.0k]
  |  Branch (1314:22): [True: 0, False: 13.0k]
  |  Branch (1314:46): [True: 0, False: 13.0k]
  ------------------
 1315|      0|		return "no";
 1316|   246k|	for (size_t i = 0; i < (sizeof card_drivers_with_file_cache / sizeof *card_drivers_with_file_cache); i++) {
  ------------------
  |  Branch (1316:21): [True: 239k, False: 7.52k]
  ------------------
 1317|   239k|		if (0 == strcmp(card->driver->short_name, card_drivers_with_file_cache[i]))
  ------------------
  |  Branch (1317:7): [True: 5.51k, False: 233k]
  ------------------
 1318|  5.51k|			return "public";
 1319|   239k|	}
 1320|       |
 1321|  7.52k|	return "no";
 1322|  13.0k|}
sc_pkcs15_bind:
 1327|  13.0k|{
 1328|  13.0k|	struct sc_pkcs15_card *p15card = NULL;
 1329|  13.0k|	struct sc_context *ctx;
 1330|  13.0k|	scconf_block *conf_block = NULL;
 1331|  13.0k|	int r, emu_first, enable_emu;
 1332|  13.0k|	const char *use_file_cache;
 1333|  13.0k|	const char *pin_protected_certificate, *private_certificate;
 1334|       |
 1335|  13.0k|	if (card == NULL || p15card_out == NULL) {
  ------------------
  |  Branch (1335:6): [True: 0, False: 13.0k]
  |  Branch (1335:22): [True: 0, False: 13.0k]
  ------------------
 1336|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1337|      0|	}
 1338|  13.0k|	ctx = card->ctx;
 1339|       |
 1340|  13.0k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  13.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  13.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  13.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  13.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 13.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|  13.0k|	sc_log(ctx, "application(aid:'%s')", aid ? sc_dump_hex(aid->value, aid->len) : "empty");
  ------------------
  |  |   71|  26.0k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 13.0k]
  |  |  ------------------
  ------------------
 1342|       |
 1343|  13.0k|	p15card = sc_pkcs15_card_new();
 1344|  13.0k|	if (p15card == NULL)
  ------------------
  |  Branch (1344:6): [True: 0, False: 13.0k]
  ------------------
 1345|  13.0k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|       |
 1347|  13.0k|	p15card->card = card;
 1348|  13.0k|	p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  13.0k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1349|  13.0k|	use_file_cache = pkcs15_get_default_use_file_cache(card);
 1350|  13.0k|	p15card->opts.use_pin_cache = 1;
 1351|  13.0k|	p15card->opts.pin_cache_counter = 10;
 1352|  13.0k|	p15card->opts.pin_cache_ignore_user_consent = 0;
 1353|  13.0k|	pin_protected_certificate = "protect";
 1354|  13.0k|	private_certificate = "";
 1355|       |
 1356|  13.0k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1357|  13.0k|	if (conf_block) {
  ------------------
  |  Branch (1357:6): [True: 0, False: 13.0k]
  ------------------
 1358|      0|		use_file_cache = scconf_get_str(conf_block, "use_file_caching", use_file_cache);
 1359|      0|		p15card->opts.use_pin_cache = scconf_get_bool(conf_block, "use_pin_caching", p15card->opts.use_pin_cache);
 1360|      0|		p15card->opts.pin_cache_counter = scconf_get_int(conf_block, "pin_cache_counter", p15card->opts.pin_cache_counter);
 1361|      0|		p15card->opts.pin_cache_ignore_user_consent = scconf_get_bool(conf_block, "pin_cache_ignore_user_consent",
 1362|      0|				p15card->opts.pin_cache_ignore_user_consent);
 1363|      0|		pin_protected_certificate = scconf_get_str(conf_block, "pin_protected_certificate", pin_protected_certificate);
 1364|       |		/* read also the old value to keep backward compatibility */
 1365|      0|		private_certificate = scconf_get_str(conf_block, "private_certificate", private_certificate);
 1366|      0|	}
 1367|       |
 1368|  13.0k|	if (0 == strcmp(use_file_cache, "yes")) {
  ------------------
  |  Branch (1368:6): [True: 0, False: 13.0k]
  ------------------
 1369|      0|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_ALL_FILES;
  ------------------
  |  |  606|      0|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
 1370|  13.0k|	} else if (0 == strcmp(use_file_cache, "public")) {
  ------------------
  |  Branch (1370:13): [True: 5.51k, False: 7.52k]
  ------------------
 1371|  5.51k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_PUBLIC_FILES;
  ------------------
  |  |  605|  5.51k|#define SC_PKCS15_OPTS_CACHE_PUBLIC_FILES		1
  ------------------
 1372|  7.52k|	} else if (0 == strcmp(use_file_cache, "no")) {
  ------------------
  |  Branch (1372:13): [True: 7.52k, False: 0]
  ------------------
 1373|  7.52k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  7.52k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1374|  7.52k|	}
 1375|       |
 1376|  13.0k|	if (0 == strcmp(pin_protected_certificate, "protect")) {
  ------------------
  |  Branch (1376:6): [True: 13.0k, False: 0]
  ------------------
 1377|  13.0k|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|  13.0k|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1378|  13.0k|	} else if (0 == strcmp(pin_protected_certificate, "ignore")) {
  ------------------
  |  Branch (1378:13): [True: 0, False: 0]
  ------------------
 1379|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1380|      0|	} else if (0 == strcmp(pin_protected_certificate, "declassify")) {
  ------------------
  |  Branch (1380:13): [True: 0, False: 0]
  ------------------
 1381|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1382|      0|	}
 1383|       |	/* overwrite pin_protected_certificate when private_certificate set */
 1384|  13.0k|	if (0 == strcmp(private_certificate, "protect")) {
  ------------------
  |  Branch (1384:6): [True: 0, False: 13.0k]
  ------------------
 1385|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1386|  13.0k|	} else if (0 == strcmp(private_certificate, "ignore")) {
  ------------------
  |  Branch (1386:13): [True: 0, False: 13.0k]
  ------------------
 1387|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1388|  13.0k|	} else if (0 == strcmp(private_certificate, "declassify")) {
  ------------------
  |  Branch (1388:13): [True: 0, False: 13.0k]
  ------------------
 1389|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1390|      0|	}
 1391|  13.0k|	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.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__
  |  |  ------------------
  ------------------
 1392|  13.0k|			p15card->opts.use_file_cache, p15card->opts.use_pin_cache, p15card->opts.pin_cache_counter,
 1393|  13.0k|			p15card->opts.pin_cache_ignore_user_consent, p15card->opts.pin_protected_certificate);
 1394|       |
 1395|  13.0k|	r = sc_lock(card);
 1396|  13.0k|	if (r) {
  ------------------
  |  Branch (1396:6): [True: 0, False: 13.0k]
  ------------------
 1397|      0|		sc_log(ctx, "sc_lock() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1398|      0|		sc_pkcs15_card_free(p15card);
 1399|      0|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1400|      0|	}
 1401|       |
 1402|  13.0k|	enable_emu = scconf_get_bool(conf_block, "enable_pkcs15_emulation", 1);
 1403|  13.0k|	if (enable_emu) {
  ------------------
  |  Branch (1403:6): [True: 13.0k, False: 0]
  ------------------
 1404|  13.0k|		sc_log(ctx, "PKCS#15 emulation enabled");
  ------------------
  |  |   71|  13.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__
  |  |  ------------------
  ------------------
 1405|  13.0k|		emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
 1406|  13.0k|		if (emu_first || sc_pkcs15_is_emulation_only(card)) {
  ------------------
  |  Branch (1406:7): [True: 0, False: 13.0k]
  |  Branch (1406:20): [True: 2.86k, False: 10.1k]
  ------------------
 1407|  2.86k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1408|  2.86k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  2.86k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1408:8): [True: 1.61k, False: 1.25k]
  ------------------
 1409|  1.61k|				goto done;
 1410|  1.25k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1411|  1.25k|			if (r < 0)
  ------------------
  |  Branch (1411:8): [True: 1.24k, False: 10]
  ------------------
 1412|  1.24k|				goto error;
 1413|  10.1k|		} else {
 1414|  10.1k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1415|  10.1k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  10.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1415:8): [True: 129, False: 10.0k]
  ------------------
 1416|    129|				goto done;
 1417|  10.0k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1418|  10.0k|			if (r < 0)
  ------------------
  |  Branch (1418:8): [True: 5.81k, False: 4.23k]
  ------------------
 1419|  5.81k|				goto error;
 1420|  10.0k|		}
 1421|  13.0k|	}
 1422|      0|	else {
 1423|      0|		r = sc_pkcs15_bind_internal(p15card, aid);
 1424|      0|		if (r < 0)
  ------------------
  |  Branch (1424:7): [True: 0, False: 0]
  ------------------
 1425|      0|			goto error;
 1426|      0|	}
 1427|  5.98k|done:
 1428|  5.98k|	*p15card_out = p15card;
 1429|  5.98k|	sc_unlock(card);
 1430|  5.98k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  5.98k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.98k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.98k|	int _ret = r; \
  |  |  |  |  155|  5.98k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.98k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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: 5.98k]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.98k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.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|  5.98k|	return _ret; \
  |  |  |  |  163|  5.98k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1431|  7.05k|error:
 1432|  7.05k|	sc_unlock(card);
 1433|  7.05k|	sc_pkcs15_card_free(p15card);
 1434|  7.05k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  7.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.05k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.05k|	int _ret = r; \
  |  |  |  |  155|  7.05k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|  7.05k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.05k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.05k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.05k|	return _ret; \
  |  |  |  |  163|  7.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1435|  7.05k|}
sc_pkcs15_get_objects:
 1539|    162|{
 1540|    162|	return sc_pkcs15_get_objects_cond(p15card, type, NULL, NULL, ret, ret_size);
 1541|    162|}
sc_pkcs15_search_objects:
 1723|     10|{
 1724|     10|	return __sc_pkcs15_search_objects(p15card,
 1725|     10|			sk->class_mask, sk->type,
 1726|     10|			compare_obj_key, sk,
 1727|     10|			ret, ret_size);
 1728|     10|}
sc_pkcs15_get_objects_cond:
 1735|    162|{
 1736|    162|	return __sc_pkcs15_search_objects(p15card, 0, type,
 1737|    162|			func, func_arg, ret, ret_size);
 1738|    162|}
sc_pkcs15_find_object_by_id:
 1744|  2.73k|{
 1745|  2.73k|	struct sc_pkcs15_search_key sk;
 1746|  2.73k|	int	r;
 1747|       |
 1748|  2.73k|	memset(&sk, 0, sizeof(sk));
 1749|  2.73k|	sk.id = id;
 1750|       |
 1751|  2.73k|	r = __sc_pkcs15_search_objects(p15card, 0, type, compare_obj_key, &sk, out, 1);
 1752|  2.73k|	if (r < 0)
  ------------------
  |  Branch (1752:6): [True: 0, False: 2.73k]
  ------------------
 1753|      0|		return r;
 1754|  2.73k|	if (r == 0)
  ------------------
  |  Branch (1754:6): [True: 1.32k, False: 1.41k]
  ------------------
 1755|  1.32k|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|  1.32k|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1756|  1.41k|	return 0;
 1757|  2.73k|}
sc_pkcs15_find_cert_by_id:
 1763|  1.78k|{
 1764|  1.78k|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, id, out);
  ------------------
  |  |  438|  1.78k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 1765|  1.78k|}
sc_pkcs15_find_pin_by_auth_id:
 1795|    954|{
 1796|    954|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_AUTH, id, out);
  ------------------
  |  |  444|    954|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1797|    954|}
sc_pkcs15_add_object:
 1987|  47.0k|{
 1988|  47.0k|	struct sc_pkcs15_object *p = p15card->obj_list;
 1989|       |
 1990|  47.0k|	if (!obj)
  ------------------
  |  Branch (1990:6): [True: 0, False: 47.0k]
  ------------------
 1991|      0|		return 0;
 1992|  47.0k|	obj->next = obj->prev = NULL;
 1993|  47.0k|	if (p15card->obj_list == NULL) {
  ------------------
  |  Branch (1993:6): [True: 5.61k, False: 41.4k]
  ------------------
 1994|  5.61k|		p15card->obj_list = obj;
 1995|  5.61k|		return 0;
 1996|  5.61k|	}
 1997|   759k|	while (p->next != NULL)
  ------------------
  |  Branch (1997:9): [True: 718k, False: 41.4k]
  ------------------
 1998|   718k|		p = p->next;
 1999|  41.4k|	p->next = obj;
 2000|  41.4k|	obj->prev = p;
 2001|       |
 2002|  41.4k|	return 0;
 2003|  47.0k|}
sc_pkcs15_free_object:
 2038|  47.0k|{
 2039|  47.0k|	if (!obj)
  ------------------
  |  Branch (2039:6): [True: 0, False: 47.0k]
  ------------------
 2040|      0|		return;
 2041|  47.0k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  47.0k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 2042|  5.63k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  5.63k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2042:2): [True: 5.63k, False: 41.4k]
  ------------------
 2043|  5.63k|		sc_pkcs15_free_prkey_info((sc_pkcs15_prkey_info_t *)obj->data);
 2044|  5.63k|		break;
 2045|  2.30k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  2.30k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (2045:2): [True: 2.30k, False: 44.7k]
  ------------------
 2046|       |		/* This is normally passed to framework-pkcs15,
 2047|       |		 * but if something fails on the way, it would not get freed */
 2048|  2.30k|		if (obj->emulated) {
  ------------------
  |  Branch (2048:7): [True: 2.08k, False: 214]
  ------------------
 2049|  2.08k|			sc_pkcs15_free_pubkey(obj->emulated);
 2050|  2.08k|		}
 2051|  2.30k|		sc_pkcs15_free_pubkey_info((sc_pkcs15_pubkey_info_t *)obj->data);
 2052|  2.30k|		break;
 2053|  3.98k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  3.98k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (2053:2): [True: 3.98k, False: 43.1k]
  ------------------
 2054|  3.98k|		sc_pkcs15_free_cert_info((sc_pkcs15_cert_info_t *)obj->data);
 2055|  3.98k|		break;
 2056|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2056:2): [True: 0, False: 47.0k]
  ------------------
 2057|      0|		sc_pkcs15_free_skey_info((sc_pkcs15_skey_info_t *)obj->data);
 2058|      0|		break;
 2059|  27.5k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  27.5k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2059:2): [True: 27.5k, False: 19.5k]
  ------------------
 2060|  27.5k|		sc_pkcs15_free_data_info((sc_pkcs15_data_info_t *)obj->data);
 2061|  27.5k|		break;
 2062|  7.63k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  7.63k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2062:2): [True: 7.63k, False: 39.4k]
  ------------------
 2063|  7.63k|		sc_pkcs15_free_auth_info((sc_pkcs15_auth_info_t *)obj->data);
 2064|  7.63k|		break;
 2065|      0|	default:
  ------------------
  |  Branch (2065:2): [True: 0, False: 47.0k]
  ------------------
 2066|      0|		free(obj->data);
 2067|  47.0k|	}
 2068|       |
 2069|  47.0k|	sc_pkcs15_free_object_content(obj);
 2070|       |
 2071|  47.0k|	free(obj);
 2072|  47.0k|}
sc_pkcs15_add_df:
 2077|  13.6k|{
 2078|  13.6k|	struct sc_pkcs15_df *p, *newdf;
 2079|       |
 2080|  13.6k|	newdf = calloc(1, sizeof(struct sc_pkcs15_df));
 2081|  13.6k|	if (newdf == NULL)
  ------------------
  |  Branch (2081:6): [True: 0, False: 13.6k]
  ------------------
 2082|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2083|  13.6k|	newdf->path = *path;
 2084|  13.6k|	newdf->type = type;
 2085|       |
 2086|  13.6k|	if (p15card->df_list == NULL) {
  ------------------
  |  Branch (2086:6): [True: 5.64k, False: 8.05k]
  ------------------
 2087|  5.64k|		p15card->df_list = newdf;
 2088|  5.64k|		return 0;
 2089|  5.64k|	}
 2090|       |
 2091|  8.05k|	p = p15card->df_list;
 2092|  28.9k|	while (p->next != NULL)
  ------------------
  |  Branch (2092:9): [True: 20.8k, False: 8.05k]
  ------------------
 2093|  20.8k|		p = p->next;
 2094|  8.05k|	p->next = newdf;
 2095|  8.05k|	newdf->prev = p;
 2096|       |
 2097|  8.05k|	return 0;
 2098|  13.6k|}
sc_pkcs15_parse_df:
 2193|  1.73k|{
 2194|  1.73k|	struct sc_context *ctx = p15card->card->ctx;
 2195|  1.73k|	unsigned char *buf;
 2196|  1.73k|	const unsigned char *p;
 2197|  1.73k|	size_t bufsize;
 2198|  1.73k|	int r;
 2199|  1.73k|	struct sc_pkcs15_object *obj = NULL;
 2200|  1.73k|	int (* func)(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
 2201|  1.73k|		     const u8 **nbuf, size_t *nbufsize) = NULL;
 2202|       |
 2203|  1.73k|	sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
  ------------------
  |  |   71|  1.73k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2204|       |
 2205|  1.73k|	if (df->enumerated)
  ------------------
  |  Branch (2205:6): [True: 0, False: 1.73k]
  ------------------
 2206|  1.73k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2207|       |
 2208|  1.73k|	switch (df->type) {
  ------------------
  |  Branch (2208:10): [True: 1.73k, False: 0]
  ------------------
 2209|    147|	case SC_PKCS15_PRKDF:
  ------------------
  |  |  488|    147|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (2209:2): [True: 147, False: 1.58k]
  ------------------
 2210|    147|		func = sc_pkcs15_decode_prkdf_entry;
 2211|    147|		break;
 2212|  1.16k|	case SC_PKCS15_PUKDF:
  ------------------
  |  |  489|  1.16k|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (2212:2): [True: 1.16k, False: 563]
  ------------------
 2213|  1.16k|		func = sc_pkcs15_decode_pukdf_entry;
 2214|  1.16k|		break;
 2215|      0|	case SC_PKCS15_SKDF:
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
  |  Branch (2215:2): [True: 0, False: 1.73k]
  ------------------
 2216|      0|		func = sc_pkcs15_decode_skdf_entry;
 2217|      0|		break;
 2218|    351|	case SC_PKCS15_CDF:
  ------------------
  |  |  492|    351|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (2218:2): [True: 351, False: 1.38k]
  ------------------
 2219|    351|	case SC_PKCS15_CDF_TRUSTED:
  ------------------
  |  |  493|    351|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
  |  Branch (2219:2): [True: 0, False: 1.73k]
  ------------------
 2220|    351|	case SC_PKCS15_CDF_USEFUL:
  ------------------
  |  |  494|    351|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
  |  Branch (2220:2): [True: 0, False: 1.73k]
  ------------------
 2221|    351|		func = sc_pkcs15_decode_cdf_entry;
 2222|    351|		break;
 2223|      0|	case SC_PKCS15_DODF:
  ------------------
  |  |  495|      0|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (2223:2): [True: 0, False: 1.73k]
  ------------------
 2224|      0|		func = sc_pkcs15_decode_dodf_entry;
 2225|      0|		break;
 2226|     65|	case SC_PKCS15_AODF:
  ------------------
  |  |  496|     65|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (2226:2): [True: 65, False: 1.66k]
  ------------------
 2227|     65|		func = sc_pkcs15_decode_aodf_entry;
 2228|     65|		break;
 2229|  1.73k|	}
 2230|  1.73k|	if (func == NULL) {
  ------------------
  |  Branch (2230:6): [True: 0, False: 1.73k]
  ------------------
 2231|      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__
  |  |  ------------------
  ------------------
 2232|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2233|      0|	}
 2234|  1.73k|	r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, 0);
 2235|  1.73k|	LOG_TEST_RET(ctx, r, "pkcs15 read file failed");
  ------------------
  |  |  174|  1.73k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.73k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.73k|	int _ret = (r); \
  |  |  |  |  168|  1.73k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.52k, False: 210]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.52k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.52k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.52k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.52k|		return _ret; \
  |  |  |  |  172|  1.52k|	} \
  |  |  |  |  173|  1.73k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 210]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2236|       |
 2237|    210|	p = buf;
 2238|    210|	while (bufsize && *p != 0x00) {
  ------------------
  |  Branch (2238:9): [True: 153, False: 57]
  |  Branch (2238:20): [True: 94, False: 59]
  ------------------
 2239|       |
 2240|     94|		obj = calloc(1, sizeof(struct sc_pkcs15_object));
 2241|     94|		if (obj == NULL) {
  ------------------
  |  Branch (2241:7): [True: 0, False: 94]
  ------------------
 2242|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2243|      0|			goto ret;
 2244|      0|		}
 2245|     94|		r = func(p15card, obj, &p, &bufsize);
 2246|     94|		if (r) {
  ------------------
  |  Branch (2246:7): [True: 94, False: 0]
  ------------------
 2247|     94|			free(obj);
 2248|     94|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|     94|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (2248:8): [True: 19, False: 75]
  ------------------
 2249|     19|				r = 0;
 2250|     19|				break;
 2251|     19|			}
 2252|     75|			sc_log(ctx, "%s: Error decoding DF entry", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2253|     75|			goto ret;
 2254|     94|		}
 2255|       |
 2256|      0|		obj->df = df;
 2257|      0|		r = sc_pkcs15_add_object(p15card, obj);
 2258|      0|		if (r) {
  ------------------
  |  Branch (2258:7): [True: 0, False: 0]
  ------------------
 2259|      0|			if (obj->data)
  ------------------
  |  Branch (2259:8): [True: 0, False: 0]
  ------------------
 2260|      0|				free(obj->data);
 2261|      0|			free(obj);
 2262|      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__
  |  |  ------------------
  ------------------
 2263|      0|			goto ret;
 2264|      0|		}
 2265|      0|		while (bufsize > 0 && *p == 00) {
  ------------------
  |  Branch (2265:10): [True: 0, False: 0]
  |  Branch (2265:25): [True: 0, False: 0]
  ------------------
 2266|      0|			bufsize--;
 2267|      0|			p++;
 2268|      0|		}
 2269|    135|	};
 2270|       |
 2271|    135|	if (r > 0)
  ------------------
  |  Branch (2271:6): [True: 0, False: 135]
  ------------------
 2272|      0|		r = 0;
 2273|    210|ret:
 2274|    210|	df->enumerated = 1;
 2275|    210|	free(buf);
 2276|    210|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    210|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    210|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    210|	int _ret = r; \
  |  |  |  |  155|    210|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 210, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    210|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     75|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 75, False: 135]
  |  |  |  |  ------------------
  |  |  |  |  157|    210|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    210|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    210|	return _ret; \
  |  |  |  |  163|    210|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2277|    210|}
sc_pkcs15_read_file:
 2529|  16.7k|{
 2530|  16.7k|	struct sc_context *ctx;
 2531|  16.7k|	struct sc_file *file = NULL;
 2532|  16.7k|	unsigned char *data = NULL;
 2533|  16.7k|	size_t	len = 0, offset = 0;
 2534|  16.7k|	int	r;
 2535|       |
 2536|  16.7k|	if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
  ------------------
  |  Branch (2536:6): [True: 0, False: 16.7k]
  |  Branch (2536:25): [True: 0, False: 16.7k]
  |  Branch (2536:50): [True: 0, False: 16.7k]
  |  Branch (2536:69): [True: 0, False: 16.7k]
  ------------------
 2537|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2538|      0|	}
 2539|  16.7k|	ctx = p15card->card->ctx;
 2540|       |
 2541|  16.7k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  16.7k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  16.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  16.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  16.7k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 16.7k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2542|  16.7k|	sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2543|       |
 2544|  16.7k|	r = -1; /* file state: not in cache */
 2545|  16.7k|	if (p15card->opts.use_file_cache
  ------------------
  |  Branch (2545:6): [True: 7.07k, False: 9.65k]
  ------------------
 2546|  7.07k|	    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|  7.07k|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2546:10): [True: 0, False: 7.07k]
  |  Branch (2546:77): [True: 7.07k, False: 0]
  ------------------
 2547|  7.07k|		r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len);
 2548|       |
 2549|  7.07k|		if (!r && in_path->aid.len > 0 && in_path->len >= 2)   {
  ------------------
  |  Branch (2549:7): [True: 335, False: 6.73k]
  |  Branch (2549:13): [True: 2, False: 333]
  |  Branch (2549:37): [True: 2, False: 0]
  ------------------
 2550|      2|			struct sc_path parent = *in_path;
 2551|       |
 2552|      2|			parent.len -= 2;
 2553|      2|			parent.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|      2|#define SC_PATH_TYPE_PATH		2
  ------------------
 2554|      2|			r = sc_select_file(p15card->card, &parent, NULL);
 2555|      2|		}
 2556|  7.07k|	}
 2557|       |
 2558|  16.7k|	if (r) {
  ------------------
  |  Branch (2558:6): [True: 16.3k, False: 334]
  ------------------
 2559|  16.3k|		r = sc_lock(p15card->card);
 2560|  16.3k|		if (r)
  ------------------
  |  Branch (2560:7): [True: 0, False: 16.3k]
  ------------------
 2561|      0|			goto fail;
 2562|  16.3k|		r = sc_select_file(p15card->card, in_path, &file);
 2563|  16.3k|		if (r)
  ------------------
  |  Branch (2563:7): [True: 11.9k, False: 4.42k]
  ------------------
 2564|  11.9k|			goto fail_unlock;
 2565|       |
 2566|       |		/* Handle the case where the ASN.1 Path object specified
 2567|       |		 * index and length values */
 2568|       |
 2569|  4.42k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  4.42k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2569:7): [True: 74, False: 4.34k]
  ------------------
 2570|       |
 2571|       |			// in_path->index: record_no
 2572|       |			// in_path->count: ignored!
 2573|       |
 2574|     74|			if(file->record_length > 0) {
  ------------------
  |  Branch (2574:7): [True: 64, False: 10]
  ------------------
 2575|     64|				if(file->record_length > MAX_FILE_SIZE) {
  ------------------
  |  |  220|     64|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2575:8): [True: 0, False: 64]
  ------------------
 2576|      0|					len = MAX_FILE_SIZE;
  ------------------
  |  |  220|      0|#define MAX_FILE_SIZE 65535
  ------------------
 2577|      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__
  |  |  ------------------
  ------------------
 2578|     64|				} else {
 2579|     64|					len = file->record_length;
 2580|     64|				}
 2581|     64|			} else {
 2582|     10|				len = MAX_FILE_SIZE;
  ------------------
  |  |  220|     10|#define MAX_FILE_SIZE 65535
  ------------------
 2583|     10|			}
 2584|       |
 2585|     74|			if ((in_path->index <= 0) || (in_path->index > (int)(file->record_count))) {
  ------------------
  |  Branch (2585:8): [True: 31, False: 43]
  |  Branch (2585:33): [True: 2, False: 41]
  ------------------
 2586|     33|				sc_log(ctx, "  record number out of bounds: %d", in_path->index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2587|     33|				r = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     33|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
 2588|     33|				goto fail_unlock;
 2589|     33|			}
 2590|       |
 2591|  4.34k|		} else {
 2592|       |
 2593|  4.34k|			if (in_path->count < 0) {
  ------------------
  |  Branch (2593:8): [True: 2.72k, False: 1.61k]
  ------------------
 2594|  2.72k|				if (file->size)
  ------------------
  |  Branch (2594:9): [True: 2.60k, False: 129]
  ------------------
 2595|  2.60k|					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|  2.60k|#define MAX_FILE_SIZE 65535
  ------------------
              					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  220|      0|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2595:12): [True: 0, False: 2.60k]
  ------------------
 2596|    129|				else
 2597|    129|					len = 1024;
 2598|  2.72k|				offset = 0;
 2599|  2.72k|			}
 2600|  1.61k|			else {
 2601|  1.61k|				offset = in_path->index;
 2602|  1.61k|				len = in_path->count;
 2603|       |				/* Make sure we're within proper bounds */
 2604|  1.61k|				if (offset >= file->size || offset + len > file->size) {
  ------------------
  |  Branch (2604:9): [True: 6, False: 1.61k]
  |  Branch (2604:33): [True: 10, False: 1.60k]
  ------------------
 2605|     16|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     16|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2606|     16|					goto fail_unlock;
 2607|     16|				}
 2608|  1.61k|			}
 2609|  4.34k|		}
 2610|       |
 2611|  4.37k|		free(data);
 2612|  4.37k|		data = malloc(len);
 2613|  4.37k|		if (data == NULL) {
  ------------------
  |  Branch (2613:7): [True: 0, False: 4.37k]
  ------------------
 2614|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2615|      0|			goto fail_unlock;
 2616|      0|		}
 2617|       |
 2618|  4.37k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE_TLV) {
  ------------------
  |  |  225|  4.37k|#define SC_FILE_EF_LINEAR_VARIABLE_TLV	0x05
  ------------------
  |  Branch (2618:7): [True: 69, False: 4.30k]
  ------------------
 2619|     69|			unsigned int i;
 2620|     69|			size_t value_bytes_read = 0, record_len;
 2621|     69|			size_t record_bytes, copied, missing;
 2622|     69|			u8 record[256], tag;
 2623|     69|			const u8 *value;
 2624|       |
 2625|       |			/* Stop before the reserved ISO 7816-4 record number 255. */
 2626|    194|			for (i = 1; i < 0xFF; i++) {
  ------------------
  |  Branch (2626:16): [True: 194, False: 0]
  ------------------
 2627|       |				/* The aggregate size counts values, not record headers. */
 2628|    194|				r = sc_read_record(p15card->card, i, 0, record, sizeof(record), SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|    194|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2629|    194|				if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|    194|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (2629:9): [True: 1, False: 193]
  ------------------
 2630|      1|					break;
 2631|    193|				if (r < 0) {
  ------------------
  |  Branch (2631:9): [True: 39, False: 154]
  ------------------
 2632|     39|					goto fail_unlock;
 2633|     39|				}
 2634|    154|				if (r == 0)
  ------------------
  |  Branch (2634:9): [True: 3, False: 151]
  ------------------
 2635|      3|					break;
 2636|    151|				if ((size_t)r > sizeof(record)) {
  ------------------
  |  Branch (2636:9): [True: 0, False: 151]
  ------------------
 2637|      0|					r = SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|      0|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
 2638|      0|					goto fail_unlock;
 2639|      0|				}
 2640|    151|				record_bytes = (size_t)r;
 2641|    151|				value = record;
 2642|    151|				r = sc_simpletlv_read_tag(&value, record_bytes, &tag, &record_len,
 2643|    151|						SC_SIMPLETLV_BIG_ENDIAN);
 2644|    151|				if ((r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS) ||
  ------------------
  |  |   28|    302|#define SC_SUCCESS				0
  ------------------
              				if ((r != SC_SUCCESS && r != SC_ERROR_TLV_END_OF_CONTENTS) ||
  ------------------
  |  |   99|     27|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  |  Branch (2644:10): [True: 27, False: 124]
  |  Branch (2644:29): [True: 1, False: 26]
  ------------------
 2645|    150|						record_len > len - value_bytes_read) {
  ------------------
  |  Branch (2645:7): [True: 5, False: 145]
  ------------------
 2646|      6|					r = SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|      6|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
 2647|      6|					goto fail_unlock;
 2648|      6|				}
 2649|    145|				copied = MIN(record_len, record_bytes - (size_t)(value - record));
  ------------------
  |  |   69|    145|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (69:20): [True: 107, False: 38]
  |  |  ------------------
  ------------------
 2650|    145|				memcpy(data + value_bytes_read, value, copied);
 2651|    145|				missing = record_len - copied;
 2652|    145|				if (missing > 0) {
  ------------------
  |  Branch (2652:9): [True: 21, False: 124]
  ------------------
 2653|     21|					r = sc_read_record(p15card->card, i, (unsigned int)record_bytes,
 2654|     21|							data + value_bytes_read + copied, missing, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|     21|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2655|     21|					if (r < 0)
  ------------------
  |  Branch (2655:10): [True: 19, False: 2]
  ------------------
 2656|     19|						goto fail_unlock;
 2657|      2|					if ((size_t)r != missing) {
  ------------------
  |  Branch (2657:10): [True: 1, False: 1]
  ------------------
 2658|      1|						r = SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|      1|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
 2659|      1|						goto fail_unlock;
 2660|      1|					}
 2661|      2|				}
 2662|    125|				value_bytes_read += record_len;
 2663|    125|			}
 2664|      4|			len = value_bytes_read;
 2665|      4|			if (len > 0) {
  ------------------
  |  Branch (2665:8): [True: 1, False: 3]
  ------------------
 2666|      1|				unsigned char *tmp = realloc(data, len);
 2667|       |
 2668|      1|				if (tmp != NULL)
  ------------------
  |  Branch (2668:9): [True: 1, False: 0]
  ------------------
 2669|      1|					data = tmp;
 2670|      1|			}
 2671|      4|		}
 2672|  4.30k|		else if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  4.30k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2672:12): [True: 41, False: 4.26k]
  ------------------
 2673|     41|			r = sc_read_record(p15card->card, in_path->index, (unsigned)offset, data, len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1298|     41|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2674|     41|			if (r < 0) {
  ------------------
  |  Branch (2674:8): [True: 9, False: 32]
  ------------------
 2675|      9|				goto fail_unlock;
 2676|      9|			}
 2677|       |			/* sc_read_record may return less than requested */
 2678|     32|			len = r;
 2679|     32|		}
 2680|  4.26k|		else {
 2681|  4.26k|			unsigned long flags = 0;
 2682|  4.26k|			r = sc_read_binary(p15card->card, (unsigned)offset, data, len, &flags);
 2683|  4.26k|			if (r < 0) {
  ------------------
  |  Branch (2683:8): [True: 926, False: 3.33k]
  ------------------
 2684|    926|				goto fail_unlock;
 2685|    926|			}
 2686|       |			/* sc_read_binary may return less than requested */
 2687|  3.33k|			len = r;
 2688|       |
 2689|  3.33k|			if (flags & SC_FILE_FLAG_COMPRESSED_AUTO
  ------------------
  |  |  230|  6.67k|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  |  Branch (2689:8): [True: 363, False: 2.97k]
  ------------------
 2690|  2.97k|			    || flags & SC_FILE_FLAG_COMPRESSED_ZLIB
  ------------------
  |  |  231|  6.30k|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2690:11): [True: 0, False: 2.97k]
  ------------------
 2691|  2.97k|			    || flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|  2.97k|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2691:11): [True: 0, False: 2.97k]
  ------------------
 2692|    363|				unsigned char *decompressed_buf = NULL;
 2693|    363|				size_t decompressed_len = 0;
 2694|    363|				r = decompress_file(p15card->card, data, len, &decompressed_buf, &decompressed_len, flags);
 2695|    363|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    363|#define SC_SUCCESS				0
  ------------------
  |  Branch (2695:9): [True: 222, False: 141]
  ------------------
 2696|    222|					goto fail_unlock;
 2697|    222|				}
 2698|    141|				free(data);
 2699|    141|				data = decompressed_buf;
 2700|    141|				len = decompressed_len;
 2701|    141|			}
 2702|  3.33k|		}
 2703|  3.15k|		sc_unlock(p15card->card);
 2704|       |
 2705|  3.15k|		sc_file_free(file);
 2706|       |
 2707|  3.15k|		if (p15card->opts.use_file_cache && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|    697|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2707:7): [True: 697, False: 2.45k]
  |  Branch (2707:40): [True: 0, False: 697]
  |  Branch (2707:107): [True: 697, False: 0]
  ------------------
 2708|    697|			sc_pkcs15_cache_file(p15card, in_path, data, len);
 2709|    697|		}
 2710|  3.15k|		if (len == 0) {
  ------------------
  |  Branch (2710:7): [True: 276, False: 2.87k]
  ------------------
 2711|    276|			free(data);
 2712|    276|			data = NULL;
 2713|    276|		}
 2714|  3.15k|	}
 2715|  3.48k|	*buf = data;
 2716|  3.48k|	*buflen = len;
 2717|  3.48k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.48k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.48k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.48k|	int _ret = r; \
  |  |  |  |  155|  3.48k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.48k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.48k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.48k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.48k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.48k|	return _ret; \
  |  |  |  |  163|  3.48k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2718|       |
 2719|  13.2k|fail_unlock:
 2720|  13.2k|	sc_unlock(p15card->card);
 2721|  13.2k|fail:
 2722|  13.2k|	free(data);
 2723|  13.2k|	sc_file_free(file);
 2724|  13.2k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  13.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  13.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  13.2k|	int _ret = r; \
  |  |  |  |  155|  13.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  13.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.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  13.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  13.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|  13.2k|	return _ret; \
  |  |  |  |  163|  13.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2725|  13.2k|}
sc_pkcs15_compare_id:
 2730|  9.35k|{
 2731|  9.35k|	if (id1 == NULL || id2 == NULL)
  ------------------
  |  Branch (2731:6): [True: 0, False: 9.35k]
  |  Branch (2731:21): [True: 0, False: 9.35k]
  ------------------
 2732|      0|		return 0;
 2733|  9.35k|	if (id1->len != id2->len)
  ------------------
  |  Branch (2733:6): [True: 4.16k, False: 5.18k]
  ------------------
 2734|  4.16k|		return 0;
 2735|  5.18k|	return memcmp(id1->value, id2->value, id1->len) == 0;
 2736|  9.35k|}
sc_pkcs15_format_id:
 2741|   115k|{
 2742|   115k|	size_t len;
 2743|       |
 2744|   115k|	if (!id)
  ------------------
  |  Branch (2744:6): [True: 0, False: 115k]
  ------------------
 2745|      0|		return;
 2746|   115k|	len = sizeof(id->value);
 2747|       |
 2748|   115k|	if (sc_hex_to_bin(str, id->value, &len) != SC_SUCCESS)
  ------------------
  |  |   28|   115k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2748:6): [True: 244, False: 115k]
  ------------------
 2749|    244|		id->len = 0;
 2750|   115k|	else
 2751|   115k|		id->len = len;
 2752|   115k|}
sc_pkcs15_print_id:
 2757|    592|{
 2758|    592|	static char buffer[256];
 2759|       |
 2760|    592|	sc_bin_to_hex(id->value, id->len, buffer, sizeof(buffer), '\0');
 2761|    592|	return buffer;
 2762|    592|}
sc_pkcs15_make_absolute_path:
 2775|  14.5k|{
 2776|       |	/* nothing to do if child has valid 'aid' */
 2777|  14.5k|	if (child->aid.len)
  ------------------
  |  Branch (2777:6): [True: 0, False: 14.5k]
  ------------------
 2778|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2779|       |
 2780|  14.5k|	if (parent->aid.len)   {
  ------------------
  |  Branch (2780:6): [True: 0, False: 14.5k]
  ------------------
 2781|      0|		sc_path_t ppath;
 2782|       |
 2783|       |		/* child inherits parent's 'aid' */
 2784|      0|		child->aid = parent->aid;
 2785|      0|		if (!parent->len)
  ------------------
  |  Branch (2785:7): [True: 0, False: 0]
  ------------------
 2786|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2787|       |
 2788|       |		/* parent has valid 'path' -- concatenate it with the child's one */
 2789|      0|		memcpy(&ppath, parent, sizeof(sc_path_t));
 2790|      0|		ppath.aid.len = 0;
 2791|      0|		ppath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 2792|      0|		return sc_concatenate_path(child, &ppath, child);
 2793|       |
 2794|      0|	}
 2795|  14.5k|	else if (parent->type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  14.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2795:11): [True: 74, False: 14.4k]
  ------------------
 2796|       |		/* child inherits parent's 'DF NAME' as 'aid' */
 2797|     74|		if (parent->len > sizeof(child->aid.value))
  ------------------
  |  Branch (2797:7): [True: 0, False: 74]
  ------------------
 2798|      0|			return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 2799|       |
 2800|     74|		memcpy(child->aid.value, parent->value, parent->len);
 2801|     74|		child->aid.len = parent->len;
 2802|       |
 2803|     74|		return SC_SUCCESS;
  ------------------
  |  |   28|     74|#define SC_SUCCESS				0
  ------------------
 2804|     74|	}
 2805|       |
 2806|       |	/* a 0 length path stays a 0 length path */
 2807|  14.4k|	if (child->len == 0)
  ------------------
  |  Branch (2807:6): [True: 125, False: 14.3k]
  ------------------
 2808|    125|		return SC_SUCCESS;
  ------------------
  |  |   28|    125|#define SC_SUCCESS				0
  ------------------
 2809|       |
 2810|  14.3k|	if (sc_compare_path_prefix(sc_get_mf_path(), child))
  ------------------
  |  Branch (2810:6): [True: 16, False: 14.3k]
  ------------------
 2811|     16|		return SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
 2812|       |
 2813|  14.3k|	return sc_concatenate_path(child, parent, child);
 2814|  14.3k|}
sc_pkcs15_free_object_content:
 2818|  48.1k|{
 2819|  48.1k|	if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (2819:6): [True: 985, False: 47.1k]
  |  Branch (2819:28): [True: 985, False: 0]
  ------------------
 2820|    985|		if (obj->content_free) {
  ------------------
  |  Branch (2820:7): [True: 985, False: 0]
  ------------------
 2821|    985|			obj->content_free(obj->content.value, obj->content.len);
 2822|    985|		} else {
 2823|      0|			free(obj->content.value);
 2824|      0|		}
 2825|    985|	}
 2826|       |	obj->content.value = NULL;
 2827|  48.1k|	obj->content.len = 0;
 2828|  48.1k|}
sc_pkcs15_allocate_object_content:
 2834|    985|{
 2835|    985|	unsigned char *tmp_buf;
 2836|       |
 2837|    985|	if (!obj)
  ------------------
  |  Branch (2837:6): [True: 0, False: 985]
  ------------------
 2838|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2839|       |
 2840|    985|	if (!value || !len)   {
  ------------------
  |  Branch (2840:6): [True: 0, False: 985]
  |  Branch (2840:16): [True: 0, False: 985]
  ------------------
 2841|      0|		sc_pkcs15_free_object_content(obj);
 2842|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2843|      0|	}
 2844|       |
 2845|       |	/* Need to pass by temporary variable,
 2846|       |	 * because 'value' and 'content.value' pointers can be the sames.
 2847|       |	 */
 2848|    985|	if (SC_PKCS15_TYPE_AUTH & obj->type
  ------------------
  |  |  444|    985|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2848:6): [True: 985, False: 0]
  ------------------
 2849|      0|			|| SC_PKCS15_TYPE_SKEY & obj->type
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2849:7): [True: 0, False: 0]
  ------------------
 2850|    985|			|| SC_PKCS15_TYPE_PRKEY & obj->type) {
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2850:7): [True: 0, False: 0]
  ------------------
 2851|    985|		tmp_buf = sc_mem_secure_alloc(len);
 2852|    985|		obj->content_free = sc_mem_secure_free;
 2853|    985|	} else {
 2854|      0|		tmp_buf = malloc(len);
 2855|      0|	}
 2856|    985|	if (!tmp_buf)
  ------------------
  |  Branch (2856:6): [True: 0, False: 985]
  ------------------
 2857|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2858|       |
 2859|    985|	memcpy(tmp_buf, value, len);
 2860|       |
 2861|    985|	sc_pkcs15_free_object_content(obj);
 2862|       |
 2863|    985|	obj->content.value = tmp_buf;
 2864|    985|	obj->content.len = len;
 2865|       |
 2866|    985|	return SC_SUCCESS;
  ------------------
  |  |   28|    985|#define SC_SUCCESS				0
  ------------------
 2867|    985|}
sc_pkcs15_free_key_params:
 3160|  7.99k|{
 3161|  7.99k|	if (!params)
  ------------------
  |  Branch (3161:6): [True: 0, False: 7.99k]
  ------------------
 3162|      0|		return;
 3163|  7.99k|	if (params->data && params->free_params)
  ------------------
  |  Branch (3163:6): [True: 0, False: 7.99k]
  |  Branch (3163:22): [True: 0, False: 0]
  ------------------
 3164|      0|		params->free_params(params->data);
 3165|  7.99k|	else if (params->data)
  ------------------
  |  Branch (3165:11): [True: 0, False: 7.99k]
  ------------------
 3166|      0|		free(params->data);
 3167|       |
 3168|       |	params->data = NULL;
 3169|  7.99k|}
pkcs15.c:sc_pkcs15_clear_tokeninfo:
  754|  22.7k|{
  755|  22.7k|	if (!tokeninfo)
  ------------------
  |  Branch (755:6): [True: 0, False: 22.7k]
  ------------------
  756|      0|		return;
  757|       |
  758|  22.7k|	free(tokeninfo->label);
  759|  22.7k|	tokeninfo->label = NULL;
  760|  22.7k|	free(tokeninfo->serial_number);
  761|  22.7k|	tokeninfo->serial_number = NULL;
  762|  22.7k|	free(tokeninfo->manufacturer_id);
  763|  22.7k|	tokeninfo->manufacturer_id = NULL;
  764|  22.7k|	free(tokeninfo->last_update.gtime);
  765|  22.7k|	tokeninfo->last_update.gtime = NULL;
  766|  22.7k|	free(tokeninfo->preferred_language);
  767|  22.7k|	tokeninfo->preferred_language = NULL;
  768|  22.7k|	free(tokeninfo->profile_indication.name);
  769|  22.7k|	tokeninfo->profile_indication.name = NULL;
  770|  22.7k|	if (tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (770:6): [True: 22, False: 22.7k]
  ------------------
  771|     22|		unsigned i;
  772|     30|		for (i = 0; i < tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (772:15): [True: 8, False: 22]
  ------------------
  773|      8|			free(tokeninfo->seInfo[i]);
  774|     22|		free(tokeninfo->seInfo);
  775|       |		tokeninfo->seInfo = NULL;
  776|     22|	}
  777|  22.7k|}
pkcs15.c:parse_odf:
  621|     34|{
  622|     34|	const unsigned char *p = buf;
  623|     34|	size_t left = buflen;
  624|     34|	int r, i, type;
  625|     34|	struct sc_path path;
  626|     34|	struct sc_asn1_entry asn1_obj_or_path[] = {
  627|     34|		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  198|     34|#define SC_ASN1_PATH			256
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  165|     34|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  186|     34|#define SC_ASN1_SEQUENCE                16
  ------------------
  628|     34|		{ NULL, 0, 0, 0, NULL, NULL }
  629|     34|	};
  630|     34|	struct sc_asn1_entry asn1_odf[10];
  631|       |
  632|     34|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  633|    340|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (633:14): [True: 306, False: 34]
  ------------------
  634|    306|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  635|    119|	while (left > 0) {
  ------------------
  |  Branch (635:9): [True: 114, False: 5]
  ------------------
  636|    114|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left, &p, &left);
  637|    114|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|    114|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (637:7): [True: 11, False: 103]
  ------------------
  638|     11|			break;
  639|    103|		if (r < 0)
  ------------------
  |  Branch (639:7): [True: 18, False: 85]
  ------------------
  640|     18|			return r;
  641|     85|		type = r;
  642|     85|		if (p15card->file_app) {
  ------------------
  |  Branch (642:7): [True: 85, False: 0]
  ------------------
  643|     85|			r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &path);
  644|     85|			if (r < 0)
  ------------------
  |  Branch (644:8): [True: 0, False: 85]
  ------------------
  645|      0|				return r;
  646|     85|			r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  647|     85|			if (r)
  ------------------
  |  Branch (647:8): [True: 0, False: 85]
  ------------------
  648|      0|				return r;
  649|     85|		}
  650|     85|	}
  651|     16|	return 0;
  652|     34|}
pkcs15.c:sc_dup_app_info:
  908|    422|{
  909|    422|	struct sc_app_info *out = calloc(1, sizeof(struct sc_app_info));
  910|       |
  911|    422|	if (!out)
  ------------------
  |  Branch (911:6): [True: 0, False: 422]
  ------------------
  912|      0|		return NULL;
  913|       |
  914|    422|	memcpy(out, info, sizeof(struct sc_app_info));
  915|       |
  916|    422|	if (info->label) {
  ------------------
  |  Branch (916:6): [True: 18, False: 404]
  ------------------
  917|     18|		out->label = strdup(info->label);
  918|     18|		if (!out->label) {
  ------------------
  |  Branch (918:7): [True: 0, False: 18]
  ------------------
  919|      0|			free(out);
  920|      0|			return NULL;
  921|      0|		}
  922|     18|	} else
  923|    404|		out->label = NULL;
  924|       |
  925|    422|	out->ddo.value = malloc(info->ddo.len);
  926|    422|	if (!out->ddo.value) {
  ------------------
  |  Branch (926:6): [True: 0, False: 422]
  ------------------
  927|      0|		free(out->label);
  928|      0|		free(out);
  929|      0|		return NULL;
  930|      0|	}
  931|    422|	memcpy(out->ddo.value, info->ddo.value, info->ddo.len);
  932|    422|	out->ddo.len = info->ddo.len;
  933|       |
  934|    422|	return out;
  935|    422|}
pkcs15.c:parse_ddo:
  473|     48|{
  474|     48|	struct sc_context *ctx = p15card->card->ctx;
  475|     48|	struct sc_asn1_entry asn1_ddo[7];
  476|     48|	sc_path_t odf_path, ti_path, us_path;
  477|     48|	struct sc_iid iid;
  478|     48|	struct sc_aid aid;
  479|     48|	int r;
  480|       |
  481|     48|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     48|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     48|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     48|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     48|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|       |
  483|     48|	iid.len = sizeof(iid.value);
  484|     48|	aid.len = sizeof(aid.value);
  485|       |
  486|     48|	sc_copy_asn1_entry(c_asn1_ddo, asn1_ddo);
  487|     48|	sc_format_asn1_entry(asn1_ddo + 1, &odf_path, NULL, 0);
  488|     48|	sc_format_asn1_entry(asn1_ddo + 2, &ti_path, NULL, 0);
  489|     48|	sc_format_asn1_entry(asn1_ddo + 3, &us_path, NULL, 0);
  490|     48|	sc_format_asn1_entry(asn1_ddo + 4, iid.value, &iid.len, 0);
  491|     48|	sc_format_asn1_entry(asn1_ddo + 5, aid.value, &aid.len, 0);
  492|       |
  493|     48|	r = sc_asn1_decode(ctx, asn1_ddo, buf, buflen, NULL, NULL);
  494|     48|	LOG_TEST_RET(ctx, r, "DDO parsing failed");
  ------------------
  |  |  174|     48|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     48|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     48|	int _ret = (r); \
  |  |  |  |  168|     48|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  495|       |
  496|     36|	if (asn1_ddo[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|     36|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (496:6): [True: 5, False: 31]
  ------------------
  497|      5|		sc_file_free(p15card->file_odf);
  498|      5|		p15card->file_odf = sc_file_new();
  499|      5|		if (p15card->file_odf == NULL)
  ------------------
  |  Branch (499:7): [True: 0, False: 5]
  ------------------
  500|      0|			goto mem_err;
  501|      5|		p15card->file_odf->path = odf_path;
  502|      5|	}
  503|     36|	if (asn1_ddo[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|     36|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (503:6): [True: 11, False: 25]
  ------------------
  504|     11|		sc_file_free(p15card->file_tokeninfo);
  505|     11|		p15card->file_tokeninfo = sc_file_new();
  506|     11|		if (p15card->file_tokeninfo == NULL)
  ------------------
  |  Branch (506:7): [True: 0, False: 11]
  ------------------
  507|      0|			goto mem_err;
  508|     11|		p15card->file_tokeninfo->path = ti_path;
  509|     11|	}
  510|     36|	if (asn1_ddo[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|     36|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (510:6): [True: 3, False: 33]
  ------------------
  511|      3|		sc_file_free(p15card->file_unusedspace);
  512|      3|		p15card->file_unusedspace = sc_file_new();
  513|      3|		if (p15card->file_unusedspace == NULL)
  ------------------
  |  Branch (513:7): [True: 0, False: 3]
  ------------------
  514|      0|			goto mem_err;
  515|      3|		p15card->file_unusedspace->path = us_path;
  516|      3|	}
  517|     36|	if (asn1_ddo[4].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|     36|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (517:6): [True: 3, False: 33]
  ------------------
  518|      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__
  |  |  ------------------
  ------------------
  519|      3|		memcpy(&p15card->app->ddo.iid, &iid, sizeof(struct sc_iid));
  520|      3|	}
  521|     36|	if (asn1_ddo[5].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  171|     36|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (521:6): [True: 4, False: 32]
  ------------------
  522|      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__
  |  |  ------------------
  ------------------
  523|      4|		memcpy(&p15card->app->ddo.aid, &aid, sizeof(struct sc_aid));
  524|      4|	}
  525|       |
  526|     36|	fix_authentic_ddo(p15card);
  527|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  528|      0|mem_err:
  529|      0|	sc_file_free(p15card->file_odf);
  530|      0|	p15card->file_odf = NULL;
  531|      0|	sc_file_free(p15card->file_tokeninfo);
  532|      0|	p15card->file_tokeninfo = NULL;
  533|      0|	sc_file_free(p15card->file_unusedspace);
  534|      0|	p15card->file_unusedspace = NULL;
  535|      0|	LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|      0|}
pkcs15.c:fix_authentic_ddo:
  459|     36|{
  460|       |	/* AuthentIC v3.2 card has invalid ODF and tokenInfo paths encoded into DDO.
  461|       |	 * Cleanup this attributes -- default values must be OK.
  462|       |	 */
  463|     36|	if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)   {
  ------------------
  |  Branch (463:6): [True: 0, False: 36]
  ------------------
  464|      0|		sc_file_free(p15card->file_odf);
  465|      0|		p15card->file_odf = NULL;
  466|      0|		sc_file_free(p15card->file_tokeninfo);
  467|       |		p15card->file_tokeninfo = NULL;
  468|      0|	}
  469|     36|}
pkcs15.c:__sc_pkcs15_search_objects:
 1458|  2.91k|{
 1459|  2.91k|	struct sc_pkcs15_object *obj = NULL;
 1460|  2.91k|	struct sc_pkcs15_df	*df = NULL;
 1461|  2.91k|	unsigned int	df_mask = 0;
 1462|  2.91k|	size_t		match_count = 0;
 1463|  2.91k|	int r;
 1464|       |
 1465|  2.91k|	if (type)
  ------------------
  |  Branch (1465:6): [True: 2.90k, False: 10]
  ------------------
 1466|  2.90k|		class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
  ------------------
  |  |  449|  2.90k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
 1467|       |
 1468|       |	/* Make sure the class mask we have makes sense */
 1469|  2.91k|	if (class_mask == 0
  ------------------
  |  Branch (1469:6): [True: 0, False: 2.91k]
  ------------------
 1470|  2.91k|			|| (class_mask & ~(
  ------------------
  |  Branch (1470:7): [True: 0, False: 2.91k]
  ------------------
 1471|  2.91k|					SC_PKCS15_SEARCH_CLASS_PRKEY |
  ------------------
  |  |  450|  2.91k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
 1472|  2.91k|					SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|  2.91k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1473|  2.91k|					SC_PKCS15_SEARCH_CLASS_SKEY |
  ------------------
  |  |  452|  2.91k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
 1474|  2.91k|					SC_PKCS15_SEARCH_CLASS_CERT |
  ------------------
  |  |  453|  2.91k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
 1475|  2.91k|					SC_PKCS15_SEARCH_CLASS_DATA |
  ------------------
  |  |  454|  2.91k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1476|  2.91k|					SC_PKCS15_SEARCH_CLASS_AUTH))) {
  ------------------
  |  |  455|  2.91k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
 1477|      0|		LOG_FUNC_RETURN(p15card->card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1478|      0|	}
 1479|       |
 1480|  2.91k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PRKEY)
  ------------------
  |  |  450|  2.91k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  |  Branch (1480:6): [True: 5, False: 2.90k]
  ------------------
 1481|      5|		df_mask |= (1 << SC_PKCS15_PRKDF);
  ------------------
  |  |  488|      5|#define SC_PKCS15_PRKDF			0
  ------------------
 1482|  2.91k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PUBKEY)
  ------------------
  |  |  451|  2.91k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
  |  Branch (1482:6): [True: 0, False: 2.91k]
  ------------------
 1483|      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
  ------------------
 1484|  2.91k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_CERT)
  ------------------
  |  |  453|  2.91k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
  |  Branch (1484:6): [True: 1.79k, False: 1.12k]
  ------------------
 1485|  1.79k|		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  492|  1.79k|#define SC_PKCS15_CDF			4
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  493|  1.79k|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  494|  1.79k|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
 1486|  2.91k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_DATA)
  ------------------
  |  |  454|  2.91k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
  |  Branch (1486:6): [True: 155, False: 2.75k]
  ------------------
 1487|    155|		df_mask |= (1 << SC_PKCS15_DODF);
  ------------------
  |  |  495|    155|#define SC_PKCS15_DODF			7
  ------------------
 1488|  2.91k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_AUTH)
  ------------------
  |  |  455|  2.91k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
  |  Branch (1488:6): [True: 961, False: 1.95k]
  ------------------
 1489|    961|		df_mask |= (1 << SC_PKCS15_AODF);
  ------------------
  |  |  496|    961|#define SC_PKCS15_AODF			8
  ------------------
 1490|  2.91k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_SKEY)
  ------------------
  |  |  452|  2.91k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
  |  Branch (1490:6): [True: 0, False: 2.91k]
  ------------------
 1491|      0|		df_mask |= (1 << SC_PKCS15_SKDF);
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
 1492|       |
 1493|       |	/* Make sure all the DFs we want to search have been
 1494|       |	 * enumerated. */
 1495|  10.6k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (1495:30): [True: 7.77k, False: 2.91k]
  ------------------
 1496|  7.77k|		if (!(df_mask & (1 << df->type)))   {
  ------------------
  |  Branch (1496:7): [True: 5.74k, False: 2.03k]
  ------------------
 1497|  5.74k|			continue;
 1498|  5.74k|		}
 1499|  2.03k|		if (df->enumerated)
  ------------------
  |  Branch (1499:7): [True: 2.02k, False: 10]
  ------------------
 1500|  2.02k|			continue;
 1501|       |		/* Enumerate the DF's, so p15card->obj_list is populated. */
 1502|     10|		if (p15card->ops.parse_df)
  ------------------
  |  Branch (1502:7): [True: 0, False: 10]
  ------------------
 1503|      0|			r = p15card->ops.parse_df(p15card, df);
 1504|     10|		else
 1505|     10|			r = sc_pkcs15_parse_df(p15card, df);
 1506|     10|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|     10|#define SC_SUCCESS				0
  ------------------
  |  Branch (1506:7): [True: 10, False: 0]
  ------------------
 1507|     10|			continue;
 1508|     10|	}
 1509|       |
 1510|       |	/* And now loop over all objects */
 1511|  25.8k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (1511:32): [True: 24.3k, False: 1.49k]
  ------------------
 1512|       |		/* Check object type */
 1513|  24.3k|		if (!(class_mask & SC_PKCS15_TYPE_TO_CLASS(obj->type)))
  ------------------
  |  |  449|  24.3k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
  |  Branch (1513:7): [True: 19.2k, False: 5.13k]
  ------------------
 1514|  19.2k|			continue;
 1515|  5.13k|		if (type != 0
  ------------------
  |  Branch (1515:7): [True: 5.13k, False: 0]
  ------------------
 1516|  5.13k|		 && obj->type != type
  ------------------
  |  Branch (1516:7): [True: 3.39k, False: 1.74k]
  ------------------
 1517|  3.39k|		 && (obj->type & SC_PKCS15_TYPE_CLASS_MASK) != type)
  ------------------
  |  |  416|  3.39k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1517:7): [True: 0, False: 3.39k]
  ------------------
 1518|      0|			continue;
 1519|       |
 1520|       |		/* Potential candidate, apply search function */
 1521|  5.13k|		if (func != NULL && func(obj, func_arg) <= 0)
  ------------------
  |  Branch (1521:7): [True: 3.39k, False: 1.74k]
  |  Branch (1521:23): [True: 1.97k, False: 1.41k]
  ------------------
 1522|  1.97k|			continue;
 1523|       |		/* Okay, we have a match. */
 1524|  3.15k|		match_count++;
 1525|  3.15k|		if (!ret || ret_size <= 0)
  ------------------
  |  Branch (1525:7): [True: 0, False: 3.15k]
  |  Branch (1525:15): [True: 0, False: 3.15k]
  ------------------
 1526|      0|			continue;
 1527|  3.15k|		ret[match_count-1] = obj;
 1528|  3.15k|		if (ret_size <= match_count)
  ------------------
  |  Branch (1528:7): [True: 1.41k, False: 1.74k]
  ------------------
 1529|  1.41k|			break;
 1530|  3.15k|	}
 1531|       |
 1532|  2.91k|	return (int)match_count;
 1533|  2.91k|}
pkcs15.c:compare_obj_key:
 1678|  3.39k|{
 1679|  3.39k|	struct sc_pkcs15_search_key *sk = (struct sc_pkcs15_search_key *) arg;
 1680|       |
 1681|  3.39k|	if (sk->id && !compare_obj_id(obj, sk->id))
  ------------------
  |  Branch (1681:6): [True: 3.39k, False: 0]
  |  Branch (1681:16): [True: 1.97k, False: 1.41k]
  ------------------
 1682|  1.97k|		return 0;
 1683|  1.41k|	if (sk->app_oid && !sc_obj_app_oid(obj, sk->app_oid))
  ------------------
  |  Branch (1683:6): [True: 0, False: 1.41k]
  |  Branch (1683:21): [True: 0, False: 0]
  ------------------
 1684|      0|		return 0;
 1685|  1.41k|	if (sk->usage_mask && !compare_obj_usage(obj, sk->usage_mask, sk->usage_value))
  ------------------
  |  Branch (1685:6): [True: 0, False: 1.41k]
  |  Branch (1685:24): [True: 0, False: 0]
  ------------------
 1686|      0|		return 0;
 1687|  1.41k|	if (sk->flags_mask && !compare_obj_flags(obj, sk->flags_mask, sk->flags_value))
  ------------------
  |  Branch (1687:6): [True: 0, False: 1.41k]
  |  Branch (1687:24): [True: 0, False: 0]
  ------------------
 1688|      0|		return 0;
 1689|  1.41k|	if (sk->match_reference && !compare_obj_reference(obj, sk->reference))
  ------------------
  |  Branch (1689:6): [True: 0, False: 1.41k]
  |  Branch (1689:29): [True: 0, False: 0]
  ------------------
 1690|      0|		return 0;
 1691|  1.41k|	if (sk->path && !compare_obj_path(obj, sk->path))
  ------------------
  |  Branch (1691:6): [True: 0, False: 1.41k]
  |  Branch (1691:18): [True: 0, False: 0]
  ------------------
 1692|      0|		return 0;
 1693|  1.41k|	if (sk->app_label) {
  ------------------
  |  Branch (1693:6): [True: 0, False: 1.41k]
  ------------------
 1694|      0|		if (sk->label && !compare_obj_data_name(obj, sk->app_label, sk->label))
  ------------------
  |  Branch (1694:7): [True: 0, False: 0]
  |  Branch (1694:20): [True: 0, False: 0]
  ------------------
 1695|      0|			return 0;
 1696|  1.41k|	} else {
 1697|  1.41k|		if (sk->label && strncmp(sk->label, obj->label, sizeof(obj->label)) != 0)
  ------------------
  |  Branch (1697:7): [True: 0, False: 1.41k]
  |  Branch (1697:20): [True: 0, False: 0]
  ------------------
 1698|      0|			return 0;
 1699|  1.41k|	}
 1700|       |
 1701|  1.41k|	return 1;
 1702|  1.41k|}
pkcs15.c:compare_obj_id:
 1546|  3.39k|{
 1547|  3.39k|	void *data = obj->data;
 1548|       |
 1549|  3.39k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  3.39k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1549:10): [True: 3.39k, False: 0]
  ------------------
 1550|  1.95k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.95k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1550:2): [True: 1.95k, False: 1.43k]
  ------------------
 1551|  1.95k|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_cert_info *) data)->id, id);
 1552|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1552:2): [True: 0, False: 3.39k]
  ------------------
 1553|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_prkey_info *) data)->id, id);
 1554|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1554:2): [True: 0, False: 3.39k]
  ------------------
 1555|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_pubkey_info *) data)->id, id);
 1556|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (1556:2): [True: 0, False: 3.39k]
  ------------------
 1557|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_skey_info *) data)->id, id);
 1558|  1.43k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  1.43k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1558:2): [True: 1.43k, False: 1.95k]
  ------------------
 1559|  1.43k|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_auth_info *) data)->auth_id, id);
 1560|      0|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (1560:2): [True: 0, False: 3.39k]
  ------------------
 1561|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_data_info *) data)->id, id);
 1562|  3.39k|	}
 1563|      0|	return 0;
 1564|  3.39k|}
pkcs15.c:sc_pkcs15_remove_objects:
 2022|  27.9k|{
 2023|  27.9k|	struct sc_pkcs15_object *cur = NULL, *next = NULL;
 2024|       |
 2025|  27.9k|	if (!p15card || !p15card->obj_list)
  ------------------
  |  Branch (2025:6): [True: 0, False: 27.9k]
  |  Branch (2025:18): [True: 22.2k, False: 5.61k]
  ------------------
 2026|  22.2k|		return;
 2027|  52.7k|	for (cur = p15card->obj_list; cur; cur = next)   {
  ------------------
  |  Branch (2027:32): [True: 47.0k, False: 5.61k]
  ------------------
 2028|  47.0k|		next = cur->next;
 2029|  47.0k|		sc_pkcs15_free_object(cur);
 2030|  47.0k|	}
 2031|       |
 2032|       |	p15card->obj_list = NULL;
 2033|  5.61k|}
pkcs15.c:sc_pkcs15_remove_dfs:
 2103|  27.9k|{
 2104|  27.9k|	struct sc_pkcs15_df *cur = NULL, *next = NULL;
 2105|       |
 2106|  27.9k|	if (!p15card || !p15card->df_list)
  ------------------
  |  Branch (2106:6): [True: 0, False: 27.9k]
  |  Branch (2106:18): [True: 22.2k, False: 5.64k]
  ------------------
 2107|  22.2k|		return;
 2108|       |
 2109|  19.3k|	for (cur = p15card->df_list; cur; cur = next)   {
  ------------------
  |  Branch (2109:31): [True: 13.6k, False: 5.64k]
  ------------------
 2110|  13.6k|		next = cur->next;
 2111|  13.6k|		free(cur);
 2112|  13.6k|	}
 2113|       |
 2114|       |	p15card->df_list = NULL;
 2115|  5.64k|}
pkcs15.c:sc_pkcs15_free_unusedspace:
 2338|  13.0k|{
 2339|  13.0k|	struct sc_pkcs15_unusedspace *cur = NULL, *next = NULL;
 2340|       |
 2341|  13.0k|	if (!p15card || !p15card->unusedspace_list)
  ------------------
  |  Branch (2341:6): [True: 0, False: 13.0k]
  |  Branch (2341:18): [True: 13.0k, False: 0]
  ------------------
 2342|  13.0k|		return;
 2343|      0|	for (cur = p15card->unusedspace_list; cur; cur = next)   {
  ------------------
  |  Branch (2343:40): [True: 0, False: 0]
  ------------------
 2344|      0|		next = cur->next;
 2345|      0|		free(cur);
 2346|      0|	}
 2347|       |
 2348|       |	p15card->unusedspace_list = NULL;
 2349|      0|}
pkcs15.c:decompress_file:
 2478|    363|{
 2479|    363|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    363|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    363|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    363|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    363|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 363]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2480|    363|#ifdef ENABLE_ZLIB
 2481|    363|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|    363|#define SC_SUCCESS				0
  ------------------
 2482|    363|	int method = 0;
 2483|       |
 2484|    363|	if (flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|    363|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2484:6): [True: 0, False: 363]
  ------------------
 2485|      0|		method = COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
 2486|    363|	} else if (flags & SC_FILE_FLAG_COMPRESSED_ZLIB) {
  ------------------
  |  |  231|    363|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2486:13): [True: 0, False: 363]
  ------------------
 2487|      0|		method = COMPRESSION_ZLIB;
  ------------------
  |  |   27|      0|#define COMPRESSION_ZLIB	1
  ------------------
 2488|    363|	} else {
 2489|    363|		method = COMPRESSION_AUTO;
  ------------------
  |  |   26|    363|#define COMPRESSION_AUTO	0
  ------------------
 2490|    363|	}
 2491|       |
 2492|    363|	rv = sc_decompress_alloc(out, outlen, buf, buflen, method);
 2493|    363|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    363|#define SC_SUCCESS				0
  ------------------
  |  Branch (2493:6): [True: 222, False: 141]
  ------------------
 2494|    222|		sc_log(card->ctx,  "Decompression failed: %d", rv);
  ------------------
  |  |   71|    222|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2495|    222|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|    222|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    222|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    222|	int _ret = r; \
  |  |  |  |  155|    222|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 222, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    222|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    222|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 222, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    222|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    222|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    222|	return _ret; \
  |  |  |  |  163|    222|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2496|    222|	}
 2497|    141|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    141|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    141|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    141|	int _ret = r; \
  |  |  |  |  155|    141|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 141, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    141|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 141]
  |  |  |  |  ------------------
  |  |  |  |  157|    141|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    141|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    141|	return _ret; \
  |  |  |  |  163|    141|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2498|       |#else
 2499|       |	sc_log(card->ctx, "Compression not supported, no zlib");
 2500|       |	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2501|       |#endif
 2502|    141|}

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

card-epass2003.c:_sc_evp_cipher:
  103|    983|{
  104|       |	return EVP_CIPHER_fetch(ctx->libctx, algorithm, NULL);
  105|    983|}
card-epass2003.c:sc_evp_cipher_free:
  109|    983|{
  110|    983|	EVP_CIPHER_free(cipher);
  111|    983|}

sc_get_version:
   58|  16.1k|{
   59|  16.1k|    return sc_version;
   60|  16.1k|}
sc_hex_to_bin:
   63|   403k|{
   64|   403k|	const char *sc_hex_to_bin_separators = " :";
   65|   403k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (65:6): [True: 244, False: 403k]
  |  Branch (65:20): [True: 0, False: 403k]
  |  Branch (65:35): [True: 0, False: 403k]
  ------------------
   66|    244|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    244|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   67|    244|	}
   68|       |
   69|   403k|	int byte_needs_nibble = 0;
   70|   403k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   403k|#define SC_SUCCESS				0
  ------------------
   71|   403k|	size_t left = *outlen;
   72|   403k|	u8 byte = 0;
   73|  6.26M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (73:9): [True: 5.86M, False: 403k]
  |  Branch (73:24): [True: 5.86M, False: 0]
  ------------------
   74|  5.86M|		char c = *in++;
   75|  5.86M|		u8 nibble;
   76|  5.86M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (76:12): [True: 5.86M, False: 0]
  |  Branch (76:24): [True: 3.16M, False: 2.69M]
  ------------------
   77|  3.16M|			nibble = c - '0';
   78|  2.69M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (78:12): [True: 540k, False: 2.15M]
  |  Branch (78:24): [True: 540k, False: 0]
  ------------------
   79|   540k|			nibble = c - 'a' + 10;
   80|  2.15M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (80:12): [True: 729k, False: 1.42M]
  |  Branch (80:24): [True: 729k, False: 0]
  ------------------
   81|   729k|			nibble = c - 'A' + 10;
   82|  1.42M|		else {
   83|  1.42M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (83:8): [True: 1.42M, False: 0]
  ------------------
   84|  1.42M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (84:9): [True: 0, False: 1.42M]
  ------------------
   85|      0|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   86|      0|					goto err;
   87|      0|				}
   88|  1.42M|				continue;
   89|  1.42M|			}
   90|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   91|      0|			goto err;
   92|  1.42M|		}
   93|       |
   94|  4.43M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (94:7): [True: 2.21M, False: 2.22M]
  ------------------
   95|  2.21M|			byte |= nibble;
   96|  2.21M|			*out++ = (u8) byte;
   97|  2.21M|			left--;
   98|  2.21M|			byte_needs_nibble = 0;
   99|  2.22M|		} else {
  100|  2.22M|			byte  = nibble << 4;
  101|  2.22M|			byte_needs_nibble = 1;
  102|  2.22M|		}
  103|  4.43M|	}
  104|       |
  105|   403k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (105:6): [True: 14.7k, False: 388k]
  |  Branch (105:25): [True: 8.58k, False: 6.21k]
  |  Branch (105:51): [True: 8.58k, False: 0]
  ------------------
  106|       |		/* no output written so far, but we have a valid nibble in the upper
  107|       |		 * bits. Allow this special case. */
  108|  8.58k|		*out = (u8) byte>>4;
  109|  8.58k|		left--;
  110|  8.58k|		byte_needs_nibble = 0;
  111|  8.58k|	}
  112|       |
  113|       |	/* for ease of implementation we only accept completely hexed bytes. */
  114|   403k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (114:6): [True: 0, False: 403k]
  ------------------
  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|   403k|	while (*in != '\0') {
  ------------------
  |  Branch (120:9): [True: 0, False: 403k]
  ------------------
  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|   403k|	if (*in != '\0') {
  ------------------
  |  Branch (125:6): [True: 0, False: 403k]
  ------------------
  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|   403k|err:
  131|   403k|	*outlen -= left;
  132|   403k|	return r;
  133|   403k|}
sc_bin_to_hex:
  137|   340k|{
  138|   340k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (138:6): [True: 0, False: 340k]
  |  Branch (138:20): [True: 0, False: 340k]
  ------------------
  139|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  140|      0|	}
  141|       |
  142|   340k|	if (in_sep > 0) {
  ------------------
  |  Branch (142:6): [True: 336k, False: 3.99k]
  ------------------
  143|   336k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (143:7): [True: 0, False: 336k]
  |  Branch (143:29): [True: 0, False: 336k]
  ------------------
  144|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  145|   336k|	} else {
  146|  3.99k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (146:7): [True: 17, False: 3.98k]
  ------------------
  147|     17|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     17|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  148|  3.99k|	}
  149|       |
  150|   340k|	const char hex[] = "0123456789abcdef";
  151|  4.31M|	while (in_len) {
  ------------------
  |  Branch (151:9): [True: 3.97M, False: 340k]
  ------------------
  152|  3.97M|		unsigned char value = *in++;
  153|  3.97M|		*out++ = hex[(value >> 4) & 0xF];
  154|  3.97M|		*out++ = hex[ value       & 0xF];
  155|  3.97M|		in_len--;
  156|  3.97M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (156:7): [True: 3.72M, False: 250k]
  |  Branch (156:17): [True: 3.70M, False: 18.2k]
  ------------------
  157|  3.70M|			*out++ = (char)in_sep;
  158|  3.97M|	}
  159|   340k|	*out = '\0';
  160|       |
  161|   340k|	return SC_SUCCESS;
  ------------------
  |  |   28|   340k|#define SC_SUCCESS				0
  ------------------
  162|   340k|}
ulong2bebytes:
  188|   136k|{
  189|   136k|	if (buf != NULL) {
  ------------------
  |  Branch (189:6): [True: 136k, False: 0]
  ------------------
  190|   136k|		buf[3] = (u8) (x & 0xff);
  191|   136k|		buf[2] = (u8) ((x >> 8) & 0xff);
  192|   136k|		buf[1] = (u8) ((x >> 16) & 0xff);
  193|   136k|		buf[0] = (u8) ((x >> 24) & 0xff);
  194|   136k|	}
  195|   136k|	return buf;
  196|   136k|}
ushort2bebytes:
  199|    436|{
  200|    436|	if (buf != NULL) {
  ------------------
  |  Branch (200:6): [True: 436, False: 0]
  ------------------
  201|    436|		buf[1] = (u8) (x & 0xff);
  202|    436|		buf[0] = (u8) ((x >> 8) & 0xff);
  203|    436|	}
  204|    436|	return buf;
  205|    436|}
bebytes2ulong:
  208|   187k|{
  209|   187k|	if (buf == NULL)
  ------------------
  |  Branch (209:6): [True: 0, False: 187k]
  ------------------
  210|      0|		return 0UL;
  211|   187k|	return (unsigned long)buf[0] << 24
  212|   187k|		| (unsigned long)buf[1] << 16
  213|   187k|		| (unsigned long)buf[2] << 8
  214|   187k|		| (unsigned long)buf[3];
  215|   187k|}
bebytes2ushort:
  218|   194k|{
  219|   194k|	if (buf == NULL)
  ------------------
  |  Branch (219:6): [True: 0, False: 194k]
  ------------------
  220|      0|		return 0U;
  221|   194k|	return (unsigned short)buf[0] << 8
  222|   194k|		| (unsigned short)buf[1];
  223|   194k|}
lebytes2ushort:
  226|  8.01k|{
  227|  8.01k|	if (buf == NULL)
  ------------------
  |  Branch (227:6): [True: 0, False: 8.01k]
  ------------------
  228|      0|		return 0U;
  229|  8.01k|	return (unsigned short)buf[1] << 8
  230|  8.01k|		| (unsigned short)buf[0];
  231|  8.01k|}
lebytes2ulong:
  234|    360|{
  235|    360|	if (buf == NULL)
  ------------------
  |  Branch (235:6): [True: 0, False: 360]
  ------------------
  236|      0|		return 0UL;
  237|    360|	return (unsigned long)buf[3] << 24
  238|    360|		| (unsigned long)buf[2] << 16
  239|    360|		| (unsigned long)buf[1] << 8
  240|    360|		| (unsigned long)buf[0];
  241|    360|}
set_string:
  244|  15.3k|{
  245|  15.3k|	if (strp == NULL) {
  ------------------
  |  Branch (245:6): [True: 0, False: 15.3k]
  ------------------
  246|      0|		return;
  247|      0|	}
  248|       |
  249|  15.3k|	free(*strp);
  250|  15.3k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (250:10): [True: 15.3k, False: 0]
  ------------------
  251|  15.3k|}
sc_init_oid:
  254|  61.6k|{
  255|  61.6k|	int ii;
  256|       |
  257|  61.6k|	if (!oid)
  ------------------
  |  Branch (257:6): [True: 0, False: 61.6k]
  ------------------
  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: 986k, False: 61.6k]
  ------------------
  260|   986k|		oid->value[ii] = -1;
  261|  61.6k|}
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|   246k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   246k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (275:13): [True: 246k, False: 0]
  ------------------
  276|   246k|		oid->value[ii] = (int)strtol(p, &q, 10);
  277|   246k|		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|  89.1k|{
  299|  89.1k|	int i;
  300|       |
  301|  89.1k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (301:6): [True: 0, False: 89.1k]
  |  Branch (301:22): [True: 0, False: 89.1k]
  ------------------
  302|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  303|      0|	}
  304|       |
  305|   227k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|   227k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (305:14): [True: 227k, False: 0]
  ------------------
  306|   227k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (306:7): [True: 86.3k, False: 140k]
  ------------------
  307|  86.3k|			return 0;
  308|   140k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (308:7): [True: 2.87k, False: 138k]
  ------------------
  309|  2.87k|			break;
  310|   140k|	}
  311|       |
  312|  2.87k|	return 1;
  313|  89.1k|}
sc_valid_oid:
  317|  28.7k|{
  318|  28.7k|	int ii;
  319|       |
  320|  28.7k|	if (!oid)
  ------------------
  |  Branch (320:6): [True: 0, False: 28.7k]
  ------------------
  321|      0|		return 0;
  322|  28.7k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (322:6): [True: 0, False: 28.7k]
  |  Branch (322:29): [True: 0, False: 28.7k]
  ------------------
  323|      0|		return 0;
  324|  28.7k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (324:6): [True: 0, False: 28.7k]
  |  Branch (324:27): [True: 0, False: 28.7k]
  ------------------
  325|      0|		return 0;
  326|  28.7k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  28.7k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (326:12): [True: 28.7k, False: 0]
  ------------------
  327|  28.7k|		if (oid->value[ii])
  ------------------
  |  Branch (327:7): [True: 28.7k, False: 0]
  ------------------
  328|  28.7k|			break;
  329|  28.7k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  28.7k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (329:6): [True: 0, False: 28.7k]
  ------------------
  330|      0|		return 0;
  331|  28.7k|	return 1;
  332|  28.7k|}
sc_path_set:
  354|  25.1k|{
  355|  25.1k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  25.1k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (355:6): [True: 0, False: 25.1k]
  |  Branch (355:22): [True: 0, False: 25.1k]
  |  Branch (355:36): [True: 0, False: 25.1k]
  |  Branch (355:51): [True: 0, False: 25.1k]
  ------------------
  356|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  357|       |
  358|  25.1k|	memset(path, 0, sizeof(*path));
  359|  25.1k|	memcpy(path->value, id, id_len);
  360|  25.1k|	path->len   = id_len;
  361|  25.1k|	path->type  = type;
  362|  25.1k|	path->index = idx;
  363|  25.1k|	path->count = count;
  364|       |
  365|  25.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  25.1k|#define SC_SUCCESS				0
  ------------------
  366|  25.1k|}
sc_format_path:
  369|   178k|{
  370|   178k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   178k|#define SC_PATH_TYPE_PATH		2
  ------------------
  371|       |
  372|   178k|	if (path) {
  ------------------
  |  Branch (372:6): [True: 178k, False: 0]
  ------------------
  373|   178k|		memset(path, 0, sizeof(*path));
  374|   178k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (374:7): [True: 43, False: 178k]
  |  Branch (374:22): [True: 0, False: 178k]
  ------------------
  375|     43|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     43|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  376|     43|			str++;
  377|     43|		}
  378|   178k|		path->len = sizeof(path->value);
  379|   178k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (379:7): [True: 178k, False: 0]
  ------------------
  380|   178k|			path->type = type;
  381|   178k|		}
  382|   178k|		path->count = -1;
  383|   178k|	}
  384|   178k|}
sc_append_path_id:
  392|  45.7k|{
  393|  45.7k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  45.7k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (393:6): [True: 1, False: 45.7k]
  ------------------
  394|      1|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  395|  45.7k|	memcpy(dest->value + dest->len, id, idlen);
  396|  45.7k|	dest->len += idlen;
  397|  45.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  45.7k|#define SC_SUCCESS				0
  ------------------
  398|  45.7k|}
sc_append_file_id:
  401|  45.7k|{
  402|  45.7k|	u8 id[2] = { fid >> 8, fid & 0xff };
  403|       |
  404|  45.7k|	return sc_append_path_id(dest, id, 2);
  405|  45.7k|}
sc_concatenate_path:
  408|  20.3k|{
  409|  20.3k|	sc_path_t tpath;
  410|       |
  411|  20.3k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (411:6): [True: 0, False: 20.3k]
  |  Branch (411:19): [True: 0, False: 20.3k]
  |  Branch (411:33): [True: 0, False: 20.3k]
  ------------------
  412|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  413|       |
  414|  20.3k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  40.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  20.3k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (414:6): [True: 0, False: 20.3k]
  |  Branch (414:42): [True: 0, False: 20.3k]
  ------------------
  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|  20.3k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  20.3k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (418:6): [True: 3, False: 20.3k]
  ------------------
  419|      3|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  420|       |
  421|  20.3k|	memset(&tpath, 0, sizeof(sc_path_t));
  422|  20.3k|	memcpy(tpath.value, p1->value, p1->len);
  423|  20.3k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  424|  20.3k|	tpath.len  = p1->len + p2->len;
  425|  20.3k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  20.3k|#define SC_PATH_TYPE_PATH		2
  ------------------
  426|       |	/* use 'index' and 'count' entry of the second path object */
  427|  20.3k|	tpath.index = p2->index;
  428|  20.3k|	tpath.count = p2->count;
  429|       |	/* the result is currently always as path */
  430|  20.3k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  20.3k|#define SC_PATH_TYPE_PATH		2
  ------------------
  431|       |
  432|  20.3k|	*d = tpath;
  433|       |
  434|  20.3k|	return SC_SUCCESS;
  ------------------
  |  |   28|  20.3k|#define SC_SUCCESS				0
  ------------------
  435|  20.3k|}
sc_print_path:
  438|   248k|{
  439|   248k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  440|       |
  441|   248k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   248k|#define SC_SUCCESS				0
  ------------------
  |  Branch (441:6): [True: 0, False: 248k]
  ------------------
  442|      0|		buffer[0] = '\0';
  443|       |
  444|   248k|	return buffer;
  445|   248k|}
sc_path_print:
  448|   357k|{
  449|   357k|	size_t i;
  450|       |
  451|   357k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (451:6): [True: 0, False: 357k]
  |  Branch (451:21): [True: 0, False: 357k]
  ------------------
  452|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  453|       |
  454|   357k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (454:6): [True: 653, False: 356k]
  ------------------
  455|    653|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|    653|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  456|       |
  457|   356k|	buf[0] = '\0';
  458|   356k|	if (path->aid.len)   {
  ------------------
  |  Branch (458:6): [True: 146k, False: 209k]
  ------------------
  459|  1.18M|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (459:15): [True: 1.03M, False: 146k]
  ------------------
  460|  1.03M|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  461|   146k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  462|   146k|	}
  463|       |
  464|  1.38M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (464:14): [True: 1.02M, False: 356k]
  ------------------
  465|  1.02M|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  466|   356k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   209k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (466:6): [True: 209k, False: 146k]
  |  Branch (466:24): [True: 31.5k, False: 178k]
  ------------------
  467|  31.5k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  468|       |
  469|   356k|	return SC_SUCCESS;
  ------------------
  |  |   28|   356k|#define SC_SUCCESS				0
  ------------------
  470|   357k|}
sc_compare_path:
  473|  19.4k|{
  474|  19.4k|	return path1->len == path2->len
  ------------------
  |  Branch (474:9): [True: 16.3k, False: 3.07k]
  ------------------
  475|  16.3k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (475:6): [True: 83, False: 16.2k]
  ------------------
  476|  19.4k|}
sc_compare_path_prefix:
  479|  14.4k|{
  480|  14.4k|	sc_path_t tpath;
  481|       |
  482|  14.4k|	if (prefix->len > path->len)
  ------------------
  |  Branch (482:6): [True: 25, False: 14.4k]
  ------------------
  483|     25|		return 0;
  484|       |
  485|  14.4k|	tpath     = *path;
  486|  14.4k|	tpath.len = prefix->len;
  487|       |
  488|  14.4k|	return sc_compare_path(&tpath, prefix);
  489|  14.4k|}
sc_get_mf_path:
  492|  18.5k|{
  493|  18.5k|	static const sc_path_t mf_path = {
  494|  18.5k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  495|  18.5k|		0,
  496|  18.5k|		0,
  497|  18.5k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  18.5k|#define SC_PATH_TYPE_PATH		2
  ------------------
  498|  18.5k|		{{0},0}
  499|  18.5k|	};
  500|  18.5k|	return &mf_path;
  501|  18.5k|}
sc_file_add_acl_entry:
  505|   162k|{
  506|   162k|	sc_acl_entry_t *p, *_new;
  507|       |
  508|   162k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   162k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (508:6): [True: 0, False: 162k]
  |  Branch (508:22): [True: 0, False: 162k]
  ------------------
  509|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  510|      0|	}
  511|       |
  512|   162k|	switch (method) {
  513|  38.7k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  38.7k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (513:2): [True: 38.7k, False: 123k]
  ------------------
  514|  38.7k|		sc_file_clear_acl_entries(file, operation);
  515|  38.7k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  516|  38.7k|		return SC_SUCCESS;
  ------------------
  |  |   28|  38.7k|#define SC_SUCCESS				0
  ------------------
  517|  7.49k|	case SC_AC_NONE:
  ------------------
  |  |  150|  7.49k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (517:2): [True: 7.49k, False: 154k]
  ------------------
  518|  7.49k|		sc_file_clear_acl_entries(file, operation);
  519|  7.49k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  520|  7.49k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.49k|#define SC_SUCCESS				0
  ------------------
  521|  2.77k|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|  2.77k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (521:2): [True: 2.77k, False: 159k]
  ------------------
  522|  2.77k|		sc_file_clear_acl_entries(file, operation);
  523|  2.77k|		file->acl[operation] = (sc_acl_entry_t *) 3;
  524|  2.77k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.77k|#define SC_SUCCESS				0
  ------------------
  525|   113k|	default:
  ------------------
  |  Branch (525:2): [True: 113k, False: 49.0k]
  ------------------
  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|   113k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (529:7): [True: 15, False: 112k]
  ------------------
  530|     15|			return SC_SUCCESS;
  ------------------
  |  |   28|     15|#define SC_SUCCESS				0
  ------------------
  531|   112k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (531:7): [True: 942, False: 112k]
  ------------------
  532|   112k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (532:7): [True: 16, False: 112k]
  ------------------
  533|    958|			file->acl[operation] = NULL;
  534|   162k|	}
  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|   140k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (538:33): [True: 29.6k, False: 110k]
  ------------------
  539|  29.6k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (539:7): [True: 26.8k, False: 2.72k]
  |  Branch (539:32): [True: 2.50k, False: 24.3k]
  ------------------
  540|  2.50k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.50k|#define SC_SUCCESS				0
  ------------------
  541|  29.6k|	}
  542|       |
  543|   110k|	_new = malloc(sizeof(sc_acl_entry_t));
  544|   110k|	if (_new == NULL)
  ------------------
  |  Branch (544:6): [True: 0, False: 110k]
  ------------------
  545|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  546|   110k|	_new->method = method;
  547|   110k|	_new->key_ref = (unsigned)key_ref;
  548|   110k|	_new->next = NULL;
  549|       |
  550|   110k|	p = file->acl[operation];
  551|   110k|	if (p == NULL) {
  ------------------
  |  Branch (551:6): [True: 105k, False: 5.29k]
  ------------------
  552|   105k|		file->acl[operation] = _new;
  553|   105k|		return SC_SUCCESS;
  ------------------
  |  |   28|   105k|#define SC_SUCCESS				0
  ------------------
  554|   105k|	}
  555|  25.0k|	while (p->next != NULL)
  ------------------
  |  Branch (555:9): [True: 19.7k, False: 5.29k]
  ------------------
  556|  19.7k|		p = p->next;
  557|  5.29k|	p->next = _new;
  558|       |
  559|  5.29k|	return SC_SUCCESS;
  ------------------
  |  |   28|  5.29k|#define SC_SUCCESS				0
  ------------------
  560|   110k|}
sc_file_get_acl_entry:
  564|   499k|{
  565|   499k|	sc_acl_entry_t *p;
  566|   499k|	static const sc_acl_entry_t e_never = {
  567|   499k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   499k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   499k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  568|   499k|	};
  569|   499k|	static const sc_acl_entry_t e_none = {
  570|   499k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   499k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   499k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  571|   499k|	};
  572|   499k|	static const sc_acl_entry_t e_unknown = {
  573|   499k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   499k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   499k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  574|   499k|	};
  575|       |
  576|   499k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   499k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (576:6): [True: 0, False: 499k]
  |  Branch (576:22): [True: 0, False: 499k]
  ------------------
  577|      0|		return NULL;
  578|      0|	}
  579|       |
  580|   499k|	p = file->acl[operation];
  581|   499k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (581:6): [True: 1.23k, False: 497k]
  ------------------
  582|  1.23k|		return &e_never;
  583|   497k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (583:6): [True: 1.13k, False: 496k]
  ------------------
  584|  1.13k|		return &e_none;
  585|   496k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (585:6): [True: 1.13k, False: 495k]
  ------------------
  586|  1.13k|		return &e_unknown;
  587|       |
  588|   495k|	return file->acl[operation];
  589|   496k|}
sc_file_clear_acl_entries:
  592|  3.37M|{
  593|  3.37M|	sc_acl_entry_t *e;
  594|       |
  595|  3.37M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  3.37M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (595:6): [True: 0, False: 3.37M]
  |  Branch (595:22): [True: 0, False: 3.37M]
  ------------------
  596|      0|		return;
  597|      0|	}
  598|       |
  599|  3.37M|	e = file->acl[operation];
  600|  3.37M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (600:6): [True: 38.7k, False: 3.34M]
  ------------------
  601|  3.34M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (601:6): [True: 6.55k, False: 3.33M]
  ------------------
  602|  3.33M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (602:6): [True: 2.76k, False: 3.33M]
  ------------------
  603|  48.0k|		file->acl[operation] = NULL;
  604|  48.0k|		return;
  605|  48.0k|	}
  606|       |
  607|  3.44M|	while (e != NULL) {
  ------------------
  |  Branch (607:9): [True: 110k, False: 3.33M]
  ------------------
  608|   110k|		sc_acl_entry_t *tmp = e->next;
  609|   110k|		free(e);
  610|   110k|		e = tmp;
  611|   110k|	}
  612|       |	file->acl[operation] = NULL;
  613|  3.33M|}
sc_file_new:
  616|   107k|{
  617|   107k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  618|   107k|	if (file == NULL)
  ------------------
  |  Branch (618:6): [True: 0, False: 107k]
  ------------------
  619|      0|		return NULL;
  620|       |
  621|   107k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   56|   107k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  622|   107k|	return file;
  623|   107k|}
sc_file_free:
  626|   281k|{
  627|   281k|	unsigned int i;
  628|   281k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (628:6): [True: 174k, False: 107k]
  |  Branch (628:22): [True: 0, False: 107k]
  ------------------
  629|   174k|		return;
  630|   107k|	file->magic = 0;
  631|  3.43M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  3.43M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (631:14): [True: 3.32M, False: 107k]
  ------------------
  632|  3.32M|		sc_file_clear_acl_entries(file, i);
  633|   107k|	if (file->sec_attr)
  ------------------
  |  Branch (633:6): [True: 1.31k, False: 106k]
  ------------------
  634|  1.31k|		free(file->sec_attr);
  635|   107k|	if (file->prop_attr)
  ------------------
  |  Branch (635:6): [True: 820, False: 106k]
  ------------------
  636|    820|		free(file->prop_attr);
  637|   107k|	if (file->type_attr)
  ------------------
  |  Branch (637:6): [True: 2.29k, False: 105k]
  ------------------
  638|  2.29k|		free(file->type_attr);
  639|   107k|	if (file->encoded_content)
  ------------------
  |  Branch (639:6): [True: 0, False: 107k]
  ------------------
  640|      0|		free(file->encoded_content);
  641|   107k|	free(file);
  642|   107k|}
sc_file_dup:
  645|  16.0k|{
  646|  16.0k|	sc_file_t *newf;
  647|  16.0k|	const sc_acl_entry_t *e;
  648|  16.0k|	unsigned int op;
  649|       |
  650|  16.0k|	if (!dest)
  ------------------
  |  Branch (650:6): [True: 0, False: 16.0k]
  ------------------
  651|      0|		return;
  652|  16.0k|	*dest = NULL;
  653|  16.0k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (653:6): [True: 0, False: 16.0k]
  ------------------
  654|      0|		return;
  655|  16.0k|	newf = sc_file_new();
  656|  16.0k|	if (newf == NULL)
  ------------------
  |  Branch (656:6): [True: 0, False: 16.0k]
  ------------------
  657|      0|		return;
  658|  16.0k|	*dest = newf;
  659|       |
  660|  16.0k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  661|  16.0k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  662|  16.0k|	newf->namelen = src->namelen;
  663|  16.0k|	newf->type    = src->type;
  664|  16.0k|	newf->shareable    = src->shareable;
  665|  16.0k|	newf->ef_structure = src->ef_structure;
  666|  16.0k|	newf->size    = src->size;
  667|  16.0k|	newf->id      = src->id;
  668|  16.0k|	newf->status  = src->status;
  669|   514k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   514k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (669:15): [True: 498k, False: 16.0k]
  ------------------
  670|   498k|		newf->acl[op] = NULL;
  671|   498k|		e = sc_file_get_acl_entry(src, op);
  672|   498k|		if (e != NULL) {
  ------------------
  |  Branch (672:7): [True: 13.2k, False: 485k]
  ------------------
  673|  13.2k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (673:8): [True: 0, False: 13.2k]
  ------------------
  674|      0|				goto err;
  675|  13.2k|		}
  676|   498k|	}
  677|  16.0k|	newf->record_length = src->record_length;
  678|  16.0k|	newf->record_count  = src->record_count;
  679|       |
  680|  16.0k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (680:6): [True: 0, False: 16.0k]
  ------------------
  681|      0|		goto err;
  682|  16.0k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (682:6): [True: 0, False: 16.0k]
  ------------------
  683|      0|		goto err;
  684|  16.0k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (684:6): [True: 0, False: 16.0k]
  ------------------
  685|      0|		goto err;
  686|  16.0k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (686:6): [True: 0, False: 16.0k]
  ------------------
  687|      0|		goto err;
  688|  16.0k|	return;
  689|  16.0k|err:
  690|      0|	sc_file_free(newf);
  691|       |	*dest = NULL;
  692|      0|}
sc_file_set_sec_attr:
  696|  17.6k|{
  697|  17.6k|	u8 *tmp;
  698|  17.6k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (698:6): [True: 0, False: 17.6k]
  ------------------
  699|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  700|      0|	}
  701|       |
  702|  17.6k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (702:6): [True: 15.9k, False: 1.71k]
  |  Branch (702:26): [True: 270, False: 1.44k]
  ------------------
  703|  16.1k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (703:7): [True: 71, False: 16.1k]
  ------------------
  704|     71|			free(file->sec_attr);
  705|  16.1k|		file->sec_attr = NULL;
  706|  16.1k|		file->sec_attr_len = 0;
  707|  16.1k|		return 0;
  708|  16.1k|	 }
  709|  1.44k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  710|  1.44k|	if (!tmp) {
  ------------------
  |  Branch (710:6): [True: 0, False: 1.44k]
  ------------------
  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.44k|	file->sec_attr = tmp;
  718|  1.44k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  719|  1.44k|	file->sec_attr_len = sec_attr_len;
  720|       |
  721|  1.44k|	return 0;
  722|  1.44k|}
sc_file_set_prop_attr:
  726|  17.4k|{
  727|  17.4k|	u8 *tmp;
  728|  17.4k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (728:6): [True: 0, False: 17.4k]
  ------------------
  729|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  730|      0|	}
  731|       |
  732|  17.4k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (732:6): [True: 15.9k, False: 1.44k]
  |  Branch (732:27): [True: 440, False: 1.00k]
  ------------------
  733|  16.4k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (733:7): [True: 95, False: 16.3k]
  ------------------
  734|     95|			free(file->prop_attr);
  735|  16.4k|		file->prop_attr = NULL;
  736|  16.4k|		file->prop_attr_len = 0;
  737|  16.4k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.4k|#define SC_SUCCESS				0
  ------------------
  738|  16.4k|	 }
  739|  1.00k|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  740|  1.00k|	if (!tmp) {
  ------------------
  |  Branch (740:6): [True: 0, False: 1.00k]
  ------------------
  741|      0|		if (file->prop_attr)
  ------------------
  |  Branch (741:7): [True: 0, False: 0]
  ------------------
  742|      0|			free(file->prop_attr);
  743|      0|		file->prop_attr = NULL;
  744|      0|		file->prop_attr_len = 0;
  745|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  746|      0|	}
  747|  1.00k|	file->prop_attr = tmp;
  748|  1.00k|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  749|  1.00k|	file->prop_attr_len = prop_attr_len;
  750|       |
  751|  1.00k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.00k|#define SC_SUCCESS				0
  ------------------
  752|  1.00k|}
sc_file_set_type_attr:
  756|  18.0k|{
  757|  18.0k|	u8 *tmp;
  758|  18.0k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (758:6): [True: 0, False: 18.0k]
  ------------------
  759|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  760|      0|	}
  761|       |
  762|  18.0k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (762:6): [True: 15.2k, False: 2.73k]
  |  Branch (762:27): [True: 0, False: 2.73k]
  ------------------
  763|  15.2k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (763:7): [True: 0, False: 15.2k]
  ------------------
  764|      0|			free(file->type_attr);
  765|  15.2k|		file->type_attr = NULL;
  766|  15.2k|		file->type_attr_len = 0;
  767|  15.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  15.2k|#define SC_SUCCESS				0
  ------------------
  768|  15.2k|	 }
  769|  2.73k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  770|  2.73k|	if (!tmp) {
  ------------------
  |  Branch (770:6): [True: 0, False: 2.73k]
  ------------------
  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.73k|	file->type_attr = tmp;
  778|  2.73k|	memcpy(file->type_attr, type_attr, type_attr_len);
  779|  2.73k|	file->type_attr_len = type_attr_len;
  780|       |
  781|  2.73k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.73k|#define SC_SUCCESS				0
  ------------------
  782|  2.73k|}
sc_file_set_content:
  787|  16.0k|{
  788|  16.0k|	u8 *tmp;
  789|  16.0k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (789:6): [True: 0, False: 16.0k]
  ------------------
  790|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  791|      0|	}
  792|       |
  793|  16.0k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (793:6): [True: 16.0k, False: 0]
  |  Branch (793:25): [True: 0, False: 0]
  ------------------
  794|  16.0k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (794:7): [True: 0, False: 16.0k]
  ------------------
  795|      0|			free(file->encoded_content);
  796|  16.0k|		file->encoded_content = NULL;
  797|  16.0k|		file->encoded_content_len = 0;
  798|  16.0k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.0k|#define SC_SUCCESS				0
  ------------------
  799|  16.0k|	}
  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|   192k|int sc_file_valid(const sc_file_t *file) {
  819|   192k|	if (file == NULL)
  ------------------
  |  Branch (819:6): [True: 0, False: 192k]
  ------------------
  820|      0|		return 0;
  821|   192k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   56|   192k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  822|   192k|}
_sc_parse_atr:
  825|  16.1k|{
  826|  16.1k|	u8 *p = reader->atr.value;
  827|  16.1k|	int atr_len = (int) reader->atr.len;
  828|  16.1k|	int n_hist, x;
  829|  16.1k|	int tx[4] = {-1, -1, -1, -1};
  830|  16.1k|	int i, FI, DI;
  831|  16.1k|	const int Fi_table[] = {
  832|  16.1k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  833|  16.1k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  834|  16.1k|	const int f_table[] = {
  835|  16.1k|		40, 50, 60, 80, 120, 160, 200, -1,
  836|  16.1k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  837|  16.1k|	const int Di_table[] = {
  838|  16.1k|		-1, 1, 2, 4, 8, 16, 32, -1,
  839|  16.1k|		12, 20, -1, -1, -1, -1, -1, -1 };
  840|       |
  841|  16.1k|	reader->atr_info.hist_bytes_len = 0;
  842|  16.1k|	reader->atr_info.hist_bytes = NULL;
  843|       |
  844|  16.1k|	if (atr_len == 0) {
  ------------------
  |  Branch (844:6): [True: 2.79k, False: 13.3k]
  ------------------
  845|  2.79k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  2.79k|#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|  2.79k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.79k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  847|  2.79k|	}
  848|       |
  849|  13.3k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (849:6): [True: 1.31k, False: 12.0k]
  |  Branch (849:22): [True: 1.24k, False: 70]
  ------------------
  850|  1.24k|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  851|  1.24k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.24k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  852|  1.24k|	}
  853|  12.0k|	n_hist = p[1] & 0x0F;
  854|  12.0k|	x = p[1] >> 4;
  855|  12.0k|	p += 2;
  856|  12.0k|	atr_len -= 2;
  857|  60.2k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (857:14): [True: 48.2k, False: 12.0k]
  |  Branch (857:23): [True: 48.1k, False: 56]
  ------------------
  858|  48.1k|                if (x & (1 << i)) {
  ------------------
  |  Branch (858:21): [True: 32.7k, False: 15.4k]
  ------------------
  859|  32.7k|                        tx[i] = *p;
  860|  32.7k|                        p++;
  861|  32.7k|                        atr_len--;
  862|  32.7k|                } else
  863|  15.4k|                        tx[i] = -1;
  864|  48.1k|        }
  865|  12.0k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (865:6): [True: 10.0k, False: 1.98k]
  ------------------
  866|  10.0k|		reader->atr_info.FI = FI = tx[0] >> 4;
  867|  10.0k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  868|  10.0k|		reader->atr_info.Fi = Fi_table[FI];
  869|  10.0k|		reader->atr_info.f = f_table[FI];
  870|  10.0k|		reader->atr_info.Di = Di_table[DI];
  871|  10.0k|	} else {
  872|  1.98k|		reader->atr_info.Fi = -1;
  873|  1.98k|		reader->atr_info.f = -1;
  874|  1.98k|		reader->atr_info.Di = -1;
  875|  1.98k|	}
  876|  12.0k|	if (tx[2] >= 0)
  ------------------
  |  Branch (876:6): [True: 8.33k, False: 3.74k]
  ------------------
  877|  8.33k|		reader->atr_info.N = tx[3];
  878|  3.74k|	else
  879|  3.74k|		reader->atr_info.N = -1;
  880|  28.0k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (880:9): [True: 16.5k, False: 11.5k]
  |  Branch (880:22): [True: 15.9k, False: 530]
  |  Branch (880:38): [True: 15.9k, False: 44]
  ------------------
  881|  15.9k|		x = tx[3] >> 4;
  882|  79.6k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (882:15): [True: 63.7k, False: 15.9k]
  |  Branch (882:24): [True: 63.7k, False: 18]
  ------------------
  883|  63.7k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (883:22): [True: 24.5k, False: 39.1k]
  ------------------
  884|  24.5k|	                        tx[i] = *p;
  885|  24.5k|	                        p++;
  886|  24.5k|	                        atr_len--;
  887|  24.5k|	                } else
  888|  39.1k|	                        tx[i] = -1;
  889|  63.7k|		}
  890|  15.9k|	}
  891|  12.0k|	if (atr_len <= 0)
  ------------------
  |  Branch (891:6): [True: 105, False: 11.9k]
  ------------------
  892|    105|		return SC_SUCCESS;
  ------------------
  |  |   28|    105|#define SC_SUCCESS				0
  ------------------
  893|  11.9k|	if (n_hist > atr_len)
  ------------------
  |  Branch (893:6): [True: 746, False: 11.2k]
  ------------------
  894|    746|		n_hist = atr_len;
  895|  11.9k|	reader->atr_info.hist_bytes_len = n_hist;
  896|  11.9k|	reader->atr_info.hist_bytes = p;
  897|  11.9k|	return SC_SUCCESS;
  ------------------
  |  |   28|  11.9k|#define SC_SUCCESS				0
  ------------------
  898|  12.0k|}
sc_mem_secure_alloc:
  901|  49.7k|{
  902|  49.7k|	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|  49.7k|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  911|  49.7k|	if (p != NULL) {
  ------------------
  |  Branch (911:6): [True: 49.7k, False: 0]
  ------------------
  912|  49.7k|		mlock(p, len);
  913|  49.7k|	}
  914|  49.7k|#endif
  915|       |
  916|  49.7k|	return p;
  917|  49.7k|}
sc_mem_secure_free:
  920|  49.7k|{
  921|       |#ifdef _WIN32
  922|       |	VirtualUnlock(ptr, len);
  923|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  924|       |#else
  925|  49.7k|	munlock(ptr, len);
  926|  49.7k|	munmap(ptr, len);
  927|  49.7k|#endif
  928|  49.7k|}
sc_mem_clear:
  931|   113k|{
  932|   113k|	if (ptr && len > 0) {
  ------------------
  |  Branch (932:6): [True: 113k, False: 0]
  |  Branch (932:13): [True: 113k, False: 306]
  ------------------
  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|   113k|	}
  945|   113k|}
sc_compacttlv_find_tag:
 1059|  1.51k|{
 1060|  1.51k|	if (buf != NULL) {
  ------------------
  |  Branch (1060:6): [True: 1.51k, False: 0]
  ------------------
 1061|  1.51k|		size_t idx;
 1062|  1.51k|		u8 plain_tag = tag & 0xF0;
 1063|  1.51k|		size_t expected_len = tag & 0x0F;
 1064|       |
 1065|  7.82k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1065:17): [True: 6.81k, False: 1.01k]
  ------------------
 1066|  6.81k|			u8 ctag = buf[idx] & 0xF0;
 1067|  6.81k|			size_t ctag_len = buf[idx] & 0x0F;
 1068|  6.81k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1068:8): [True: 851, False: 5.96k]
  |  Branch (1068:29): [True: 818, False: 33]
  ------------------
 1069|    818|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1069:7): [True: 200, False: 618]
  |  Branch (1069:28): [True: 297, False: 321]
  ------------------
 1070|    497|				if (outlen != NULL)
  ------------------
  |  Branch (1070:9): [True: 200, False: 297]
  ------------------
 1071|    200|					*outlen = ctag_len;
 1072|    497|				return buf + (idx + 1);
 1073|    497|			}
 1074|  6.31k|			idx += ctag_len;
 1075|  6.31k|		}
 1076|  1.51k|	}
 1077|  1.01k|	return NULL;
 1078|  1.51k|}
sc_mutex_create:
 1083|  32.2k|{
 1084|  32.2k|	if (ctx == NULL)
  ------------------
  |  Branch (1084:6): [True: 0, False: 32.2k]
  ------------------
 1085|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1086|  32.2k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1086:6): [True: 0, False: 32.2k]
  |  Branch (1086:33): [True: 0, False: 0]
  ------------------
 1087|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1088|  32.2k|	else
 1089|  32.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  32.2k|#define SC_SUCCESS				0
  ------------------
 1090|  32.2k|}
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.60k|{
   37|  3.60k|	int r;
   38|       |
   39|  3.60k|	if (card == NULL) {
  ------------------
  |  Branch (39:6): [True: 0, False: 3.60k]
  ------------------
   40|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   41|      0|	}
   42|  3.60k|	if (crgram == NULL || out == NULL) {
  ------------------
  |  Branch (42:6): [True: 1.06k, False: 2.54k]
  |  Branch (42:24): [True: 0, False: 2.54k]
  ------------------
   43|  1.06k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   44|  1.06k|	}
   45|  2.54k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.54k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.54k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.54k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.54k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.54k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   46|  2.54k|	if (card->ops == NULL || card->ops->decipher == NULL)
  ------------------
  |  Branch (46:6): [True: 0, False: 2.54k]
  |  Branch (46:27): [True: 0, False: 2.54k]
  ------------------
   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.54k|	r = card->ops->decipher(card, crgram, crgram_len, out, outlen);
   49|  2.54k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.54k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.54k|	int _ret = r; \
  |  |  155|  2.54k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 2.23k, False: 309]
  |  |  ------------------
  |  |  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|  2.07k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.07k, False: 157]
  |  |  ------------------
  |  |  157|  2.23k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.23k|	} else { \
  |  |  159|    309|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    309|			"returning with: %d\n", _ret); \
  |  |  161|    309|	} \
  |  |  162|  2.54k|	return _ret; \
  |  |  163|  2.54k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   50|  2.54k|}
sc_compute_signature:
   55|  6.00k|{
   56|  6.00k|	int r;
   57|       |
   58|  6.00k|	if (card == NULL) {
  ------------------
  |  Branch (58:6): [True: 0, False: 6.00k]
  ------------------
   59|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   60|      0|	}
   61|  6.00k|	if (data == NULL || out == NULL) {
  ------------------
  |  Branch (61:6): [True: 0, False: 6.00k]
  |  Branch (61:22): [True: 0, False: 6.00k]
  ------------------
   62|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|      0|	}
   64|  6.00k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.00k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.00k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.00k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.00k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.00k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   65|  6.00k|	if (card->ops == NULL || card->ops->compute_signature == NULL)
  ------------------
  |  Branch (65:6): [True: 0, False: 6.00k]
  |  Branch (65:27): [True: 0, False: 6.00k]
  ------------------
   66|      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]
  |  |  ------------------
  ------------------
   67|  6.00k|	r = card->ops->compute_signature(card, data, datalen, out, outlen);
   68|  6.00k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  6.00k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  6.00k|	int _ret = r; \
  |  |  155|  6.00k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 5.64k, False: 358]
  |  |  ------------------
  |  |  156|  5.64k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  5.42k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 5.42k, False: 221]
  |  |  ------------------
  |  |  157|  5.64k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.64k|	} else { \
  |  |  159|    358|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    358|			"returning with: %d\n", _ret); \
  |  |  161|    358|	} \
  |  |  162|  6.00k|	return _ret; \
  |  |  163|  6.00k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   69|  6.00k|}
sc_set_security_env:
  104|  14.0k|{
  105|  14.0k|	int r;
  106|       |
  107|  14.0k|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (107:6): [True: 0, False: 14.0k]
  |  Branch (107:22): [True: 0, False: 14.0k]
  ------------------
  108|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  109|      0|	}
  110|  14.0k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  14.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  14.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  14.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  14.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 14.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  111|  14.0k|	if (card->ops == NULL || card->ops->set_security_env == NULL)
  ------------------
  |  Branch (111:6): [True: 0, False: 14.0k]
  |  Branch (111:27): [True: 0, False: 14.0k]
  ------------------
  112|      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]
  |  |  ------------------
  ------------------
  113|  14.0k|	r = card->ops->set_security_env(card, env, se_num);
  114|  14.0k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  14.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  14.0k|	int _ret = r; \
  |  |  155|  14.0k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 14.0k, False: 0]
  |  |  ------------------
  |  |  156|  14.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|  4.39k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.39k, False: 9.61k]
  |  |  ------------------
  |  |  157|  14.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  14.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|  14.0k|	return _ret; \
  |  |  163|  14.0k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  115|  14.0k|}
sc_restore_security_env:
  118|     40|{
  119|     40|	int r;
  120|       |
  121|     40|	if (card == NULL) {
  ------------------
  |  Branch (121:6): [True: 0, False: 40]
  ------------------
  122|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  123|      0|	}
  124|     40|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     40|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     40|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     40|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     40|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 40]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  125|     40|	if (card->ops == NULL || card->ops->restore_security_env == NULL)
  ------------------
  |  Branch (125:6): [True: 0, False: 40]
  |  Branch (125:27): [True: 0, False: 40]
  ------------------
  126|      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]
  |  |  ------------------
  ------------------
  127|     40|	r = card->ops->restore_security_env(card, se_num);
  128|     40|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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|     24|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 24, False: 16]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  129|     40|}
sc_verify:
  133|  1.10k|{
  134|  1.10k|	struct sc_pin_cmd_data data;
  135|       |
  136|  1.10k|	memset(&data, 0, sizeof(data));
  137|  1.10k|	data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  415|  1.10k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  138|  1.10k|	data.pin_type = type;
  139|  1.10k|	data.pin_reference = ref;
  140|  1.10k|	data.pin1.data = pin;
  141|  1.10k|	data.pin1.len = pinlen;
  142|       |
  143|  1.10k|	int r = sc_pin_cmd(card, &data);
  144|  1.10k|	if (tries_left)
  ------------------
  |  Branch (144:6): [True: 1.10k, False: 0]
  ------------------
  145|  1.10k|		*tries_left = data.pin1.tries_left;
  146|       |
  147|  1.10k|	return r;
  148|  1.10k|}
sc_pin_cmd:
  206|  11.0k|{
  207|  11.0k|	int r, debug;
  208|       |
  209|  11.0k|	if (card == NULL || data == NULL) {
  ------------------
  |  Branch (209:6): [True: 0, False: 11.0k]
  |  Branch (209:22): [True: 0, False: 11.0k]
  ------------------
  210|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  211|      0|	}
  212|  11.0k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  11.0k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.0k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.0k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.0k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.0k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|       |
  214|  11.0k|	debug = card->ctx->debug;
  215|  11.0k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  418|  22.0k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (215:6): [True: 2.94k, False: 8.05k]
  ------------------
  216|  2.94k|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (216:7): [True: 2.94k, False: 0]
  ------------------
  217|  2.94k|		card->ctx->debug = 0;
  218|  2.94k|	}
  219|       |
  220|  11.0k|	if (card->ops && card->ops->pin_cmd) {
  ------------------
  |  Branch (220:6): [True: 11.0k, False: 0]
  |  Branch (220:19): [True: 11.0k, False: 0]
  ------------------
  221|  11.0k|		r = card->ops->pin_cmd(card, data);
  222|  11.0k|	} else if (!(data->flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  421|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (222:13): [True: 0, False: 0]
  ------------------
  223|       |		/* Card driver doesn't support new style pin_cmd, fall
  224|       |		 * back to old interface */
  225|       |
  226|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  227|      0|		if (card->ops) {
  ------------------
  |  Branch (227:7): [True: 0, False: 0]
  ------------------
  228|      0|			switch (data->cmd) {
  ------------------
  |  Branch (228:12): [True: 0, False: 0]
  ------------------
  229|      0|			case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  415|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (229:4): [True: 0, False: 0]
  ------------------
  230|      0|				if (card->ops->verify != NULL)
  ------------------
  |  Branch (230:9): [True: 0, False: 0]
  ------------------
  231|      0|					r = card->ops->verify(card,
  232|      0|							data->pin_type,
  233|      0|							data->pin_reference,
  234|      0|							data->pin1.data,
  235|      0|							(size_t)data->pin1.len,
  236|      0|							&data->pin1.tries_left);
  237|      0|				break;
  238|      0|			case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  416|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (238:4): [True: 0, False: 0]
  ------------------
  239|      0|				if (card->ops->change_reference_data != NULL)
  ------------------
  |  Branch (239:9): [True: 0, False: 0]
  ------------------
  240|      0|					r = card->ops->change_reference_data(card,
  241|      0|							data->pin_type,
  242|      0|							data->pin_reference,
  243|      0|							data->pin1.data,
  244|      0|							(size_t)data->pin1.len,
  245|      0|							data->pin2.data,
  246|      0|							(size_t)data->pin2.len,
  247|      0|							&data->pin1.tries_left);
  248|      0|				break;
  249|      0|			case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  417|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (249:4): [True: 0, False: 0]
  ------------------
  250|      0|				if (card->ops->reset_retry_counter != NULL)
  ------------------
  |  Branch (250:9): [True: 0, False: 0]
  ------------------
  251|      0|					r = card->ops->reset_retry_counter(card,
  252|      0|							data->pin_type,
  253|      0|							data->pin_reference,
  254|      0|							data->pin1.data,
  255|      0|							(size_t)data->pin1.len,
  256|      0|							data->pin2.data,
  257|      0|							(size_t)data->pin2.len);
  258|      0|				break;
  259|      0|			}
  260|      0|		}
  261|      0|		if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (261:7): [True: 0, False: 0]
  ------------------
  262|      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__
  |  |  ------------------
  ------------------
  263|      0|					data->cmd);
  264|      0|	} else {
  265|      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__
  |  |  ------------------
  ------------------
  266|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  267|      0|	}
  268|  11.0k|	card->ctx->debug = debug;
  269|       |
  270|  11.0k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  11.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  11.0k|	int _ret = r; \
  |  |  155|  11.0k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 11.0k, False: 0]
  |  |  ------------------
  |  |  156|  11.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|  7.16k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 7.16k, False: 3.84k]
  |  |  ------------------
  |  |  157|  11.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  11.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|  11.0k|	return _ret; \
  |  |  163|  11.0k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  271|  11.0k|}
sc_build_pin:
  285|  2.13k|{
  286|  2.13k|	size_t i = 0, j, pin_len;
  287|       |
  288|  2.13k|	if (buf == NULL || pin == NULL || buflen == 0)
  ------------------
  |  Branch (288:6): [True: 0, False: 2.13k]
  |  Branch (288:21): [True: 0, False: 2.13k]
  |  Branch (288:36): [True: 0, False: 2.13k]
  ------------------
  289|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  290|       |
  291|  2.13k|	pin_len = pin->len;
  292|  2.13k|	if (pin_len > 0 && pin->data == NULL)
  ------------------
  |  Branch (292:6): [True: 2.13k, False: 0]
  |  Branch (292:21): [True: 0, False: 2.13k]
  ------------------
  293|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  294|       |
  295|  2.13k|	if (pin->max_length && pin_len > pin->max_length)
  ------------------
  |  Branch (295:6): [True: 1.98k, False: 149]
  |  Branch (295:25): [True: 0, False: 1.98k]
  ------------------
  296|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  297|       |
  298|  2.13k|	if (pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|  2.13k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (298:6): [True: 46, False: 2.08k]
  ------------------
  299|    118|		while (pin_len > 0 && pin->data[pin_len - 1] == 0xFF)
  ------------------
  |  Branch (299:10): [True: 112, False: 6]
  |  Branch (299:25): [True: 72, False: 40]
  ------------------
  300|     72|			pin_len--;
  301|     46|		if (pin_len > 12)
  ------------------
  |  Branch (301:7): [True: 6, False: 40]
  ------------------
  302|      6|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      6|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  303|    109|		for (i = 0; i < pin_len; i++) {
  ------------------
  |  Branch (303:15): [True: 92, False: 17]
  ------------------
  304|     92|			if (pin->data[i] < '0' || pin->data[i] > '9')
  ------------------
  |  Branch (304:8): [True: 11, False: 81]
  |  Branch (304:30): [True: 12, False: 69]
  ------------------
  305|     23|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     23|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  306|     92|		}
  307|     17|		if (buflen < 1)
  ------------------
  |  Branch (307:7): [True: 0, False: 17]
  ------------------
  308|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  309|     17|		buf[0] = 0x20 | (u8) pin_len;
  310|     17|		buf++;
  311|     17|		buflen--;
  312|     17|	}
  313|       |
  314|       |	/* PIN given by application, encode if required */
  315|  2.10k|	if (pin->encoding == SC_PIN_ENCODING_ASCII) {
  ------------------
  |  |  425|  2.10k|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  |  Branch (315:6): [True: 2.05k, False: 48]
  ------------------
  316|  2.05k|		if (pin_len > buflen)
  ------------------
  |  Branch (316:7): [True: 18, False: 2.03k]
  ------------------
  317|     18|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     18|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  318|  2.03k|		if (pin_len > 0)
  ------------------
  |  Branch (318:7): [True: 2.03k, False: 0]
  ------------------
  319|  2.03k|			memcpy(buf, pin->data, pin_len);
  320|  2.03k|		i = pin_len;
  321|  2.03k|	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  426|     96|#define SC_PIN_ENCODING_BCD	1
  ------------------
              	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|     17|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (321:13): [True: 31, False: 17]
  |  Branch (321:53): [True: 17, False: 0]
  ------------------
  322|     48|		if (pin_len > 2 * buflen)
  ------------------
  |  Branch (322:7): [True: 0, False: 48]
  ------------------
  323|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  324|    341|		for (i = j = 0; j < pin_len; j++) {
  ------------------
  |  Branch (324:19): [True: 308, False: 33]
  ------------------
  325|    308|			if (!isdigit((unsigned char)pin->data[j])) {
  ------------------
  |  Branch (325:8): [True: 15, False: 293]
  ------------------
  326|     15|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     15|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  327|     15|			}
  328|    293|			if ((j & 1) == 0)
  ------------------
  |  Branch (328:8): [True: 155, False: 138]
  ------------------
  329|    155|				buf[i] = 0;
  330|    293|			buf[i] <<= 4;
  331|    293|			buf[i] |= pin->data[j] & 0xf;
  332|    293|			if (j & 1)
  ------------------
  |  Branch (332:8): [True: 138, False: 155]
  ------------------
  333|    138|				i++;
  334|    293|		}
  335|     33|		if (j & 1) {
  ------------------
  |  Branch (335:7): [True: 13, False: 20]
  ------------------
  336|     13|			buf[i] <<= 4;
  337|     13|			buf[i] |= pin->pad_char & 0xf;
  338|     13|			i++;
  339|     13|		}
  340|     33|	}
  341|       |
  342|       |	/* Pad to maximum PIN length if requested */
  343|  2.06k|	if (pad || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  427|    870|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (343:6): [True: 1.19k, False: 870]
  |  Branch (343:13): [True: 0, False: 870]
  ------------------
  344|  1.19k|		size_t pad_length = pin->pad_length;
  345|  1.19k|		u8     pad_char   = pin->encoding == SC_PIN_ENCODING_GLP ? 0xFF : pin->pad_char;
  ------------------
  |  |  427|  1.19k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (345:23): [True: 17, False: 1.18k]
  ------------------
  346|       |
  347|  1.19k|		if (pin->encoding == SC_PIN_ENCODING_BCD)
  ------------------
  |  |  426|  1.19k|#define SC_PIN_ENCODING_BCD	1
  ------------------
  |  Branch (347:7): [True: 16, False: 1.18k]
  ------------------
  348|     16|			pad_length >>= 1;
  349|  1.19k|		if (pin->encoding == SC_PIN_ENCODING_GLP)
  ------------------
  |  |  427|  1.19k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (349:7): [True: 17, False: 1.18k]
  ------------------
  350|     17|			pad_length = 8;
  351|       |
  352|  1.19k|		if (pad_length > buflen)
  ------------------
  |  Branch (352:7): [True: 0, False: 1.19k]
  ------------------
  353|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  354|       |
  355|  1.19k|		if (pad_length && i < pad_length) {
  ------------------
  |  Branch (355:7): [True: 1.06k, False: 136]
  |  Branch (355:21): [True: 479, False: 584]
  ------------------
  356|    479|			memset(buf + i, pad_char, pad_length - i);
  357|    479|			i = pad_length;
  358|    479|		}
  359|  1.19k|	}
  360|       |
  361|  2.06k|	return (int)i;
  362|  2.06k|}

sc_simpletlv_put_tag:
   43|    634|{
   44|    634|	u8 *p = out;
   45|       |
   46|    634|	if (byte_order != SC_SIMPLETLV_LITTLE_ENDIAN && byte_order != SC_SIMPLETLV_BIG_ENDIAN)
  ------------------
  |  Branch (46:6): [True: 0, False: 634]
  |  Branch (46:50): [True: 0, False: 0]
  ------------------
   47|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   48|       |
   49|    634|	if (out == NULL || outlen < 2 || (outlen < 4 && datalen >= 0xff))
  ------------------
  |  Branch (49:6): [True: 0, False: 634]
  |  Branch (49:21): [True: 0, False: 634]
  |  Branch (49:36): [True: 29, False: 605]
  |  Branch (49:50): [True: 0, False: 29]
  ------------------
   50|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   51|       |
   52|       |	/* tag is just number between 0x01 and 0xFE */
   53|    634|	if (tag == 0x00 || tag == 0xff)
  ------------------
  |  Branch (53:6): [True: 140, False: 494]
  |  Branch (53:21): [True: 42, False: 452]
  ------------------
   54|    182|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    182|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   55|    452|	if (datalen > 0xffff) {
  ------------------
  |  Branch (55:6): [True: 0, False: 452]
  ------------------
   56|       |		/* we can't store more than two bytes in Simple TLV */
   57|      0|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
   58|      0|	}
   59|       |
   60|    452|	*p++ = tag; /* tag is single byte */
   61|    452|	if (datalen < 0xff) {
  ------------------
  |  Branch (61:6): [True: 421, False: 31]
  ------------------
   62|       |		/* short value up to 254 */
   63|    421|		*p++ = (u8)datalen; /* is in the second byte */
   64|    421|	} else {
   65|       |		/* longer values up to 65535 */
   66|     31|		*p++ = (u8)0xff; /* first byte is 0xff */
   67|     31|		if (byte_order == SC_SIMPLETLV_BIG_ENDIAN) {
  ------------------
  |  Branch (67:7): [True: 0, False: 31]
  ------------------
   68|      0|			*p++ = (u8)(datalen >> 8);
   69|      0|			*p++ = (u8)datalen;
   70|     31|		} else {
   71|     31|			*p++ = (u8)datalen;
   72|     31|			*p++ = (u8)(datalen >> 8);
   73|     31|		}
   74|     31|	}
   75|    452|	if (ptr != NULL)
  ------------------
  |  Branch (75:6): [True: 452, False: 0]
  ------------------
   76|    452|		*ptr = p;
   77|    452|	return SC_SUCCESS;
  ------------------
  |  |   28|    452|#define SC_SUCCESS				0
  ------------------
   78|    452|}
sc_simpletlv_read_tag:
   86|  62.6k|{
   87|  62.6k|	u8 tag;
   88|  62.6k|	size_t left = buflen, len;
   89|  62.6k|	const u8 *p;
   90|       |
   91|  62.6k|	if (byte_order != SC_SIMPLETLV_LITTLE_ENDIAN && byte_order != SC_SIMPLETLV_BIG_ENDIAN)
  ------------------
  |  Branch (91:6): [True: 151, False: 62.5k]
  |  Branch (91:50): [True: 0, False: 151]
  ------------------
   92|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   93|  62.6k|	if (buf == NULL || tag_out == NULL || taglen == NULL)
  ------------------
  |  Branch (93:6): [True: 0, False: 62.6k]
  |  Branch (93:21): [True: 0, False: 62.6k]
  |  Branch (93:40): [True: 0, False: 62.6k]
  ------------------
   94|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   95|  62.6k|	if (*buf == NULL)
  ------------------
  |  Branch (95:6): [True: 0, False: 62.6k]
  ------------------
   96|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   97|       |
   98|  62.6k|	p = *buf;
   99|  62.6k|	*buf = NULL;
  100|       |
  101|  62.6k|	if (left < 2) {
  ------------------
  |  Branch (101:6): [True: 222, False: 62.4k]
  ------------------
  102|    222|		return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    222|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
  103|    222|	}
  104|  62.4k|	tag = *p;
  105|  62.4k|	p++;
  106|  62.4k|	len = *p;
  107|  62.4k|	p++;
  108|  62.4k|	left -= 2;
  109|       |
  110|  62.4k|	if (len == 0xff) {
  ------------------
  |  Branch (110:6): [True: 1.28k, False: 61.1k]
  ------------------
  111|       |		/* don't crash on bad data */
  112|  1.28k|		if (left < 2) {
  ------------------
  |  Branch (112:7): [True: 104, False: 1.18k]
  ------------------
  113|    104|			return SC_ERROR_INVALID_TLV_OBJECT;
  ------------------
  |  |   98|    104|#define SC_ERROR_INVALID_TLV_OBJECT		-1417
  ------------------
  114|    104|		}
  115|       |		/* skip two bytes (the size) */
  116|  1.18k|		len = byte_order == SC_SIMPLETLV_BIG_ENDIAN ? bebytes2ushort(p) : lebytes2ushort(p);
  ------------------
  |  Branch (116:9): [True: 115, False: 1.06k]
  ------------------
  117|  1.18k|		p += 2;
  118|  1.18k|		left -= 2;
  119|  1.18k|	}
  120|       |
  121|  62.3k|	*tag_out = tag;
  122|  62.3k|	*taglen = len;
  123|  62.3k|	*buf = p;
  124|       |
  125|  62.3k|	if (len > left)
  ------------------
  |  Branch (125:6): [True: 5.85k, False: 56.4k]
  ------------------
  126|  5.85k|		return SC_ERROR_TLV_END_OF_CONTENTS;
  ------------------
  |  |   99|  5.85k|#define SC_ERROR_TLV_END_OF_CONTENTS	-1418
  ------------------
  127|       |
  128|  56.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  56.4k|#define SC_SUCCESS				0
  ------------------
  129|  62.3k|}

sc_sm_parse_answer:
   44|  3.95k|{
   45|  3.95k|	struct sc_asn1_entry asn1_sm_response[4];
   46|  3.95k|	unsigned char data[SC_MAX_APDU_BUFFER_SIZE];
   47|  3.95k|	size_t data_len = sizeof(data);
   48|  3.95k|	unsigned char status[2] = {0, 0};
   49|  3.95k|	size_t status_len = sizeof(status);
   50|  3.95k|	unsigned char mac[8];
   51|  3.95k|	size_t mac_len = sizeof(mac);
   52|  3.95k|	int rv;
   53|       |
   54|  3.95k|	if (!resp_data || !resp_len || !out)
  ------------------
  |  Branch (54:6): [True: 0, False: 3.95k]
  |  Branch (54:20): [True: 0, False: 3.95k]
  |  Branch (54:33): [True: 0, False: 3.95k]
  ------------------
   55|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   56|       |
   57|  3.95k|	sc_copy_asn1_entry(c_asn1_sm_response, asn1_sm_response);
   58|       |
   59|  3.95k|	sc_format_asn1_entry(asn1_sm_response + 0, data, &data_len, 0);
   60|  3.95k|	sc_format_asn1_entry(asn1_sm_response + 1, status, &status_len, 0);
   61|  3.95k|	sc_format_asn1_entry(asn1_sm_response + 2, mac, &mac_len, 0);
   62|       |
   63|  3.95k|	rv = sc_asn1_decode(card->ctx, asn1_sm_response, resp_data, resp_len, NULL, NULL);
   64|  3.95k|	if (rv)
  ------------------
  |  Branch (64:6): [True: 3.78k, False: 169]
  ------------------
   65|  3.78k|		return rv;
   66|       |
   67|    169|	if (asn1_sm_response[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|    169|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (67:6): [True: 34, False: 135]
  ------------------
   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|    169|	if (asn1_sm_response[1].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|    169|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (73:6): [True: 169, False: 0]
  ------------------
   74|    169|		if (!status[0])
  ------------------
  |  Branch (74:7): [True: 55, False: 114]
  ------------------
   75|     55|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     55|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
   76|    114|		out->sw1 = status[0];
   77|    114|		out->sw2 = status[1];
   78|    114|	}
   79|    114|	if (asn1_sm_response[2].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  171|    114|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (79:6): [True: 114, False: 0]
  ------------------
   80|    114|		memcpy(out->mac, mac, mac_len);
   81|    114|		out->mac_len = mac_len;
   82|    114|	}
   83|       |
   84|    114|	return SC_SUCCESS;
  ------------------
  |  |   28|    114|#define SC_SUCCESS				0
  ------------------
   85|    169|}
sc_sm_update_apdu_response:
   98|  3.95k|{
   99|  3.95k|	struct sm_card_response sm_resp;
  100|  3.95k|	int r;
  101|       |
  102|  3.95k|	if (!apdu)
  ------------------
  |  Branch (102:6): [True: 0, False: 3.95k]
  ------------------
  103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  104|  3.95k|	else if (!resp_data || !resp_len)
  ------------------
  |  Branch (104:11): [True: 0, False: 3.95k]
  |  Branch (104:25): [True: 0, False: 3.95k]
  ------------------
  105|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  106|       |
  107|  3.95k|	memset(&sm_resp, 0, sizeof(sm_resp));
  108|  3.95k|	r = sc_sm_parse_answer(card, resp_data, resp_len, &sm_resp);
  109|  3.95k|	if (r)
  ------------------
  |  Branch (109:6): [True: 3.84k, False: 114]
  ------------------
  110|  3.84k|		return r;
  111|       |
  112|    114|	if (sm_resp.mac_len)   {
  ------------------
  |  Branch (112:6): [True: 45, False: 69]
  ------------------
  113|     45|		if (sm_resp.mac_len > sizeof(apdu->mac))
  ------------------
  |  Branch (113:7): [True: 0, False: 45]
  ------------------
  114|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  115|     45|		memcpy(apdu->mac, sm_resp.mac, sm_resp.mac_len);
  116|     45|		apdu->mac_len = sm_resp.mac_len;
  117|     45|	}
  118|       |
  119|    114|	apdu->sw1 = sm_resp.sw1;
  120|    114|	apdu->sw2 = sm_resp.sw2;
  121|       |
  122|    114|	return SC_SUCCESS;
  ------------------
  |  |   28|    114|#define SC_SUCCESS				0
  ------------------
  123|    114|}
sc_sm_single_transmit:
  127|  2.63k|{
  128|  2.63k|	struct sc_context *ctx  = card->ctx;
  129|  2.63k|	struct sc_apdu *sm_apdu = NULL;
  130|  2.63k|	int retries = 1;
  131|  2.63k|	int rv;
  132|       |
  133|  2.63k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.63k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.63k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.63k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.63k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|  2.63k|	sc_log(ctx, "SM_MODE:%X", card->sm_ctx.sm_mode);
  ------------------
  |  |   71|  2.63k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  135|  2.63k|	if (!card->sm_ctx.ops.get_sm_apdu || !card->sm_ctx.ops.free_sm_apdu)
  ------------------
  |  Branch (135:6): [True: 0, False: 2.63k]
  |  Branch (135:39): [True: 0, False: 2.63k]
  ------------------
  136|  2.63k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  137|       |
  138|  2.63k|retry:
  139|       |	/* get SM encoded APDU */
  140|  2.63k|	rv = card->sm_ctx.ops.get_sm_apdu(card, apdu, &sm_apdu);
  141|  2.63k|	if (rv == SC_ERROR_SM_NOT_APPLIED)   {
  ------------------
  |  |  125|  2.63k|#define SC_ERROR_SM_NOT_APPLIED			-1610
  ------------------
  |  Branch (141:6): [True: 0, False: 2.63k]
  ------------------
  142|       |		/* SM wrap of this APDU is ignored by card driver.
  143|       |		 * Send plain APDU to the reader driver */
  144|      0|		rv = card->reader->ops->transmit(card->reader, apdu);
  145|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  146|  2.63k|	} else {
  147|  2.63k|		if (rv < 0)
  ------------------
  |  Branch (147:7): [True: 0, False: 2.63k]
  ------------------
  148|      0|			sc_sm_stop(card);
  149|  2.63k|	}
  150|  2.63k|	LOG_TEST_RET(ctx, rv, "get SM APDU error");
  ------------------
  |  |  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: 0, False: 2.63k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  2.63k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.63k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  151|       |
  152|       |	/* check if SM APDU is still valid */
  153|  2.63k|	rv = sc_check_apdu(card, sm_apdu);
  154|  2.63k|	if (rv < 0)   {
  ------------------
  |  Branch (154:6): [True: 0, False: 2.63k]
  ------------------
  155|      0|		card->sm_ctx.ops.free_sm_apdu(card, apdu, &sm_apdu);
  156|      0|		sc_sm_stop(card);
  157|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|      0|	}
  159|       |
  160|  2.63k|	sm_apdu->flags |= SC_APDU_FLAGS_NO_RETRY_WL;
  ------------------
  |  |  312|  2.63k|#define SC_APDU_FLAGS_NO_RETRY_WL	0x00000004UL
  ------------------
  161|  2.63k|	card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|  2.63k|#define SM_MODE_NONE		0x0
  ------------------
  162|  2.63k|	rv = sc_transmit_apdu(card, sm_apdu);
  163|  2.63k|	card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|  2.63k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  164|  2.63k|	if (rv < 0) {
  ------------------
  |  Branch (164:6): [True: 21, False: 2.61k]
  ------------------
  165|     21|		card->sm_ctx.ops.free_sm_apdu(card, apdu, &sm_apdu);
  166|     21|		sc_sm_stop(card);
  167|     21|		LOG_TEST_RET(ctx, rv, "unable to transmit APDU");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  168|     21|	}
  169|       |
  170|       |	/* decode SM answer and free temporary SM related data */
  171|  2.61k|	rv = card->sm_ctx.ops.free_sm_apdu(card, apdu, &sm_apdu);
  172|       |
  173|       |	/*
  174|       |	 * Multiple processes may have reset our SM session.
  175|       |	 * sm_ctx.ops.free_sm_apdu can detect SM failure
  176|       |	 * try again with new SM session using current pcsc lock
  177|       |	 */
  178|  2.61k|	if (rv == SC_ERROR_INCORRECT_SM_OBJECTS && retries > 0 &&
  ------------------
  |  |  128|  5.23k|#define SC_ERROR_INCORRECT_SM_OBJECTS		-1613
  ------------------
  |  Branch (178:6): [True: 4, False: 2.61k]
  |  Branch (178:45): [True: 4, False: 0]
  ------------------
  179|      4|			apdu->flags & SC_APDU_FLAGS_RETRY_WITH_SM_OPEN) {
  ------------------
  |  |  317|      4|#define SC_APDU_FLAGS_RETRY_WITH_SM_OPEN 0x00000020UL
  ------------------
  |  Branch (179:4): [True: 4, False: 0]
  ------------------
  180|      4|		sc_log(ctx, "Retry apdu with new SM 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__
  |  |  ------------------
  ------------------
  181|      4|		retries--;
  182|      4|		if (card->sm_ctx.ops.open) {
  ------------------
  |  Branch (182:7): [True: 4, False: 0]
  ------------------
  183|      4|			rv = card->sm_ctx.ops.open(card);
  184|      4|			if (rv == SC_SUCCESS)
  ------------------
  |  |   28|      4|#define SC_SUCCESS				0
  ------------------
  |  Branch (184:8): [True: 0, False: 4]
  ------------------
  185|      0|				goto retry;
  186|      4|		}
  187|      4|	}
  188|       |
  189|  2.61k|	if (rv < 0)
  ------------------
  |  Branch (189:6): [True: 211, False: 2.40k]
  ------------------
  190|    211|		sc_sm_stop(card);
  191|       |
  192|  2.61k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  2.61k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.61k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.61k|	int _ret = r; \
  |  |  |  |  155|  2.61k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.61k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|    211|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 211, False: 2.40k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.61k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.61k|	return _ret; \
  |  |  |  |  163|  2.61k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  193|  2.61k|}
sc_sm_stop:
  197|    532|{
  198|    532|    int r = SC_SUCCESS;
  ------------------
  |  |   28|    532|#define SC_SUCCESS				0
  ------------------
  199|       |
  200|    532|    if (card) {
  ------------------
  |  Branch (200:9): [True: 532, False: 0]
  ------------------
  201|    532|        if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT
  ------------------
  |  |   47|  1.06k|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (201:13): [True: 228, False: 304]
  ------------------
  202|    228|                && card->sm_ctx.ops.close)
  ------------------
  |  Branch (202:20): [True: 0, False: 228]
  ------------------
  203|      0|            r = card->sm_ctx.ops.close(card);
  204|    532|        card->sm_ctx.sm_mode = SM_MODE_NONE;
  ------------------
  |  |   43|    532|#define SM_MODE_NONE		0x0
  ------------------
  205|    532|    }
  206|       |
  207|    532|    return r;
  208|    532|}

scconf_parse_token:
  264|   161k|{
  265|   161k|	scconf_item *item;
  266|   161k|	size_t len;
  267|       |
  268|   161k|	if (parser->error) {
  ------------------
  |  Branch (268:6): [True: 0, False: 161k]
  ------------------
  269|       |		/* fatal error */
  270|      0|		return;
  271|      0|	}
  272|   161k|	switch (token_type) {
  ------------------
  |  Branch (272:10): [True: 161k, False: 0]
  ------------------
  273|      0|	case TOKEN_TYPE_NEWLINE:
  ------------------
  |  |   32|      0|#define TOKEN_TYPE_NEWLINE	1
  ------------------
  |  Branch (273:2): [True: 0, False: 161k]
  ------------------
  274|      0|		parser->line++;
  275|      0|		if (parser->last_token_type != TOKEN_TYPE_NEWLINE) {
  ------------------
  |  |   32|      0|#define TOKEN_TYPE_NEWLINE	1
  ------------------
  |  Branch (275:7): [True: 0, False: 0]
  ------------------
  276|      0|			break;
  277|      0|		}
  278|       |		/* fall through - treat empty lines as comments */
  279|      0|	case TOKEN_TYPE_COMMENT:
  ------------------
  |  |   31|      0|#define TOKEN_TYPE_COMMENT	0
  ------------------
  |  Branch (279:2): [True: 0, False: 161k]
  ------------------
  280|      0|		item = scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_COMMENT);
  ------------------
  |  |   42|      0|#define SCCONF_ITEM_TYPE_COMMENT	0	/* key = NULL, comment */
  ------------------
  281|      0|		if (!item) {
  ------------------
  |  Branch (281:7): [True: 0, False: 0]
  ------------------
  282|      0|			return;
  283|      0|		}
  284|      0|		item->value.comment = token ? strdup(token) : NULL;
  ------------------
  |  Branch (284:25): [True: 0, False: 0]
  ------------------
  285|      0|		break;
  286|  80.6k|	case TOKEN_TYPE_STRING:
  ------------------
  |  |   33|  80.6k|#define TOKEN_TYPE_STRING	2
  ------------------
  |  Branch (286:2): [True: 80.6k, False: 80.6k]
  ------------------
  287|  80.6k|		{
  288|  80.6k|			char *stoken = NULL;
  289|       |
  290|  80.6k|			if ((parser->state & (STATE_VALUE | STATE_SET)) ==
  ------------------
  |  |   37|  80.6k|#define STATE_VALUE	0x02
  ------------------
              			if ((parser->state & (STATE_VALUE | STATE_SET)) ==
  ------------------
  |  |   38|  80.6k|#define STATE_SET	0x10
  ------------------
  |  Branch (290:8): [True: 0, False: 80.6k]
  ------------------
  291|  80.6k|			    (STATE_VALUE | STATE_SET)) {
  ------------------
  |  |   37|  80.6k|#define STATE_VALUE	0x02
  ------------------
              			    (STATE_VALUE | STATE_SET)) {
  ------------------
  |  |   38|  80.6k|#define STATE_SET	0x10
  ------------------
  292|      0|				scconf_parse_warning_expect(parser, ";");
  293|      0|				scconf_parse_reset_state(parser);
  294|      0|			}
  295|  80.6k|			if (token && *token == '"') {
  ------------------
  |  Branch (295:8): [True: 80.6k, False: 0]
  |  Branch (295:17): [True: 0, False: 80.6k]
  ------------------
  296|       |				/* quoted string, remove them */
  297|      0|				token++;
  298|      0|				len = strlen(token);
  299|      0|				if (len < 1 || token[len - 1] != '"') {
  ------------------
  |  Branch (299:9): [True: 0, False: 0]
  |  Branch (299:20): [True: 0, False: 0]
  ------------------
  300|      0|					scconf_parse_warning_expect(parser, "\"");
  301|      0|				} else {
  302|       |					/* stoken */
  303|      0|					stoken = strdup(token);
  304|      0|					if (stoken) {
  ------------------
  |  Branch (304:10): [True: 0, False: 0]
  ------------------
  305|      0|						stoken[len - 1] = '\0';
  306|      0|					}
  307|      0|				}
  308|      0|			}
  309|  80.6k|			if (!stoken) {
  ------------------
  |  Branch (309:8): [True: 80.6k, False: 0]
  ------------------
  310|  80.6k|				stoken = token ? strdup(token) : NULL;
  ------------------
  |  Branch (310:14): [True: 80.6k, False: 0]
  ------------------
  311|  80.6k|			}
  312|  80.6k|			if (parser->state == 0) {
  ------------------
  |  Branch (312:8): [True: 32.2k, False: 48.3k]
  ------------------
  313|       |				/* key */
  314|  32.2k|				parser->key = stoken ? strdup(stoken) : NULL;
  ------------------
  |  Branch (314:19): [True: 32.2k, False: 0]
  ------------------
  315|  32.2k|				parser->state = STATE_NAME;
  ------------------
  |  |   36|  32.2k|#define STATE_NAME	0x01
  ------------------
  316|  48.3k|			} else if (parser->state == STATE_NAME) {
  ------------------
  |  |   36|  48.3k|#define STATE_NAME	0x01
  ------------------
  |  Branch (316:15): [True: 16.1k, False: 32.2k]
  ------------------
  317|       |				/* name */
  318|  16.1k|				parser->state |= STATE_SET;
  ------------------
  |  |   38|  16.1k|#define STATE_SET	0x10
  ------------------
  319|  16.1k|				scconf_list_add(&parser->name, stoken);
  320|  32.2k|			} else if (parser->state == STATE_VALUE && parser->current_item->type == SCCONF_ITEM_TYPE_VALUE) {
  ------------------
  |  |   37|  64.4k|#define STATE_VALUE	0x02
  ------------------
              			} else if (parser->state == STATE_VALUE && parser->current_item->type == SCCONF_ITEM_TYPE_VALUE) {
  ------------------
  |  |   44|  32.2k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (320:15): [True: 32.2k, False: 0]
  |  Branch (320:47): [True: 32.2k, False: 0]
  ------------------
  321|       |				/* value */
  322|  32.2k|				parser->state |= STATE_SET;
  ------------------
  |  |   38|  32.2k|#define STATE_SET	0x10
  ------------------
  323|  32.2k|				scconf_list_add(&parser->current_item->value.list,
  324|  32.2k|						      stoken);
  325|  32.2k|			} else {
  326|       |				/* error */
  327|      0|				scconf_parse_error_not_expect(parser, stoken);
  328|      0|			}
  329|  80.6k|			if (stoken) {
  ------------------
  |  Branch (329:8): [True: 80.6k, False: 0]
  ------------------
  330|  80.6k|				free(stoken);
  331|  80.6k|			}
  332|  80.6k|			stoken = NULL;
  333|  80.6k|		}
  334|  80.6k|		break;
  335|  80.6k|	case TOKEN_TYPE_PUNCT:
  ------------------
  |  |   34|  80.6k|#define TOKEN_TYPE_PUNCT	3
  ------------------
  |  Branch (335:2): [True: 80.6k, False: 80.6k]
  ------------------
  336|  80.6k|		switch (*token) {
  337|  16.1k|		case '{':
  ------------------
  |  Branch (337:3): [True: 16.1k, False: 64.4k]
  ------------------
  338|  16.1k|			if ((parser->state & STATE_NAME) == 0) {
  ------------------
  |  |   36|  16.1k|#define STATE_NAME	0x01
  ------------------
  |  Branch (338:8): [True: 0, False: 16.1k]
  ------------------
  339|      0|				scconf_parse_error_not_expect(parser, "{");
  340|      0|				break;
  341|      0|			}
  342|  16.1k|			parser->nested_blocks++;
  343|  16.1k|			scconf_block_add_internal(parser);
  344|  16.1k|			scconf_parse_reset_state(parser);
  345|  16.1k|			break;
  346|  16.1k|		case '}':
  ------------------
  |  Branch (346:3): [True: 16.1k, False: 64.4k]
  ------------------
  347|  16.1k|			parser->nested_blocks--;
  348|  16.1k|			if (parser->state != 0) {
  ------------------
  |  Branch (348:8): [True: 0, False: 16.1k]
  ------------------
  349|      0|				if ((parser->state & STATE_VALUE) == 0 ||
  ------------------
  |  |   37|      0|#define STATE_VALUE	0x02
  ------------------
  |  Branch (349:9): [True: 0, False: 0]
  ------------------
  350|      0|				    (parser->state & STATE_SET) == 0) {
  ------------------
  |  |   38|      0|#define STATE_SET	0x10
  ------------------
  |  Branch (350:9): [True: 0, False: 0]
  ------------------
  351|      0|					scconf_parse_error_not_expect(parser,
  352|      0|								      "}");
  353|      0|					break;
  354|      0|				}
  355|       |				/* foo = bar } */
  356|      0|				scconf_parse_warning_expect(parser, ";");
  357|      0|				scconf_parse_reset_state(parser);
  358|      0|			}
  359|  16.1k|			if (!parser->block->parent) {
  ------------------
  |  Branch (359:8): [True: 0, False: 16.1k]
  ------------------
  360|       |				/* too many '}' */
  361|      0|				scconf_parse_error(parser,
  362|      0|						   "missing matching '{'");
  363|      0|				break;
  364|      0|			}
  365|  16.1k|			scconf_parse_parent(parser);
  366|  16.1k|			break;
  367|  16.1k|		case ',':
  ------------------
  |  Branch (367:3): [True: 16.1k, False: 64.4k]
  ------------------
  368|  16.1k|			if ((parser->state & (STATE_NAME | STATE_VALUE)) == 0) {
  ------------------
  |  |   36|  16.1k|#define STATE_NAME	0x01
  ------------------
              			if ((parser->state & (STATE_NAME | STATE_VALUE)) == 0) {
  ------------------
  |  |   37|  16.1k|#define STATE_VALUE	0x02
  ------------------
  |  Branch (368:8): [True: 0, False: 16.1k]
  ------------------
  369|      0|				scconf_parse_error_not_expect(parser, ",");
  370|      0|			}
  371|  16.1k|			parser->state &= ~STATE_SET;
  ------------------
  |  |   38|  16.1k|#define STATE_SET	0x10
  ------------------
  372|  16.1k|			break;
  373|  16.1k|		case '=':
  ------------------
  |  Branch (373:3): [True: 16.1k, False: 64.4k]
  ------------------
  374|  16.1k|			if ((parser->state & STATE_NAME) == 0) {
  ------------------
  |  |   36|  16.1k|#define STATE_NAME	0x01
  ------------------
  |  Branch (374:8): [True: 0, False: 16.1k]
  ------------------
  375|      0|				scconf_parse_error_not_expect(parser, "=");
  376|      0|				break;
  377|      0|			}
  378|  16.1k|			scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_VALUE);
  ------------------
  |  |   44|  16.1k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  379|  16.1k|			parser->state = STATE_VALUE;
  ------------------
  |  |   37|  16.1k|#define STATE_VALUE	0x02
  ------------------
  380|  16.1k|			break;
  381|  16.1k|		case ';':
  ------------------
  |  Branch (381:3): [True: 16.1k, False: 64.4k]
  ------------------
  382|  16.1k|			scconf_parse_reset_state(parser);
  383|  16.1k|			break;
  384|      0|		default:
  ------------------
  |  Branch (384:3): [True: 0, False: 80.6k]
  ------------------
  385|      0|			snprintf(parser->emesg, sizeof(parser->emesg),
  386|      0|				"Line %d: bad token ignoring\n",
  387|      0|				parser->line);
  388|  80.6k|		}
  389|  80.6k|		break;
  390|   161k|	}
  391|       |
  392|   161k|	parser->last_token_type = token_type;
  393|   161k|}
scconf_parse:
  396|  16.1k|{
  397|  16.1k|	static char buffer[256];
  398|  16.1k|	scconf_parser p;
  399|  16.1k|	int r = 1;
  400|       |
  401|  16.1k|	memset(&p, 0, sizeof(p));
  402|  16.1k|	p.config = config;
  403|  16.1k|	p.block = config->root;
  404|  16.1k|	p.line = 1;
  405|  16.1k|	p.nested_blocks = 0;
  406|       |
  407|  16.1k|	if (!scconf_lex_parse(&p, config->filename)) {
  ------------------
  |  Branch (407:6): [True: 16.1k, False: 0]
  ------------------
  408|  16.1k|		snprintf(buffer, sizeof(buffer),
  409|  16.1k|				"Unable to open \"%s\": %s",
  410|  16.1k|				config->filename, strerror(errno));
  411|  16.1k|		r = -1;
  412|  16.1k|	} else if (p.error) {
  ------------------
  |  Branch (412:13): [True: 0, False: 0]
  ------------------
  413|      0|		strlcpy(buffer, p.emesg, sizeof(buffer));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  414|      0|		r = 0;
  415|      0|	} else {
  416|      0|		r = 1;
  417|      0|	}
  418|       |
  419|  16.1k|	scconf_parse_reset_state(&p);
  420|       |
  421|  16.1k|	if (r <= 0)
  ------------------
  |  Branch (421:6): [True: 16.1k, False: 0]
  ------------------
  422|  16.1k|		config->errmsg = buffer;
  423|  16.1k|	return r;
  424|  16.1k|}
scconf_parse_string:
  427|  16.1k|{
  428|  16.1k|	static char buffer[256];
  429|  16.1k|	scconf_parser p;
  430|  16.1k|	int r;
  431|       |
  432|  16.1k|	memset(&p, 0, sizeof(p));
  433|  16.1k|	p.config = config;
  434|  16.1k|	p.block = config->root;
  435|  16.1k|	p.line = 1;
  436|  16.1k|	p.nested_blocks = 0;
  437|       |
  438|  16.1k|	if (!scconf_lex_parse_string(&p, string)) {
  ------------------
  |  Branch (438:6): [True: 0, False: 16.1k]
  ------------------
  439|      0|		snprintf(buffer, sizeof(buffer),
  440|      0|				"Failed to parse configuration string");
  441|      0|		r = -1;
  442|  16.1k|	} else if (p.error) {
  ------------------
  |  Branch (442:13): [True: 0, False: 16.1k]
  ------------------
  443|      0|		strlcpy(buffer, p.emesg, sizeof(buffer));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  444|      0|		r = 0;
  445|  16.1k|	} else {
  446|  16.1k|		r = 1;
  447|  16.1k|	}
  448|       |
  449|  16.1k|	scconf_parse_reset_state(&p);
  450|       |
  451|  16.1k|	if (r <= 0)
  ------------------
  |  Branch (451:6): [True: 0, False: 16.1k]
  ------------------
  452|      0|		config->errmsg = buffer;
  453|  16.1k|	return r;
  454|  16.1k|}
parse.c:scconf_item_add_internal:
   95|  32.2k|{
   96|  32.2k|	scconf_item *item;
   97|       |
   98|  32.2k|	if (type == SCCONF_ITEM_TYPE_VALUE) {
  ------------------
  |  |   44|  32.2k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (98:6): [True: 16.1k, False: 16.1k]
  ------------------
   99|       |		/* if item with same key already exists, use it */
  100|  16.1k|		item = scconf_item_find(parser);
  101|  16.1k|		if (item) {
  ------------------
  |  Branch (101:7): [True: 0, False: 16.1k]
  ------------------
  102|      0|			free(parser->key);
  103|      0|			parser->key = NULL;
  104|      0|			parser->current_item = item;
  105|      0|			return item;
  106|      0|		}
  107|  16.1k|	}
  108|  32.2k|	item = calloc(1, sizeof(scconf_item));
  109|  32.2k|	if (!item) {
  ------------------
  |  Branch (109:6): [True: 0, False: 32.2k]
  ------------------
  110|      0|		return NULL;
  111|      0|	}
  112|  32.2k|	item->type = type;
  113|       |
  114|       |	/*
  115|       |	 * A comment is a standalone item and has no key. Assigning the key
  116|       |	 * here would let a comment swallow the key of the item that is still
  117|       |	 * being parsed, and the following block or value would then be added
  118|       |	 * with key == NULL, which crashes the lookup and write functions.
  119|       |	 */
  120|  32.2k|	if (type != SCCONF_ITEM_TYPE_COMMENT) {
  ------------------
  |  |   42|  32.2k|#define SCCONF_ITEM_TYPE_COMMENT	0	/* key = NULL, comment */
  ------------------
  |  Branch (120:6): [True: 32.2k, False: 0]
  ------------------
  121|  32.2k|		item->key = parser->key;
  122|  32.2k|		parser->key = NULL;
  123|  32.2k|	}
  124|       |
  125|  32.2k|	if (parser->last_item) {
  ------------------
  |  Branch (125:6): [True: 0, False: 32.2k]
  ------------------
  126|      0|		parser->last_item->next = item;
  127|  32.2k|	} else {
  128|  32.2k|		parser->block->items = item;
  129|  32.2k|	}
  130|  32.2k|	parser->last_item = item;
  131|  32.2k|	if (type != SCCONF_ITEM_TYPE_COMMENT) {
  ------------------
  |  |   42|  32.2k|#define SCCONF_ITEM_TYPE_COMMENT	0	/* key = NULL, comment */
  ------------------
  |  Branch (131:6): [True: 32.2k, False: 0]
  ------------------
  132|  32.2k|		parser->current_item = item;
  133|  32.2k|	}
  134|  32.2k|	return item;
  135|  32.2k|}
parse.c:scconf_item_find:
   81|  16.1k|{
   82|  16.1k|	scconf_item *item;
   83|       |
   84|  16.1k|	for (item = parser->block->items; item; item = item->next) {
  ------------------
  |  Branch (84:36): [True: 0, False: 16.1k]
  ------------------
   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.1k|	return item;
   92|  16.1k|}
parse.c:scconf_block_add_internal:
  186|  16.1k|{
  187|  16.1k|	scconf_block *block;
  188|  16.1k|	scconf_item *item;
  189|       |
  190|  16.1k|	item = scconf_item_add_internal(parser, SCCONF_ITEM_TYPE_BLOCK);
  ------------------
  |  |   43|  16.1k|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  191|  16.1k|	if (!item) {
  ------------------
  |  Branch (191:6): [True: 0, False: 16.1k]
  ------------------
  192|      0|		return;
  193|      0|	}
  194|       |
  195|  16.1k|	block = calloc(1, sizeof(scconf_block));
  196|  16.1k|	if (!block) {
  ------------------
  |  Branch (196:6): [True: 0, False: 16.1k]
  ------------------
  197|      0|		return;
  198|      0|	}
  199|  16.1k|	block->parent = parser->block;
  200|  16.1k|	item->value.block = block;
  201|       |
  202|  16.1k|	if (!parser->name) {
  ------------------
  |  Branch (202:6): [True: 0, False: 16.1k]
  ------------------
  203|      0|		scconf_list_add(&parser->name, "");
  204|      0|	}
  205|  16.1k|	block->name = parser->name;
  206|  16.1k|	parser->name = NULL;
  207|       |
  208|  16.1k|	parser->block = block;
  209|       |	parser->last_item = NULL;
  210|  16.1k|}
parse.c:scconf_parse_reset_state:
  244|  64.4k|{
  245|  64.4k|	if (parser) {
  ------------------
  |  Branch (245:6): [True: 64.4k, False: 0]
  ------------------
  246|  64.4k|		if (parser->key) {
  ------------------
  |  Branch (246:7): [True: 0, False: 64.4k]
  ------------------
  247|      0|			free(parser->key);
  248|      0|		}
  249|  64.4k|		scconf_list_destroy(parser->name);
  250|       |
  251|  64.4k|		parser->key = NULL;
  252|       |		parser->name = NULL;
  253|  64.4k|		parser->state = 0;
  254|  64.4k|	}
  255|  64.4k|}
parse.c:scconf_parse_parent:
  232|  16.1k|{
  233|  16.1k|	parser->block = parser->block->parent;
  234|       |
  235|  16.1k|	parser->last_item = parser->block->items;
  236|  16.1k|	if (parser->last_item) {
  ------------------
  |  Branch (236:6): [True: 16.1k, False: 0]
  ------------------
  237|  16.1k|		while (parser->last_item->next) {
  ------------------
  |  Branch (237:10): [True: 0, False: 16.1k]
  ------------------
  238|      0|			parser->last_item = parser->last_item->next;
  239|      0|		}
  240|  16.1k|	}
  241|  16.1k|}

scconf_new:
   37|  16.1k|{
   38|  16.1k|	scconf_context *config;
   39|       |
   40|  16.1k|	config = calloc(1, sizeof(scconf_context));
   41|  16.1k|	if (!config) {
  ------------------
  |  Branch (41:6): [True: 0, False: 16.1k]
  ------------------
   42|      0|		return NULL;
   43|      0|	}
   44|  16.1k|	config->filename = filename ? strdup(filename) : NULL;
  ------------------
  |  Branch (44:21): [True: 16.1k, False: 0]
  ------------------
   45|  16.1k|	config->root = calloc(1, sizeof(scconf_block));
   46|  16.1k|	if (!config->root) {
  ------------------
  |  Branch (46:6): [True: 0, False: 16.1k]
  ------------------
   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.1k|	return config;
   54|  16.1k|}
scconf_free:
   57|  16.1k|{
   58|  16.1k|	if (config) {
  ------------------
  |  Branch (58:6): [True: 16.1k, False: 0]
  ------------------
   59|  16.1k|		scconf_block_destroy(config->root);
   60|  16.1k|		if (config->filename) {
  ------------------
  |  Branch (60:7): [True: 16.1k, False: 0]
  ------------------
   61|  16.1k|			free(config->filename);
   62|  16.1k|		}
   63|  16.1k|		free(config);
   64|  16.1k|	}
   65|  16.1k|}
scconf_find_blocks:
   89|   853k|{
   90|   853k|	scconf_block **blocks = NULL, **tmp;
   91|   853k|	int alloc_size, size;
   92|   853k|	scconf_item *item;
   93|       |
   94|   853k|	if (!block) {
  ------------------
  |  Branch (94:6): [True: 48.3k, False: 805k]
  ------------------
   95|  48.3k|		if (!config)
  ------------------
  |  Branch (95:7): [True: 0, False: 48.3k]
  ------------------
   96|      0|			return NULL;
   97|  48.3k|		block = config->root;
   98|  48.3k|	}
   99|   853k|	if (!block || !item_name) {
  ------------------
  |  Branch (99:6): [True: 0, False: 853k]
  |  Branch (99:16): [True: 0, False: 853k]
  ------------------
  100|      0|		return NULL;
  101|      0|	}
  102|   853k|	size = 0;
  103|   853k|	alloc_size = 10;
  104|   853k|	tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
  105|   853k|	if (!tmp) {
  ------------------
  |  Branch (105:6): [True: 0, False: 853k]
  ------------------
  106|      0|		free(blocks);
  107|      0|		return NULL;
  108|      0|	}
  109|   853k|	blocks = tmp;
  110|       |
  111|  1.70M|	for (item = block->items; item; item = item->next) {
  ------------------
  |  Branch (111:28): [True: 853k, False: 853k]
  ------------------
  112|   853k|		if (item->type == SCCONF_ITEM_TYPE_BLOCK &&
  ------------------
  |  |   43|  1.70M|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  |  Branch (112:7): [True: 48.3k, False: 805k]
  ------------------
  113|  48.3k|				item->key && strcasecmp(item_name, item->key) == 0) {
  ------------------
  |  Branch (113:5): [True: 48.3k, False: 0]
  |  Branch (113:18): [True: 48.3k, False: 0]
  ------------------
  114|  48.3k|			if (!item->value.block)
  ------------------
  |  Branch (114:8): [True: 0, False: 48.3k]
  ------------------
  115|      0|				continue;
  116|  48.3k|			if (key) {
  ------------------
  |  Branch (116:8): [True: 48.3k, False: 0]
  ------------------
  117|  48.3k|				if (!item->value.block->name || !item->value.block->name->data ||
  ------------------
  |  Branch (117:9): [True: 0, False: 48.3k]
  |  Branch (117:37): [True: 0, False: 48.3k]
  ------------------
  118|  48.3k|						strcasecmp(key, item->value.block->name->data)) {
  ------------------
  |  Branch (118:7): [True: 32.2k, False: 16.1k]
  ------------------
  119|  32.2k|					continue;
  120|  32.2k|				}
  121|  48.3k|			}
  122|  16.1k|			if (size + 1 >= alloc_size) {
  ------------------
  |  Branch (122:8): [True: 0, False: 16.1k]
  ------------------
  123|      0|				alloc_size *= 2;
  124|      0|				tmp = (scconf_block **) realloc(blocks, sizeof(scconf_block *) * alloc_size);
  125|      0|				if (!tmp) {
  ------------------
  |  Branch (125:9): [True: 0, False: 0]
  ------------------
  126|      0|					free(blocks);
  127|      0|					return NULL;
  128|      0|				}
  129|      0|				blocks = tmp;
  130|      0|			}
  131|  16.1k|			blocks[size++] = item->value.block;
  132|  16.1k|		}
  133|   853k|	}
  134|   853k|	blocks[size] = NULL;
  135|   853k|	return blocks;
  136|   853k|}
scconf_find_list:
  139|   158k|{
  140|   158k|	scconf_item *item;
  141|       |
  142|   158k|	if (!block || !option)
  ------------------
  |  Branch (142:6): [True: 29.8k, False: 128k]
  |  Branch (142:16): [True: 0, False: 128k]
  ------------------
  143|  29.8k|		return NULL;
  144|       |
  145|   241k|	for (item = block->items; item; item = item->next)
  ------------------
  |  Branch (145:28): [True: 128k, False: 112k]
  ------------------
  146|   128k|		if (item->type == SCCONF_ITEM_TYPE_VALUE && item->key && strcasecmp(option, item->key) == 0)
  ------------------
  |  |   44|   257k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (146:7): [True: 128k, False: 0]
  |  Branch (146:47): [True: 128k, False: 0]
  |  Branch (146:60): [True: 16.1k, False: 112k]
  ------------------
  147|  16.1k|			return item->value.list;
  148|   112k|	return NULL;
  149|   128k|}
scconf_get_str:
  152|  52.1k|{
  153|  52.1k|	const scconf_list *list;
  154|       |
  155|  52.1k|	list = scconf_find_list(block, option);
  156|  52.1k|	if (!list || !list->data)
  ------------------
  |  Branch (156:6): [True: 52.1k, False: 0]
  |  Branch (156:15): [True: 0, False: 0]
  ------------------
  157|  52.1k|		return def;
  158|       |
  159|       |	/* ignore non 'auto-configured' values */
  160|      0|	if (*list->data == '@' && *(list->data + strlen(list->data) - 1) == '@')
  ------------------
  |  Branch (160:6): [True: 0, False: 0]
  |  Branch (160:28): [True: 0, False: 0]
  ------------------
  161|      0|		return def;
  162|       |
  163|      0|	return list->data;
  164|      0|}
scconf_get_int:
  167|  16.1k|{
  168|  16.1k|	const scconf_list *list;
  169|  16.1k|	long res;
  170|       |
  171|  16.1k|	list = scconf_find_list(block, option);
  172|  16.1k|	if (!list || !list->data || !*list->data) {
  ------------------
  |  Branch (172:6): [True: 16.1k, False: 0]
  |  Branch (172:15): [True: 0, False: 0]
  |  Branch (172:30): [True: 0, False: 0]
  ------------------
  173|  16.1k|		return def;
  174|  16.1k|	}
  175|      0|	res = strtol(list->data, NULL, 0);
  176|      0|	if (res <= INT_MAX) {
  ------------------
  |  Branch (176:6): [True: 0, False: 0]
  ------------------
  177|      0|		return (int)res;
  178|      0|	}
  179|      0|	return def;
  180|      0|}
scconf_get_bool:
  183|  74.4k|{
  184|  74.4k|	const scconf_list *list;
  185|       |
  186|  74.4k|	list = scconf_find_list(block, option);
  187|  74.4k|	if (!list || !list->data || !*list->data) {
  ------------------
  |  Branch (187:6): [True: 74.4k, False: 0]
  |  Branch (187:15): [True: 0, False: 0]
  |  Branch (187:30): [True: 0, False: 0]
  ------------------
  188|  74.4k|		return def;
  189|  74.4k|	}
  190|      0|	return toupper((int)(unsigned char)*list->data) == 'T' || toupper((int)(unsigned char)*list->data) == 'Y';
  ------------------
  |  Branch (190:9): [True: 0, False: 0]
  |  Branch (190:60): [True: 0, False: 0]
  ------------------
  191|  74.4k|}
scconf_item_destroy:
  268|  32.2k|{
  269|  32.2k|	scconf_item *next;
  270|       |
  271|  64.4k|	while (item) {
  ------------------
  |  Branch (271:9): [True: 32.2k, False: 32.2k]
  ------------------
  272|  32.2k|		next = item->next;
  273|       |
  274|  32.2k|		switch (item->type) {
  ------------------
  |  Branch (274:11): [True: 32.2k, False: 0]
  ------------------
  275|      0|		case SCCONF_ITEM_TYPE_COMMENT:
  ------------------
  |  |   42|      0|#define SCCONF_ITEM_TYPE_COMMENT	0	/* key = NULL, comment */
  ------------------
  |  Branch (275:3): [True: 0, False: 32.2k]
  ------------------
  276|      0|			if (item->value.comment) {
  ------------------
  |  Branch (276:8): [True: 0, False: 0]
  ------------------
  277|      0|				free(item->value.comment);
  278|      0|			}
  279|      0|			item->value.comment = NULL;
  280|      0|			break;
  281|  16.1k|		case SCCONF_ITEM_TYPE_BLOCK:
  ------------------
  |  |   43|  16.1k|#define SCCONF_ITEM_TYPE_BLOCK		1	/* key = key, block */
  ------------------
  |  Branch (281:3): [True: 16.1k, False: 16.1k]
  ------------------
  282|  16.1k|			scconf_block_destroy(item->value.block);
  283|  16.1k|			break;
  284|  16.1k|		case SCCONF_ITEM_TYPE_VALUE:
  ------------------
  |  |   44|  16.1k|#define SCCONF_ITEM_TYPE_VALUE		2	/* key = key, list */
  ------------------
  |  Branch (284:3): [True: 16.1k, False: 16.1k]
  ------------------
  285|  16.1k|			scconf_list_destroy(item->value.list);
  286|  16.1k|			break;
  287|  32.2k|		}
  288|       |
  289|  32.2k|		if (item->key) {
  ------------------
  |  Branch (289:7): [True: 32.2k, False: 0]
  ------------------
  290|  32.2k|			free(item->key);
  291|  32.2k|		}
  292|       |		item->key = NULL;
  293|  32.2k|		free(item);
  294|  32.2k|		item = next;
  295|  32.2k|	}
  296|  32.2k|}
scconf_block_destroy:
  321|  32.2k|{
  322|  32.2k|	if (block) {
  ------------------
  |  Branch (322:6): [True: 32.2k, False: 0]
  ------------------
  323|  32.2k|		scconf_list_destroy(block->name);
  324|  32.2k|		scconf_item_destroy(block->items);
  325|  32.2k|		free(block);
  326|  32.2k|	}
  327|  32.2k|}
scconf_list_add:
  330|  48.3k|{
  331|  48.3k|	scconf_list *rec, **tmp;
  332|       |
  333|  48.3k|	if (!list)
  ------------------
  |  Branch (333:6): [True: 0, False: 48.3k]
  ------------------
  334|      0|		return NULL;
  335|       |
  336|  48.3k|	rec = calloc(1, sizeof(scconf_list));
  337|  48.3k|	if (!rec) {
  ------------------
  |  Branch (337:6): [True: 0, False: 48.3k]
  ------------------
  338|      0|		return NULL;
  339|      0|	}
  340|  48.3k|	rec->data = value ? strdup(value) : NULL;
  ------------------
  |  Branch (340:14): [True: 48.3k, False: 0]
  ------------------
  341|       |
  342|  48.3k|	if (!*list) {
  ------------------
  |  Branch (342:6): [True: 32.2k, False: 16.1k]
  ------------------
  343|  32.2k|		*list = rec;
  344|  32.2k|	} else {
  345|  32.2k|		for (tmp = list; *tmp; tmp = &(*tmp)->next);
  ------------------
  |  Branch (345:20): [True: 16.1k, False: 16.1k]
  ------------------
  346|  16.1k|		*tmp = rec;
  347|  16.1k|	}
  348|  48.3k|	return rec;
  349|  48.3k|}
scconf_list_destroy:
  364|   112k|{
  365|   112k|	scconf_list *next;
  366|       |
  367|   161k|	while (list) {
  ------------------
  |  Branch (367:9): [True: 48.3k, False: 112k]
  ------------------
  368|  48.3k|		next = list->next;
  369|  48.3k|		if (list->data) {
  ------------------
  |  Branch (369:7): [True: 48.3k, False: 0]
  ------------------
  370|  48.3k|			free(list->data);
  371|  48.3k|		}
  372|  48.3k|		free(list);
  373|  48.3k|		list = next;
  374|  48.3k|	}
  375|   112k|}

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

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

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

sc_notify:
  548|     35|void sc_notify(const char *title, const char *text) {}
sc_notify_id:
  550|    544|		struct sc_pkcs15_card *p15card, enum ui_str id) {}

