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

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

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

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

_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|   458k|		while (--n != 0) {
  ------------------
  |  Branch (43:10): [True: 458k, False: 0]
  ------------------
   44|   458k|			if ((*d++ = *s++) == '\0')
  ------------------
  |  Branch (44:8): [True: 25.1k, False: 432k]
  ------------------
   45|  25.1k|				break;
   46|   458k|		}
   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|  47.8k|{
   86|  47.8k|	return constant_time_msb(~a & (a - 1));
   87|  47.8k|}
padding.c:constant_time_msb:
   59|  52.5k|{
   60|  52.5k|	return 0 - (a >> (sizeof(a) * 8 - 1));
   61|  52.5k|}
padding.c:constant_time_eq:
  118|    835|{
  119|    835|	return constant_time_is_zero(a ^ b);
  120|    835|}
padding.c:constant_time_select:
   66|   192k|{
   67|   192k|	return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
   68|   192k|}
padding.c:value_barrier:
   38|   384k|{
   39|   384k|	volatile unsigned int r = a;
   40|   384k|	return r;
   41|   384k|}
padding.c:constant_time_ge:
  110|    186|{
  111|    186|	return ~constant_time_lt(a, b);
  112|    186|}
padding.c:constant_time_lt:
  104|  4.67k|{
  105|  4.67k|	return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
  106|  4.67k|}
padding.c:constant_time_select_8:
   72|   164k|{
   73|   164k|	return (unsigned char)constant_time_select(mask, a, b);
   74|   164k|}

list_init:
  235|  19.8k|int list_init(list_t *simclist_restrict l) {
  236|  19.8k|    if (l == NULL) {
  ------------------
  |  Branch (236:9): [True: 0, False: 19.8k]
  ------------------
  237|      0|        return -1;
  238|      0|    }
  239|       |
  240|  19.8k|    memset(l, 0, sizeof *l);
  241|       |
  242|  19.8k|    seed_random();
  243|       |
  244|  19.8k|    l->numels = 0;
  245|       |
  246|       |    /* head/tail sentinels and mid pointer */
  247|  19.8k|    l->head_sentinel = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
  248|  19.8k|    l->tail_sentinel = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
  249|  19.8k|    if (l->tail_sentinel == NULL || l->head_sentinel == NULL) {
  ------------------
  |  Branch (249:9): [True: 0, False: 19.8k]
  |  Branch (249:37): [True: 0, False: 19.8k]
  ------------------
  250|      0|        return -1;
  251|      0|    }
  252|  19.8k|    l->head_sentinel->next = l->tail_sentinel;
  253|  19.8k|    l->tail_sentinel->prev = l->head_sentinel;
  254|  19.8k|    l->head_sentinel->prev = l->tail_sentinel->next = l->mid = NULL;
  255|  19.8k|    l->head_sentinel->data = l->tail_sentinel->data = NULL;
  256|       |
  257|       |    /* iteration attributes */
  258|  19.8k|    l->iter_active = 0;
  259|  19.8k|    l->iter_pos = 0;
  260|  19.8k|    l->iter_curentry = NULL;
  261|       |
  262|       |    /* free-list attributes */
  263|  19.8k|    l->spareelsnum = 0;
  264|  19.8k|    l->spareels = (struct list_entry_s **)malloc(SIMCLIST_MAX_SPARE_ELEMS * sizeof(struct list_entry_s *));
  ------------------
  |  |  115|  19.8k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  265|  19.8k|    if (l->spareels == NULL) {
  ------------------
  |  Branch (265:9): [True: 0, False: 19.8k]
  ------------------
  266|      0|        return -1;
  267|      0|    }
  268|       |
  269|       |#ifdef SIMCLIST_WITH_THREADS
  270|       |    l->threadcount = 0;
  271|       |#endif
  272|       |
  273|  19.8k|    if (0 != list_attributes_setdefaults(l)) {
  ------------------
  |  Branch (273:9): [True: 0, False: 19.8k]
  ------------------
  274|      0|        return -1;
  275|      0|    }
  276|       |
  277|  19.8k|    assert(list_repOk(l));
  278|  19.8k|    assert(list_attrOk(l));
  279|       |
  280|  19.8k|    return 0;
  281|  19.8k|}
list_destroy:
  283|  19.8k|void list_destroy(list_t *simclist_restrict l) {
  284|  19.8k|    unsigned int i;
  285|       |
  286|  19.8k|    list_clear(l);
  287|  40.9k|    for (i = 0; i < l->spareelsnum; i++) {
  ------------------
  |  Branch (287:17): [True: 21.1k, False: 19.8k]
  ------------------
  288|  21.1k|        free(l->spareels[i]);
  289|  21.1k|    }
  290|  19.8k|    free(l->spareels);
  291|  19.8k|    free(l->head_sentinel);
  292|  19.8k|    free(l->tail_sentinel);
  293|  19.8k|}
list_attributes_comparator:
  315|  3.17k|int list_attributes_comparator(list_t *simclist_restrict l, element_comparator comparator_fun) {
  316|  3.17k|    if (l == NULL) return -1;
  ------------------
  |  Branch (316:9): [True: 0, False: 3.17k]
  ------------------
  317|       |
  318|  3.17k|    l->attrs.comparator = comparator_fun;
  319|       |
  320|  3.17k|    assert(list_attrOk(l));
  321|       |
  322|  3.17k|    return 0;
  323|  3.17k|}
list_attributes_seeker:
  325|  16.2k|int list_attributes_seeker(list_t *simclist_restrict l, element_seeker seeker_fun) {
  326|  16.2k|    if (l == NULL) return -1;
  ------------------
  |  Branch (326:9): [True: 0, False: 16.2k]
  ------------------
  327|       |
  328|  16.2k|    l->attrs.seeker = seeker_fun;
  329|  16.2k|    assert(list_attrOk(l));
  330|       |
  331|  16.2k|    return 0;
  332|  16.2k|}
list_attributes_copy:
  334|  4.46k|int list_attributes_copy(list_t *simclist_restrict l, element_meter metric_fun, int copy_data) {
  335|  4.46k|    if (l == NULL || (metric_fun == NULL && copy_data != 0)) return -1;
  ------------------
  |  Branch (335:9): [True: 0, False: 4.46k]
  |  Branch (335:23): [True: 0, False: 4.46k]
  |  Branch (335:45): [True: 0, False: 0]
  ------------------
  336|       |
  337|  4.46k|    l->attrs.meter = metric_fun;
  338|  4.46k|    l->attrs.copy_data = copy_data;
  339|       |
  340|  4.46k|    assert(list_attrOk(l));
  341|       |
  342|  4.46k|    return 0;
  343|  4.46k|}
list_append:
  369|  36.7k|int list_append(list_t *simclist_restrict l, const void *data) {
  370|  36.7k|    return list_insert_at(l, data, l->numels);
  371|  36.7k|}
list_get_at:
  381|  37.2k|void *list_get_at(const list_t *simclist_restrict l, unsigned int pos) {
  382|  37.2k|    struct list_entry_s *tmp;
  383|       |
  384|  37.2k|    tmp = list_findpos(l, pos);
  385|       |
  386|  37.2k|    return (tmp != NULL ? tmp->data : NULL);
  ------------------
  |  Branch (386:13): [True: 37.2k, False: 0]
  ------------------
  387|  37.2k|}
list_insert_at:
  465|  36.7k|int list_insert_at(list_t *simclist_restrict l, const void *data, unsigned int pos) {
  466|  36.7k|    struct list_entry_s *lent, *succ, *prec;
  467|       |
  468|  36.7k|    if (l->iter_active || pos > l->numels) return -1;
  ------------------
  |  Branch (468:9): [True: 0, False: 36.7k]
  |  Branch (468:27): [True: 0, False: 36.7k]
  ------------------
  469|       |
  470|       |    /* this code optimizes malloc() with a free-list */
  471|  36.7k|    if (l->spareelsnum > 0) {
  ------------------
  |  Branch (471:9): [True: 0, False: 36.7k]
  ------------------
  472|      0|        lent = l->spareels[l->spareelsnum-1];
  473|      0|        l->spareelsnum--;
  474|  36.7k|    } else {
  475|  36.7k|        lent = (struct list_entry_s *)malloc(sizeof(struct list_entry_s));
  476|  36.7k|        if (lent == NULL) {
  ------------------
  |  Branch (476:13): [True: 0, False: 36.7k]
  ------------------
  477|      0|            return -1;
  478|      0|        }
  479|  36.7k|    }
  480|       |
  481|  36.7k|    if (l->attrs.copy_data) {
  ------------------
  |  Branch (481:9): [True: 21.3k, False: 15.3k]
  ------------------
  482|       |        /* make room for user' data (has to be copied) */
  483|  21.3k|        size_t datalen = l->attrs.meter(data);
  484|  21.3k|        lent->data = (struct list_entry_s *)malloc(datalen);
  485|  21.3k|        if (lent->data == NULL) {
  ------------------
  |  Branch (485:13): [True: 0, False: 21.3k]
  ------------------
  486|      0|            if (!(l->spareelsnum > 0)) {
  ------------------
  |  Branch (486:17): [True: 0, False: 0]
  ------------------
  487|      0|                free(lent);
  488|      0|            }
  489|      0|            return -1;
  490|      0|        }
  491|  21.3k|        memcpy(lent->data, data, datalen);
  492|  21.3k|    } else {
  493|  15.3k|        lent->data = (void*)data;
  494|  15.3k|    }
  495|       |
  496|       |    /* actually append element */
  497|  36.7k|    prec = list_findpos(l, pos-1);
  498|  36.7k|    if (prec == NULL) {
  ------------------
  |  Branch (498:9): [True: 0, False: 36.7k]
  ------------------
  499|      0|        if (l->attrs.copy_data) {
  ------------------
  |  Branch (499:13): [True: 0, False: 0]
  ------------------
  500|      0|            free(lent->data);
  501|      0|        }
  502|      0|        if (!(l->spareelsnum > 0)) {
  ------------------
  |  Branch (502:13): [True: 0, False: 0]
  ------------------
  503|      0|            free(lent);
  504|      0|        }
  505|      0|        return -1;
  506|      0|    }
  507|  36.7k|    succ = prec->next;
  508|       |
  509|  36.7k|    prec->next = lent;
  510|  36.7k|    lent->prev = prec;
  511|  36.7k|    lent->next = succ;
  512|  36.7k|    succ->prev = lent;
  513|       |
  514|  36.7k|    l->numels++;
  515|       |
  516|       |    /* fix mid pointer */
  517|  36.7k|    if (l->numels == 1) { /* first element, set pointer */
  ------------------
  |  Branch (517:9): [True: 17.1k, False: 19.5k]
  ------------------
  518|  17.1k|        l->mid = lent;
  519|  19.5k|    } else if (l->numels % 2) {    /* now odd */
  ------------------
  |  Branch (519:16): [True: 9.49k, False: 10.1k]
  ------------------
  520|  9.49k|        if (pos >= (l->numels-1)/2) l->mid = l->mid->next;
  ------------------
  |  Branch (520:13): [True: 9.49k, False: 0]
  ------------------
  521|  10.1k|    } else {                /* now even */
  522|  10.1k|        if (pos <= (l->numels-1)/2) l->mid = l->mid->prev;
  ------------------
  |  Branch (522:13): [True: 0, False: 10.1k]
  ------------------
  523|  10.1k|    }
  524|       |
  525|  36.7k|    assert(list_repOk(l));
  526|       |
  527|  36.7k|    return 1;
  528|  36.7k|}
list_delete:
  530|  15.3k|int list_delete(list_t *simclist_restrict l, const void *data) {
  531|  15.3k|	int pos, r;
  532|       |
  533|  15.3k|	pos = list_locate(l, data);
  534|  15.3k|	if (pos < 0)
  ------------------
  |  Branch (534:6): [True: 0, False: 15.3k]
  ------------------
  535|      0|		return -1;
  536|       |
  537|  15.3k|	r = list_delete_at(l, pos);
  538|  15.3k|	if (r < 0)
  ------------------
  |  Branch (538:6): [True: 0, False: 15.3k]
  ------------------
  539|      0|		return -1;
  540|       |
  541|  15.3k|    assert(list_repOk(l));
  542|       |
  543|  15.3k|	return 0;
  544|  15.3k|}
list_delete_at:
  546|  15.3k|int list_delete_at(list_t *simclist_restrict l, unsigned int pos) {
  547|  15.3k|    struct list_entry_s *delendo;
  548|       |
  549|       |
  550|  15.3k|    if (l->iter_active || pos >= l->numels) return -1;
  ------------------
  |  Branch (550:9): [True: 0, False: 15.3k]
  |  Branch (550:27): [True: 0, False: 15.3k]
  ------------------
  551|       |
  552|  15.3k|    delendo = list_findpos(l, pos);
  553|       |
  554|  15.3k|    list_drop_elem(l, delendo, pos);
  555|       |
  556|  15.3k|    l->numels--;
  557|       |
  558|       |
  559|  15.3k|    assert(list_repOk(l));
  560|       |
  561|  15.3k|    return  0;
  562|  15.3k|}
list_clear:
  629|  19.8k|int list_clear(list_t *simclist_restrict l) {
  630|  19.8k|    struct list_entry_s *s;
  631|       |
  632|  19.8k|    if (l->iter_active) return -1;
  ------------------
  |  Branch (632:9): [True: 0, False: 19.8k]
  ------------------
  633|       |
  634|  19.8k|    if (l->head_sentinel && l->tail_sentinel) {
  ------------------
  |  Branch (634:9): [True: 19.8k, False: 0]
  |  Branch (634:29): [True: 19.8k, False: 0]
  ------------------
  635|  19.8k|        if (l->attrs.copy_data) {        /* also free user data */
  ------------------
  |  Branch (635:13): [True: 4.46k, False: 15.3k]
  ------------------
  636|       |            /* spare a loop conditional with two loops: spareing elems and freeing elems */
  637|  10.2k|            for (s = l->head_sentinel->next; l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS && s != l->tail_sentinel; s = s->next) {
  ------------------
  |  |  115|  20.5k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  |  Branch (637:46): [True: 9.44k, False: 842]
  |  Branch (637:91): [True: 5.81k, False: 3.62k]
  ------------------
  638|       |                /* move elements as spares as long as there is room */
  639|  5.81k|                if (s->data != NULL) free(s->data);
  ------------------
  |  Branch (639:21): [True: 5.81k, False: 0]
  ------------------
  640|  5.81k|                l->spareels[l->spareelsnum++] = s;
  641|  5.81k|            }
  642|  20.0k|            while (s != l->tail_sentinel) {
  ------------------
  |  Branch (642:20): [True: 15.5k, False: 4.46k]
  ------------------
  643|       |                /* free the remaining elems */
  644|  15.5k|                if (s->data != NULL) free(s->data);
  ------------------
  |  Branch (644:21): [True: 15.5k, False: 0]
  ------------------
  645|  15.5k|                s = s->next;
  646|  15.5k|                free(s->prev);
  647|  15.5k|            }
  648|  4.46k|            l->head_sentinel->next = l->tail_sentinel;
  649|  4.46k|            l->tail_sentinel->prev = l->head_sentinel;
  650|  15.3k|        } else { /* only free element containers */
  651|       |            /* spare a loop conditional with two loops: spareing elems and freeing elems */
  652|  15.3k|            for (s = l->head_sentinel->next; l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS && s != l->tail_sentinel; s = s->next) {
  ------------------
  |  |  115|  30.6k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  |  Branch (652:46): [True: 15.3k, False: 0]
  |  Branch (652:91): [True: 0, False: 15.3k]
  ------------------
  653|       |                /* move elements as spares as long as there is room */
  654|      0|                l->spareels[l->spareelsnum++] = s;
  655|      0|            }
  656|  15.3k|            while (s != l->tail_sentinel) {
  ------------------
  |  Branch (656:20): [True: 0, False: 15.3k]
  ------------------
  657|       |                /* free the remaining elems */
  658|      0|                s = s->next;
  659|      0|                free(s->prev);
  660|      0|            }
  661|  15.3k|            l->head_sentinel->next = l->tail_sentinel;
  662|  15.3k|            l->tail_sentinel->prev = l->head_sentinel;
  663|  15.3k|        }
  664|  19.8k|    }
  665|  19.8k|    l->numels = 0;
  666|  19.8k|    l->mid = NULL;
  667|       |
  668|  19.8k|    assert(list_repOk(l));
  669|       |
  670|  19.8k|    return 0;
  671|  19.8k|}
list_size:
  673|  48.5k|unsigned int list_size(const list_t *simclist_restrict l) {
  674|  48.5k|    return l->numels;
  675|  48.5k|}
list_locate:
  681|  40.5k|int list_locate(const list_t *simclist_restrict l, const void *data) {
  682|  40.5k|    struct list_entry_s *el;
  683|  40.5k|    int pos = 0;
  684|       |
  685|  40.5k|    if (l->head_sentinel == NULL || l->tail_sentinel == NULL) return -1;
  ------------------
  |  Branch (685:9): [True: 0, False: 40.5k]
  |  Branch (685:37): [True: 0, False: 40.5k]
  ------------------
  686|       |
  687|  40.5k|    if (l->attrs.comparator != NULL) {
  ------------------
  |  Branch (687:9): [True: 25.2k, False: 15.3k]
  ------------------
  688|       |        /* use comparator */
  689|   304k|        for (el = l->head_sentinel->next; el != l->tail_sentinel; el = el->next, pos++) {
  ------------------
  |  Branch (689:43): [True: 288k, False: 16.0k]
  ------------------
  690|   288k|            if (l->attrs.comparator(data, el->data) == 0) break;
  ------------------
  |  Branch (690:17): [True: 9.23k, False: 279k]
  ------------------
  691|   288k|        }
  692|  25.2k|    } else {
  693|       |        /* compare references */
  694|  15.3k|        for (el = l->head_sentinel->next; el != l->tail_sentinel; el = el->next, pos++) {
  ------------------
  |  Branch (694:43): [True: 15.3k, False: 0]
  ------------------
  695|  15.3k|            if (el->data == data) break;
  ------------------
  |  Branch (695:17): [True: 15.3k, False: 0]
  ------------------
  696|  15.3k|        }
  697|  15.3k|    }
  698|  40.5k|    if (el == l->tail_sentinel) return -1;
  ------------------
  |  Branch (698:9): [True: 16.0k, False: 24.5k]
  ------------------
  699|       |
  700|  24.5k|    return pos;
  701|  40.5k|}
list_seek:
  703|    552|void *list_seek(list_t *simclist_restrict l, const void *indicator) {
  704|    552|    const struct list_entry_s *iter;
  705|       |
  706|    552|    if (l->attrs.seeker == NULL) return NULL;
  ------------------
  |  Branch (706:9): [True: 0, False: 552]
  ------------------
  707|       |
  708|    552|    if (l->head_sentinel == NULL || l->tail_sentinel == NULL) return NULL;
  ------------------
  |  Branch (708:9): [True: 0, False: 552]
  |  Branch (708:37): [True: 0, False: 552]
  ------------------
  709|       |
  710|  1.36k|    for (iter = l->head_sentinel->next; iter != l->tail_sentinel; iter = iter->next) {
  ------------------
  |  Branch (710:41): [True: 941, False: 425]
  ------------------
  711|    941|        if (l->attrs.seeker(iter->data, indicator) != 0) return iter->data;
  ------------------
  |  Branch (711:13): [True: 127, False: 814]
  ------------------
  712|    941|    }
  713|       |
  714|    425|    return NULL;
  715|    552|}
list_contains:
  717|  9.59k|int list_contains(const list_t *simclist_restrict l, const void *data) {
  718|  9.59k|    return (list_locate(l, data) >= 0);
  719|  9.59k|}
list_iterator_start:
  962|  6.45k|int list_iterator_start(list_t *simclist_restrict l) {
  963|  6.45k|    if (l->iter_active) return 0;
  ------------------
  |  Branch (963:9): [True: 0, False: 6.45k]
  ------------------
  964|  6.45k|    if (l->head_sentinel == NULL) return -1;
  ------------------
  |  Branch (964:9): [True: 0, False: 6.45k]
  ------------------
  965|  6.45k|    l->iter_pos = 0;
  966|  6.45k|    l->iter_active = 1;
  967|  6.45k|    l->iter_curentry = l->head_sentinel->next;
  968|  6.45k|    return 1;
  969|  6.45k|}
list_iterator_next:
  971|  61.1k|void *list_iterator_next(list_t *simclist_restrict l) {
  972|  61.1k|    void *toret;
  973|       |
  974|  61.1k|    if (! l->iter_active) return NULL;
  ------------------
  |  Branch (974:9): [True: 0, False: 61.1k]
  ------------------
  975|       |
  976|  61.1k|    toret = l->iter_curentry->data;
  977|  61.1k|    l->iter_curentry = l->iter_curentry->next;
  978|  61.1k|    l->iter_pos++;
  979|       |
  980|  61.1k|    return toret;
  981|  61.1k|}
list_iterator_hasnext:
  983|  56.7k|int list_iterator_hasnext(const list_t *simclist_restrict l) {
  984|  56.7k|    if (! l->iter_active) return 0;
  ------------------
  |  Branch (984:9): [True: 0, False: 56.7k]
  ------------------
  985|  56.7k|    return (l->iter_pos < l->numels);
  986|  56.7k|}
list_iterator_stop:
  988|  6.45k|int list_iterator_stop(list_t *simclist_restrict l) {
  989|  6.45k|    if (! l->iter_active) return 0;
  ------------------
  |  Branch (989:9): [True: 0, False: 6.45k]
  ------------------
  990|  6.45k|    l->iter_pos = 0;
  991|  6.45k|    l->iter_active = 0;
  992|  6.45k|    return 1;
  993|  6.45k|}
simclist.c:list_attributes_setdefaults:
  295|  19.8k|int list_attributes_setdefaults(list_t *simclist_restrict l) {
  296|  19.8k|    l->attrs.comparator = NULL;
  297|  19.8k|    l->attrs.seeker = NULL;
  298|       |
  299|       |    /* also free() element data when removing and element from the list */
  300|  19.8k|    l->attrs.meter = NULL;
  301|  19.8k|    l->attrs.copy_data = 0;
  302|       |
  303|  19.8k|    l->attrs.hasher = NULL;
  304|       |
  305|       |    /* serializer/unserializer */
  306|  19.8k|    l->attrs.serializer = NULL;
  307|  19.8k|    l->attrs.unserializer = NULL;
  308|       |
  309|  19.8k|    assert(list_attrOk(l));
  310|       |
  311|  19.8k|    return 0;
  312|  19.8k|}
simclist.c:list_findpos:
  416|  89.2k|static simclist_inline struct list_entry_s *list_findpos(const list_t *simclist_restrict l, int posstart) {
  417|  89.2k|    struct list_entry_s *ptr;
  418|  89.2k|    float x;
  419|  89.2k|    int i;
  420|       |
  421|  89.2k|    if (l->head_sentinel == NULL || l->tail_sentinel == NULL) return NULL;
  ------------------
  |  Branch (421:9): [True: 0, False: 89.2k]
  |  Branch (421:37): [True: 0, False: 89.2k]
  ------------------
  422|       |
  423|       |    /* accept 1 slot overflow for fetching head and tail sentinels */
  424|  89.2k|    if (posstart < -1 || posstart > (int)l->numels) return NULL;
  ------------------
  |  Branch (424:9): [True: 0, False: 89.2k]
  |  Branch (424:26): [True: 0, False: 89.2k]
  ------------------
  425|       |
  426|  89.2k|    x = l->numels ? (float)(posstart+1) / l->numels : 0;
  ------------------
  |  Branch (426:9): [True: 72.1k, False: 17.1k]
  ------------------
  427|  89.2k|    if (x <= 0.25) {
  ------------------
  |  Branch (427:9): [True: 18.5k, False: 70.7k]
  ------------------
  428|       |        /* first quarter: get to posstart from head */
  429|  24.4k|        for (i = -1, ptr = l->head_sentinel; i < posstart; ptr = ptr->next, i++);
  ------------------
  |  Branch (429:46): [True: 5.86k, False: 18.5k]
  ------------------
  430|  70.7k|    } else if (x < 0.5) {
  ------------------
  |  Branch (430:16): [True: 1.87k, False: 68.8k]
  ------------------
  431|       |        /* second quarter: get to posstart from mid */
  432|  8.23k|        for (i = (l->numels-1)/2, ptr = l->mid; i > posstart; ptr = ptr->prev, i--);
  ------------------
  |  Branch (432:49): [True: 6.36k, False: 1.87k]
  ------------------
  433|  68.8k|    } else if (x <= 0.75) {
  ------------------
  |  Branch (433:16): [True: 1.71k, False: 67.1k]
  ------------------
  434|       |        /* third quarter: get to posstart from mid */
  435|  5.80k|        for (i = (l->numels-1)/2, ptr = l->mid; i < posstart; ptr = ptr->next, i++);
  ------------------
  |  Branch (435:49): [True: 4.08k, False: 1.71k]
  ------------------
  436|  67.1k|    } else {
  437|       |        /* fourth quarter: get to posstart from tail */
  438|   137k|        for (i = l->numels, ptr = l->tail_sentinel; i > posstart; ptr = ptr->prev, i--);
  ------------------
  |  Branch (438:53): [True: 70.5k, False: 67.1k]
  ------------------
  439|  67.1k|    }
  440|       |
  441|  89.2k|    return ptr;
  442|  89.2k|}
simclist.c:list_drop_elem:
 1427|  15.3k|static int list_drop_elem(list_t *simclist_restrict l, struct list_entry_s *tmp, unsigned int pos) {
 1428|  15.3k|    if (tmp == NULL) return -1;
  ------------------
  |  Branch (1428:9): [True: 0, False: 15.3k]
  ------------------
 1429|       |
 1430|       |    /* fix mid pointer. This is wrt the PRE situation */
 1431|  15.3k|    if (l->numels % 2) {    /* now odd */
  ------------------
  |  Branch (1431:9): [True: 15.3k, False: 0]
  ------------------
 1432|       |        /* sort out the base case by hand */
 1433|  15.3k|        if (l->numels == 1) l->mid = NULL;
  ------------------
  |  Branch (1433:13): [True: 15.3k, False: 0]
  ------------------
 1434|      0|        else if (pos >= l->numels/2) l->mid = l->mid->prev;
  ------------------
  |  Branch (1434:18): [True: 0, False: 0]
  ------------------
 1435|  15.3k|    } else {                /* now even */
 1436|      0|        if (pos < l->numels/2) l->mid = l->mid->next;
  ------------------
  |  Branch (1436:13): [True: 0, False: 0]
  ------------------
 1437|      0|    }
 1438|       |
 1439|  15.3k|    tmp->prev->next = tmp->next;
 1440|  15.3k|    tmp->next->prev = tmp->prev;
 1441|       |
 1442|       |    /* free what's to be freed */
 1443|  15.3k|    if (l->attrs.copy_data && tmp->data != NULL)
  ------------------
  |  Branch (1443:9): [True: 0, False: 15.3k]
  |  Branch (1443:31): [True: 0, False: 0]
  ------------------
 1444|      0|        free(tmp->data);
 1445|       |
 1446|  15.3k|    if (l->spareels != NULL && l->spareelsnum < SIMCLIST_MAX_SPARE_ELEMS) {
  ------------------
  |  |  115|  15.3k|#define SIMCLIST_MAX_SPARE_ELEMS        5
  ------------------
  |  Branch (1446:9): [True: 15.3k, False: 0]
  |  Branch (1446:32): [True: 15.3k, False: 0]
  ------------------
 1447|  15.3k|        l->spareels[l->spareelsnum++] = tmp;
 1448|  15.3k|    } else {
 1449|      0|        free(tmp);
 1450|      0|    }
 1451|       |
 1452|  15.3k|    return 0;
 1453|  15.3k|}

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

sc_asn1_read_tag:
   64|   310k|{
   65|   310k|	const u8 *p = *buf;
   66|   310k|	size_t left = buflen, len;
   67|   310k|	unsigned int cla, tag, i;
   68|       |
   69|   310k|	*buf = NULL;
   70|       |
   71|   310k|	if (left == 0 || !p || buflen == 0)
  ------------------
  |  Branch (71:6): [True: 1.11k, False: 309k]
  |  Branch (71:19): [True: 0, False: 309k]
  |  Branch (71:25): [True: 0, False: 309k]
  ------------------
   72|  1.11k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.11k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   73|   309k|	if (*p == 0xff || *p == 0) {
  ------------------
  |  Branch (73:6): [True: 2.26k, False: 306k]
  |  Branch (73:20): [True: 13.9k, False: 292k]
  ------------------
   74|       |		/* end of data reached */
   75|  16.2k|		*taglen = 0;
   76|  16.2k|		*tag_out = SC_ASN1_TAG_EOC;
  ------------------
  |  |  194|  16.2k|#define SC_ASN1_TAG_EOC			0
  ------------------
   77|  16.2k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.2k|#define SC_SUCCESS				0
  ------------------
   78|  16.2k|	}
   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|   292k|	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  184|   292k|#define SC_ASN1_TAG_CLASS		0xC0
  ------------------
              	cla = (*p & SC_ASN1_TAG_CLASS) | (*p & SC_ASN1_TAG_CONSTRUCTED);
  ------------------
  |  |  190|   292k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
   85|   292k|	tag = *p & SC_ASN1_TAG_PRIMITIVE;
  ------------------
  |  |  191|   292k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
   86|   292k|	if (left < 1)
  ------------------
  |  Branch (86:6): [True: 0, False: 292k]
  ------------------
   87|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   88|   292k|	p++;
   89|   292k|	left--;
   90|   292k|	if (tag == SC_ASN1_TAG_PRIMITIVE) {
  ------------------
  |  |  191|   292k|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
  |  Branch (90:6): [True: 2.68k, False: 290k]
  ------------------
   91|       |		/* high tag number */
   92|  2.68k|		size_t n = SC_ASN1_TAGNUM_SIZE - 1;
  ------------------
  |  |  145|  2.68k|#define SC_ASN1_TAGNUM_SIZE		3
  ------------------
   93|       |		/* search the last tag octet */
   94|  4.03k|		do {
   95|  4.03k|			if (left == 0 || n == 0)
  ------------------
  |  Branch (95:8): [True: 172, False: 3.86k]
  |  Branch (95:21): [True: 119, False: 3.74k]
  ------------------
   96|       |				/* either an invalid tag or it doesn't fit in
   97|       |				 * unsigned int */
   98|    291|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    291|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
   99|  3.74k|			tag <<= 8;
  100|  3.74k|			tag |= *p;
  101|  3.74k|			p++;
  102|  3.74k|			left--;
  103|  3.74k|			n--;
  104|  3.74k|		} while (tag & 0x80);
  ------------------
  |  Branch (104:12): [True: 1.35k, False: 2.39k]
  ------------------
  105|  2.68k|	}
  106|       |
  107|       |	/* parse length byte(s) */
  108|   292k|	if (left == 0)
  ------------------
  |  Branch (108:6): [True: 1.88k, False: 290k]
  ------------------
  109|  1.88k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  1.88k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  110|   290k|	len = *p;
  111|   290k|	p++;
  112|   290k|	left--;
  113|   290k|	if (len & 0x80) {
  ------------------
  |  Branch (113:6): [True: 47.4k, False: 243k]
  ------------------
  114|  47.4k|		len &= 0x7f;
  115|  47.4k|		unsigned int a = 0;
  116|  47.4k|		if (len > sizeof a || len > left)
  ------------------
  |  Branch (116:7): [True: 12.3k, False: 35.0k]
  |  Branch (116:25): [True: 630, False: 34.4k]
  ------------------
  117|  12.9k|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  12.9k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  118|  59.4k|		for (i = 0; i < len; i++) {
  ------------------
  |  Branch (118:15): [True: 24.9k, False: 34.4k]
  ------------------
  119|  24.9k|			a <<= 8;
  120|  24.9k|			a |= *p;
  121|  24.9k|			p++;
  122|  24.9k|			left--;
  123|  24.9k|		}
  124|  34.4k|		len = a;
  125|  34.4k|	}
  126|       |
  127|   277k|	*cla_out = cla;
  128|   277k|	*tag_out = tag;
  129|   277k|	*taglen = len;
  130|   277k|	*buf = p;
  131|       |
  132|   277k|	if (len > left)
  ------------------
  |  Branch (132:6): [True: 20.5k, False: 257k]
  ------------------
  133|  20.5k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  20.5k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  134|       |
  135|   257k|	return SC_SUCCESS;
  ------------------
  |  |   28|   257k|#define SC_SUCCESS				0
  ------------------
  136|   277k|}
sc_format_asn1_entry:
  140|   269k|{
  141|   269k|	entry->parm = parm;
  142|   269k|	entry->arg  = arg;
  143|   269k|	if (set_present)
  ------------------
  |  Branch (143:6): [True: 39.4k, False: 229k]
  ------------------
  144|  39.4k|		entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  39.4k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  145|   269k|}
sc_copy_asn1_entry:
  149|  92.1k|{
  150|   365k|	while (src->name != NULL) {
  ------------------
  |  Branch (150:9): [True: 273k, False: 92.1k]
  ------------------
  151|   273k|		*dest = *src;
  152|   273k|		dest++;
  153|   273k|		src++;
  154|   273k|	}
  155|       |	dest->name = NULL;
  156|  92.1k|}
sc_asn1_find_tag:
  486|  50.9k|{
  487|  50.9k|	size_t left = buflen, taglen;
  488|  50.9k|	const u8 *p = buf;
  489|       |
  490|  50.9k|	*taglen_in = 0;
  491|   112k|	while (left >= 2) {
  ------------------
  |  Branch (491:9): [True: 103k, False: 8.89k]
  ------------------
  492|   103k|		unsigned int cla = 0, tag, mask = 0xff00;
  493|       |
  494|   103k|		buf = p;
  495|       |		/* read a tag */
  496|   103k|		if (sc_asn1_read_tag(&p, left, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   207k|#define SC_SUCCESS				0
  ------------------
  |  Branch (496:7): [True: 10.2k, False: 93.3k]
  ------------------
  497|  93.3k|				|| p == NULL)
  ------------------
  |  Branch (497:8): [True: 7.95k, False: 85.3k]
  ------------------
  498|  18.1k|			return NULL;
  499|       |
  500|  85.3k|		left -= (p - buf);
  501|       |		/* we need to shift the class byte to the leftmost
  502|       |		 * byte of the tag */
  503|  87.3k|		while ((tag & mask) != 0) {
  ------------------
  |  Branch (503:10): [True: 1.95k, False: 85.3k]
  ------------------
  504|  1.95k|			cla  <<= 8;
  505|  1.95k|			mask <<= 8;
  506|  1.95k|		}
  507|       |		/* compare the read tag with the given tag */
  508|  85.3k|		if ((tag | cla) == tag_in) {
  ------------------
  |  Branch (508:7): [True: 23.8k, False: 61.4k]
  ------------------
  509|       |			/* we have a match => return length and value part */
  510|  23.8k|			if (taglen > left)
  ------------------
  |  Branch (510:8): [True: 0, False: 23.8k]
  ------------------
  511|      0|				return NULL;
  512|  23.8k|			*taglen_in = taglen;
  513|  23.8k|			return p;
  514|  23.8k|		}
  515|       |		/* otherwise continue reading tags */
  516|  61.4k|		left -= taglen;
  517|  61.4k|		p += taglen;
  518|  61.4k|	}
  519|  8.89k|	return NULL;
  520|  50.9k|}
sc_asn1_skip_tag:
  524|   133k|{
  525|   133k|	const u8 *p = *buf;
  526|   133k|	size_t len = *buflen, taglen;
  527|   133k|	unsigned int cla = 0, tag;
  528|       |
  529|   133k|	if (sc_asn1_read_tag((const u8 **) &p, len, &cla, &tag, &taglen) != SC_SUCCESS
  ------------------
  |  |   28|   267k|#define SC_SUCCESS				0
  ------------------
  |  Branch (529:6): [True: 20.2k, False: 113k]
  ------------------
  530|   113k|			|| p == NULL)
  ------------------
  |  Branch (530:7): [True: 6.00k, False: 107k]
  ------------------
  531|  26.2k|		return NULL;
  532|   107k|	switch (cla & 0xC0) {
  ------------------
  |  Branch (532:10): [True: 107k, False: 0]
  ------------------
  533|  63.5k|	case SC_ASN1_TAG_UNIVERSAL:
  ------------------
  |  |  185|  63.5k|#define SC_ASN1_TAG_UNIVERSAL		0x00
  ------------------
  |  Branch (533:2): [True: 63.5k, False: 43.8k]
  ------------------
  534|  63.5k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  136|  63.5k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_UNI)
  ------------------
  |  |  137|  63.5k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (534:7): [True: 6.47k, False: 57.0k]
  ------------------
  535|  6.47k|			return NULL;
  536|  57.0k|		break;
  537|  57.0k|	case SC_ASN1_TAG_APPLICATION:
  ------------------
  |  |  186|  6.59k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
  |  Branch (537:2): [True: 6.59k, False: 100k]
  ------------------
  538|  6.59k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  136|  6.59k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_APP)
  ------------------
  |  |  138|  6.59k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (538:7): [True: 1.61k, False: 4.97k]
  ------------------
  539|  1.61k|			return NULL;
  540|  4.97k|		break;
  541|  35.8k|	case SC_ASN1_TAG_CONTEXT:
  ------------------
  |  |  187|  35.8k|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
  |  Branch (541:2): [True: 35.8k, False: 71.4k]
  ------------------
  542|  35.8k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  136|  35.8k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_CTX)
  ------------------
  |  |  139|  35.8k|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (542:7): [True: 2.31k, False: 33.5k]
  ------------------
  543|  2.31k|			return NULL;
  544|  33.5k|		break;
  545|  33.5k|	case SC_ASN1_TAG_PRIVATE:
  ------------------
  |  |  188|  1.35k|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
  |  Branch (545:2): [True: 1.35k, False: 105k]
  ------------------
  546|  1.35k|		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  136|  1.35k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
              		if ((tag_in & SC_ASN1_CLASS_MASK) != SC_ASN1_PRV)
  ------------------
  |  |  140|  1.35k|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (546:7): [True: 1.35k, False: 0]
  ------------------
  547|  1.35k|			return NULL;
  548|      0|		break;
  549|   107k|	}
  550|  95.5k|	if (cla & SC_ASN1_TAG_CONSTRUCTED) {
  ------------------
  |  |  190|  95.5k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
  |  Branch (550:6): [True: 62.4k, False: 33.1k]
  ------------------
  551|  62.4k|		if ((tag_in & SC_ASN1_CONS) == 0)
  ------------------
  |  |  141|  62.4k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (551:7): [True: 4.97k, False: 57.4k]
  ------------------
  552|  4.97k|			return NULL;
  553|  62.4k|	} else
  554|  33.1k|		if (tag_in & SC_ASN1_CONS)
  ------------------
  |  |  141|  33.1k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (554:7): [True: 1.82k, False: 31.2k]
  ------------------
  555|  1.82k|			return NULL;
  556|  88.7k|	if ((tag_in & SC_ASN1_TAG_MASK) != tag)
  ------------------
  |  |  144|  88.7k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
  |  Branch (556:6): [True: 25.1k, False: 63.6k]
  ------------------
  557|  25.1k|		return NULL;
  558|  63.6k|	len -= (p - *buf);	/* header size */
  559|  63.6k|	if (taglen > len) {
  ------------------
  |  Branch (559:6): [True: 0, False: 63.6k]
  ------------------
  560|      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__
  |  |  ------------------
  ------------------
  561|      0|			 "too long ASN.1 object (size %"SC_FORMAT_LEN_SIZE_T"u while only %"SC_FORMAT_LEN_SIZE_T"u available)\n",
  562|      0|			 taglen, len);
  563|      0|		return NULL;
  564|      0|	}
  565|  63.6k|	*buflen -= (p - *buf) + taglen;
  566|  63.6k|	*buf = p + taglen;	/* point to next tag */
  567|  63.6k|	*taglen_out = taglen;
  568|  63.6k|	return p;
  569|  63.6k|}
sc_asn1_verify_tag:
  573|  2.57k|{
  574|  2.57k|	return sc_asn1_skip_tag(ctx, &buf, &buflen, tag_in, taglen_out);
  575|  2.57k|}
sc_asn1_decode_integer:
  734|  3.07k|{
  735|  3.07k|	int    a = 0, is_negative = 0;
  736|  3.07k|	size_t i = 0;
  737|       |
  738|  3.07k|	if (inlen == 0) {
  ------------------
  |  Branch (738:6): [True: 4, False: 3.07k]
  ------------------
  739|      4|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      4|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  740|      4|	}
  741|  3.07k|	if (inlen > sizeof(int)) {
  ------------------
  |  Branch (741:6): [True: 10, False: 3.06k]
  ------------------
  742|     10|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     10|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  743|     10|	}
  744|  3.06k|	if (inbuf[0] & 0x80) {
  ------------------
  |  Branch (744:6): [True: 1.24k, False: 1.81k]
  ------------------
  745|  1.24k|		if (strict && inlen > 1 && inbuf[0] == 0xff && (inbuf[1] & 0x80)) {
  ------------------
  |  Branch (745:7): [True: 0, False: 1.24k]
  |  Branch (745:17): [True: 0, False: 0]
  |  Branch (745:30): [True: 0, False: 0]
  |  Branch (745:50): [True: 0, False: 0]
  ------------------
  746|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  747|      0|		}
  748|  1.24k|		is_negative = 1;
  749|  1.24k|		a |= 0xff^(*inbuf++);
  750|  1.24k|		i = 1;
  751|  1.81k|	} else {
  752|  1.81k|		if (strict && inlen > 1 && inbuf[0] == 0x00 && (inbuf[1] & 0x80) == 0) {
  ------------------
  |  Branch (752:7): [True: 0, False: 1.81k]
  |  Branch (752:17): [True: 0, False: 0]
  |  Branch (752:30): [True: 0, False: 0]
  |  Branch (752:50): [True: 0, False: 0]
  ------------------
  753|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  754|      0|		}
  755|  1.81k|	}
  756|  7.04k|	for (; i < inlen; i++) {
  ------------------
  |  Branch (756:9): [True: 3.98k, False: 3.06k]
  ------------------
  757|  3.98k|		if (a > (INT_MAX >> 8) || a < (INT_MIN + (1<<8))) {
  ------------------
  |  Branch (757:7): [True: 0, False: 3.98k]
  |  Branch (757:29): [True: 0, False: 3.98k]
  ------------------
  758|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  759|      0|		}
  760|  3.98k|		a <<= 8;
  761|  3.98k|		if (is_negative) {
  ------------------
  |  Branch (761:7): [True: 1.25k, False: 2.72k]
  ------------------
  762|  1.25k|			a |= 0xff^(*inbuf++);
  763|  2.72k|		} else {
  764|  2.72k|			a |= *inbuf++;
  765|  2.72k|		}
  766|  3.98k|	}
  767|  3.06k|	if (is_negative) {
  ------------------
  |  Branch (767:6): [True: 1.24k, False: 1.81k]
  ------------------
  768|       |		/* Calculate Two's complement from previously positive number */
  769|  1.24k|		a = (-1 * a) - 1;
  770|  1.24k|	}
  771|  3.06k|	*out = a;
  772|  3.06k|	return 0;
  773|  3.06k|}
sc_asn1_decode_object_id:
  834|  9.56k|{
  835|  9.56k|	int large_second_octet = 0;
  836|  9.56k|	unsigned int a = 0;
  837|  9.56k|	const u8 *p = inbuf;
  838|  9.56k|	int *octet;
  839|       |
  840|  9.56k|	if (inlen == 0 || inbuf == NULL || id == NULL)
  ------------------
  |  Branch (840:6): [True: 1.14k, False: 8.42k]
  |  Branch (840:20): [True: 1, False: 8.41k]
  |  Branch (840:37): [True: 0, False: 8.41k]
  ------------------
  841|  1.14k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.14k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  842|       |
  843|  8.41k|	sc_init_oid(id);
  844|  8.41k|	octet = id->value;
  845|       |
  846|       |	/* The first octet can be 0, 1 or 2 and is derived from the first byte */
  847|  8.41k|	a = MIN(*p / 40, 2);
  ------------------
  |  |   70|  8.41k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 6.02k, False: 2.39k]
  |  |  ------------------
  ------------------
  848|  8.41k|	*octet++ = a;
  849|       |
  850|       |	/* The second octet fits here if the previous was 0 or 1 and second one is smaller than 40.
  851|       |	 * for the value 2 we can go up to 47. Otherwise the first bit needs to be set
  852|       |	 * and we continue reading further */
  853|  8.41k|	if ((*p & 0x80) == 0) {
  ------------------
  |  Branch (853:6): [True: 6.77k, False: 1.64k]
  ------------------
  854|  6.77k|		*octet++ = *p - (a * 40);
  855|  6.77k|		inlen--;
  856|  6.77k|	} else {
  857|  1.64k|		large_second_octet = 1;
  858|  1.64k|	}
  859|       |
  860|  39.6k|	while (inlen) {
  ------------------
  |  Branch (860:9): [True: 32.9k, False: 6.69k]
  ------------------
  861|  32.9k|		if (!large_second_octet)
  ------------------
  |  Branch (861:7): [True: 31.2k, False: 1.64k]
  ------------------
  862|  31.2k|			p++;
  863|       |		/* This signalizes empty most significant bits, which means
  864|       |		 * the unsigned integer encoding is not minimal */
  865|  32.9k|		if (*p == 0x80) {
  ------------------
  |  Branch (865:7): [True: 508, False: 32.4k]
  ------------------
  866|    508|			sc_init_oid(id);
  867|    508|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    508|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  868|    508|		}
  869|       |		/* Use unsigned type here so we can process the whole INT range.
  870|       |		 * Values can not be negative */
  871|  32.4k|		a = *p & 0x7F;
  872|  32.4k|		inlen--;
  873|  49.4k|		while (inlen && *p & 0x80) {
  ------------------
  |  Branch (873:10): [True: 42.3k, False: 7.09k]
  |  Branch (873:19): [True: 17.1k, False: 25.2k]
  ------------------
  874|       |			/* Limit the OID values to int size and do not overflow */
  875|  17.1k|			if (a > (UINT_MAX>>7)) {
  ------------------
  |  Branch (875:8): [True: 112, False: 16.9k]
  ------------------
  876|    112|				sc_init_oid(id);
  877|    112|				return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    112|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  878|    112|			}
  879|  16.9k|			p++;
  880|  16.9k|			a <<= 7;
  881|  16.9k|			a |= *p & 0x7F;
  882|  16.9k|			inlen--;
  883|  16.9k|		}
  884|  32.3k|		if (*p & 0x80) {
  ------------------
  |  Branch (884:7): [True: 589, False: 31.7k]
  ------------------
  885|       |			/* We dropped out from previous cycle on the end of
  886|       |			 * data while still expecting continuation of value */
  887|    589|			sc_init_oid(id);
  888|    589|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    589|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  889|    589|		}
  890|  31.7k|		if (large_second_octet) {
  ------------------
  |  Branch (890:7): [True: 594, False: 31.1k]
  ------------------
  891|    594|			a -= (2 * 40);
  892|    594|		}
  893|  31.7k|		if (a > INT_MAX) {
  ------------------
  |  Branch (893:7): [True: 377, False: 31.3k]
  ------------------
  894|    377|			sc_init_oid(id);
  895|    377|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    377|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  896|    377|		}
  897|  31.3k|		*octet++ = a;
  898|  31.3k|		if (octet - id->value >= SC_MAX_OBJECT_ID_OCTETS)   {
  ------------------
  |  |   46|  31.3k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (898:7): [True: 141, False: 31.2k]
  ------------------
  899|    141|			sc_init_oid(id);
  900|    141|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|    141|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  901|    141|		}
  902|  31.2k|		large_second_octet = 0;
  903|  31.2k|	}
  904|       |
  905|  6.69k|	return 0;
  906|  8.41k|}
sc_asn1_encode_object_id:
  910|  3.50k|{
  911|  3.50k|	u8 temp[SC_MAX_OBJECT_ID_OCTETS*5], *p = temp;
  912|  3.50k|	int	i;
  913|       |
  914|  3.50k|	if (!buflen || !id)
  ------------------
  |  Branch (914:6): [True: 0, False: 3.50k]
  |  Branch (914:17): [True: 0, False: 3.50k]
  ------------------
  915|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  916|       |
  917|       |	/* an OID must have at least two components */
  918|  3.50k|	if (id->value[0] == -1 || id->value[1] == -1)
  ------------------
  |  Branch (918:6): [True: 0, False: 3.50k]
  |  Branch (918:28): [True: 0, False: 3.50k]
  ------------------
  919|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  920|       |
  921|  26.0k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++) {
  ------------------
  |  |   46|  26.0k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (921:14): [True: 26.0k, False: 0]
  ------------------
  922|  26.0k|		unsigned int k, shift;
  923|       |
  924|  26.0k|		if (id->value[i] == -1)
  ------------------
  |  Branch (924:7): [True: 3.50k, False: 22.4k]
  ------------------
  925|  3.50k|			break;
  926|       |
  927|  22.4k|		k = id->value[i];
  928|  22.4k|		switch (i) {
  929|  3.50k|		case 0:
  ------------------
  |  Branch (929:3): [True: 3.50k, False: 18.9k]
  ------------------
  930|  3.50k|			if (k > 2)
  ------------------
  |  Branch (930:8): [True: 0, False: 3.50k]
  ------------------
  931|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  932|  3.50k|			*p = k * 40;
  933|  3.50k|			break;
  934|  3.50k|		case 1:
  ------------------
  |  Branch (934:3): [True: 3.50k, False: 18.9k]
  ------------------
  935|  3.50k|			if (k > 39 && id->value[0] < 2) {
  ------------------
  |  Branch (935:8): [True: 0, False: 3.50k]
  |  Branch (935:18): [True: 0, False: 0]
  ------------------
  936|      0|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  937|      0|			}
  938|       |			/* We can encode larger IDs to multiple bytes
  939|       |			 * similarly as the following IDs */
  940|  3.50k|			k += *p;
  941|       |			/* fall through */
  942|  18.9k|		default:
  ------------------
  |  Branch (942:3): [True: 15.4k, False: 7.00k]
  ------------------
  943|  18.9k|			shift = 28;
  944|  88.6k|			while (shift && (k >> shift) == 0)
  ------------------
  |  Branch (944:11): [True: 75.5k, False: 13.1k]
  |  Branch (944:20): [True: 69.7k, False: 5.82k]
  ------------------
  945|  69.7k|				shift -= 7;
  946|  25.2k|			while (shift) {
  ------------------
  |  Branch (946:11): [True: 6.26k, False: 18.9k]
  ------------------
  947|  6.26k|				*p++ = 0x80 | ((k >> shift) & 0x7f);
  948|  6.26k|				shift -= 7;
  949|  6.26k|			}
  950|  18.9k|			*p++ = k & 0x7F;
  951|  18.9k|			break;
  952|  22.4k|		}
  953|  22.4k|	}
  954|       |
  955|  3.50k|	*buflen = p - temp;
  956|       |
  957|  3.50k|	if (buf)   {
  ------------------
  |  Branch (957:6): [True: 3.50k, False: 0]
  ------------------
  958|  3.50k|		*buf = malloc(*buflen);
  959|  3.50k|		if (!*buf)
  ------------------
  |  Branch (959:7): [True: 0, False: 3.50k]
  ------------------
  960|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  961|  3.50k|		memcpy(*buf, temp, *buflen);
  962|  3.50k|	}
  963|  3.50k|	return 0;
  964|  3.50k|}
sc_asn1_put_tag:
  981|  26.2k|{
  982|  26.2k|	size_t c = 0;
  983|  26.2k|	unsigned int tag_len, ii;
  984|  26.2k|	u8 *p = out;
  985|  26.2k|	u8 tag_char[4] = {0, 0, 0, 0};
  986|       |
  987|       |	/* Check tag */
  988|  26.2k|	if (tag == 0 || tag > 0xFFFFFFFF) {
  ------------------
  |  Branch (988:6): [True: 0, False: 26.2k]
  |  Branch (988:18): [True: 0, False: 26.2k]
  ------------------
  989|       |		/* A tag of 0x00 is not valid and at most 4-byte tag names are supported. */
  990|      0|		return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  991|      0|	}
  992|  52.4k|	for (tag_len = 0; tag; tag >>= 8) {
  ------------------
  |  Branch (992:20): [True: 26.2k, False: 26.2k]
  ------------------
  993|       |		/* Note: tag char will be reversed order. */
  994|  26.2k|		tag_char[tag_len++] = tag & 0xFF;
  995|  26.2k|	}
  996|       |
  997|  26.2k|	if (tag_len > 1)   {
  ------------------
  |  Branch (997:6): [True: 0, False: 26.2k]
  ------------------
  998|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  191|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER) {
  ------------------
  |  |  222|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (998:7): [True: 0, False: 0]
  ------------------
  999|       |			/* First byte is not escape marker. */
 1000|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1001|      0|		}
 1002|      0|		for (ii = 1; ii < tag_len - 1; ii++) {
  ------------------
  |  Branch (1002:16): [True: 0, False: 0]
  ------------------
 1003|      0|			if ((tag_char[ii] & 0x80) != 0x80) {
  ------------------
  |  Branch (1003:8): [True: 0, False: 0]
  ------------------
 1004|       |				/* MS bit is not 'one'. */
 1005|      0|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1006|      0|			}
 1007|      0|		}
 1008|      0|		if ((tag_char[0] & 0x80) != 0x00) {
  ------------------
  |  Branch (1008:7): [True: 0, False: 0]
  ------------------
 1009|       |			/* MS bit of the last byte is not 'zero'. */
 1010|      0|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 1011|      0|		}
 1012|      0|	}
 1013|       |
 1014|       |	/* Calculate the number of additional bytes necessary to encode the length. */
 1015|       |	/* c+1 is the size of the length field. */
 1016|  26.2k|	if (datalen > 127) {
  ------------------
  |  Branch (1016:6): [True: 769, False: 25.4k]
  ------------------
 1017|    769|		c = 1;
 1018|  1.16k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1018:10): [True: 399, False: 769]
  ------------------
 1019|    399|			c++;
 1020|    769|	}
 1021|  26.2k|	if (outlen == 0 || out == NULL) {
  ------------------
  |  Branch (1021:6): [True: 5.41k, False: 20.7k]
  |  Branch (1021:21): [True: 0, False: 20.7k]
  ------------------
 1022|       |		/* Caller only asks for the length that would be written. */
 1023|  5.41k|		return (int)(tag_len + (c + 1) + datalen);
 1024|  5.41k|	}
 1025|       |	/* We will write the tag, so check the length. */
 1026|  20.7k|	if (outlen < tag_len + (c+1) + datalen)
  ------------------
  |  Branch (1026:6): [True: 33, False: 20.7k]
  ------------------
 1027|     33|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     33|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
 1028|  41.5k|	for (ii=0;ii<tag_len;ii++)
  ------------------
  |  Branch (1028:12): [True: 20.7k, False: 20.7k]
  ------------------
 1029|  20.7k|		*p++ = tag_char[tag_len - ii - 1];
 1030|       |
 1031|  20.7k|	if (c > 0) {
  ------------------
  |  Branch (1031:6): [True: 470, False: 20.2k]
  ------------------
 1032|    470|		*p++ = 0x80 | c;
 1033|  1.17k|		while (c--)
  ------------------
  |  Branch (1033:10): [True: 703, False: 470]
  ------------------
 1034|    703|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1035|    470|	}
 1036|  20.2k|	else {
 1037|  20.2k|		*p++ = datalen & 0x7F;
 1038|  20.2k|	}
 1039|  20.7k|	if(data && datalen > 0) {
  ------------------
  |  Branch (1039:5): [True: 15.4k, False: 5.35k]
  |  Branch (1039:13): [True: 14.4k, False: 936]
  ------------------
 1040|  14.4k|		memcpy(p, data, datalen);
 1041|  14.4k|		p += datalen;
 1042|  14.4k|	}
 1043|  20.7k|	if (ptr != NULL)
  ------------------
  |  Branch (1043:6): [True: 20.7k, False: 0]
  ------------------
 1044|  20.7k|		*ptr = p;
 1045|  20.7k|	return 0;
 1046|  20.7k|}
sc_asn1_decode:
 1816|  22.0k|{
 1817|  22.0k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 0, 0);
 1818|  22.0k|}
sc_asn1_decode_choice:
 1822|  6.21k|{
 1823|  6.21k|	return asn1_decode(ctx, asn1, in, len, newp, len_left, 1, 0);
 1824|  6.21k|}
sc_asn1_encode:
 2088|  19.3k|{
 2089|  19.3k|	return asn1_encode(ctx, asn1, ptr, size, 0);
 2090|  19.3k|}
_sc_asn1_encode:
 2094|  3.50k|{
 2095|  3.50k|	return asn1_encode(ctx, asn1, ptr, size, depth);
 2096|  3.50k|}
_sc_asn1_decode:
 2102|  3.77k|{
 2103|  3.77k|	return asn1_decode(ctx, asn1, in, len, newp, left, choice, depth);
 2104|  3.77k|}
sc_der_copy:
 2108|  2.49k|{
 2109|  2.49k|	if (!dst || !src)
  ------------------
  |  Branch (2109:6): [True: 0, False: 2.49k]
  |  Branch (2109:14): [True: 0, False: 2.49k]
  ------------------
 2110|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2111|  2.49k|	memset(dst, 0, sizeof(*dst));
 2112|  2.49k|	if (src->len) {
  ------------------
  |  Branch (2112:6): [True: 2.48k, False: 2]
  ------------------
 2113|  2.48k|		if (!src->value)
  ------------------
  |  Branch (2113:7): [True: 0, False: 2.48k]
  ------------------
 2114|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2115|  2.48k|		dst->value = malloc(src->len);
 2116|  2.48k|		if (!dst->value)
  ------------------
  |  Branch (2116:7): [True: 0, False: 2.48k]
  ------------------
 2117|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2118|  2.48k|		dst->len = src->len;
 2119|  2.48k|		memcpy(dst->value, src->value, src->len);
 2120|  2.48k|	}
 2121|  2.49k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.49k|#define SC_SUCCESS				0
  ------------------
 2122|  2.49k|}
sc_encode_oid:
 2127|  2.20k|{
 2128|  2.20k|	static const struct sc_asn1_entry c_asn1_object_id[2] = {
 2129|  2.20k|		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  159|  2.20k|#define SC_ASN1_OBJECT                  6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  200|  2.20k|#define SC_ASN1_TAG_OBJECT		6
  ------------------
              		{ "oid", SC_ASN1_OBJECT, SC_ASN1_TAG_OBJECT, SC_ASN1_ALLOC, NULL, NULL },
  ------------------
  |  |  149|  2.20k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
 2130|  2.20k|		{ NULL, 0, 0, 0, NULL, NULL }
 2131|  2.20k|	};
 2132|  2.20k|	struct sc_asn1_entry asn1_object_id[2];
 2133|  2.20k|	int rv;
 2134|       |
 2135|  2.20k|	sc_copy_asn1_entry(c_asn1_object_id, asn1_object_id);
 2136|  2.20k|	sc_format_asn1_entry(asn1_object_id + 0, id, NULL, 1);
 2137|       |
 2138|  2.20k|	rv = _sc_asn1_encode(ctx, asn1_object_id, out, size, 1);
 2139|  2.20k|	LOG_TEST_RET(ctx, rv, "Cannot encode object ID");
  ------------------
  |  |  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: 0, False: 2.20k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2140|       |
 2141|  2.20k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.20k|#define SC_SUCCESS				0
  ------------------
 2142|  2.20k|}
sc_asn1_decode_ecdsa_signature:
 2243|    224|int sc_asn1_decode_ecdsa_signature(sc_context_t *ctx, const u8 *data, size_t datalen, size_t fieldsize, u8 **out, size_t outlen) {
 2244|    224|	int i, r;
 2245|    224|	const unsigned char *pseq, *pint, *pend;
 2246|    224|	unsigned int cla, tag;
 2247|    224|	size_t seqlen, intlen;
 2248|       |
 2249|    224|	if (!ctx || !data || !out || !(*out)) {
  ------------------
  |  Branch (2249:6): [True: 0, False: 224]
  |  Branch (2249:14): [True: 0, False: 224]
  |  Branch (2249:23): [True: 0, False: 224]
  |  Branch (2249:31): [True: 0, False: 224]
  ------------------
 2250|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2251|      0|	}
 2252|    224|	if (outlen < 2 * fieldsize) {
  ------------------
  |  Branch (2252:6): [True: 0, False: 224]
  ------------------
 2253|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Output too small for EC signature");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2254|      0|	}
 2255|       |
 2256|    224|	memset(*out, 0, outlen);
 2257|       |
 2258|    224|	pseq = data;
 2259|    224|	r = sc_asn1_read_tag(&pseq, datalen, &cla, &tag, &seqlen);
 2260|    224|	if (pseq == NULL || r < 0 || seqlen == 0 || (cla | tag) != 0x30)
  ------------------
  |  Branch (2260:6): [True: 216, False: 8]
  |  Branch (2260:22): [True: 1, False: 7]
  |  Branch (2260:31): [True: 1, False: 6]
  |  Branch (2260:46): [True: 1, False: 5]
  ------------------
 2261|    224|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x30 tag");
  ------------------
  |  |  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: 219, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|    219|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2262|       |
 2263|      5|	pint = pseq;
 2264|      5|	pend = pseq + seqlen;
 2265|      6|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (2265:14): [True: 6, False: 0]
  ------------------
 2266|      6|		r = sc_asn1_read_tag(&pint, (pend - pint), &cla, &tag, &intlen);
 2267|      6|		if (pint == NULL || r < 0 || intlen == 0 || (cla | tag) != 0x02) {
  ------------------
  |  Branch (2267:7): [True: 2, False: 4]
  |  Branch (2267:23): [True: 1, False: 3]
  |  Branch (2267:32): [True: 1, False: 2]
  |  Branch (2267:47): [True: 1, False: 1]
  ------------------
 2268|      5|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      5|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2269|      5|			LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Can not find 0x02");
  ------------------
  |  |  184|      5|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      5|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      5|	int _ret = (r); \
  |  |  |  |  178|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      5|		goto err; \
  |  |  |  |  182|      5|	} \
  |  |  |  |  183|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2270|      5|		}
 2271|       |
 2272|      1|		if (intlen == fieldsize + 1) { /* drop leading 00 if present */
  ------------------
  |  Branch (2272:7): [True: 0, False: 1]
  ------------------
 2273|      0|			if (*pint != 0x00) {
  ------------------
  |  Branch (2273:8): [True: 0, False: 0]
  ------------------
 2274|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2275|      0|				LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Signature too long");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2276|      0|			}
 2277|      0|			pint++;
 2278|      0|			intlen--;
 2279|      0|		}
 2280|      1|		if (intlen > fieldsize) {
  ------------------
  |  Branch (2280:7): [True: 0, False: 1]
  ------------------
 2281|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2282|      0|			LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_DATA, "Signature too long");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2283|      0|		}
 2284|      1|		memcpy(*out + fieldsize * i + fieldsize - intlen , pint, intlen);
 2285|      1|		pint += intlen; /* next integer */
 2286|      1|	}
 2287|      0|	r = (int)(2 * fieldsize);
 2288|      5|err:
 2289|      5|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2290|      5|}
asn1.c:decode_bit_string:
  579|  2.48k|{
  580|  2.48k|	const u8 *in = inbuf;
  581|  2.48k|	u8 *out = (u8 *) outbuf;
  582|  2.48k|	int i, count = 0;
  583|  2.48k|	int zero_bits;
  584|  2.48k|	size_t octets_left;
  585|       |
  586|  2.48k|	if (inlen < 1)
  ------------------
  |  Branch (586:6): [True: 3, False: 2.47k]
  ------------------
  587|      3|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  588|       |
  589|       |	/* The formatting is only enforced by SHALL keyword so we should accept
  590|       |	 * by default also non-strict values. */
  591|  2.47k|	if (strict) {
  ------------------
  |  Branch (591:6): [True: 0, False: 2.47k]
  ------------------
  592|       |		/* 8.6.2.3 If the bitstring is empty, there shall be no
  593|       |		 * subsequent octets,and the initial octet shall be zero. */
  594|      0|		if (inlen == 1 && *in != 0)
  ------------------
  |  Branch (594:7): [True: 0, False: 0]
  |  Branch (594:21): [True: 0, False: 0]
  ------------------
  595|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  596|       |		/* ITU-T Rec. X.690 8.6.2.2: The number shall be in the range zero to seven. */
  597|      0|		if ((*in & ~0x07) != 0)
  ------------------
  |  Branch (597:7): [True: 0, False: 0]
  ------------------
  598|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  599|      0|	}
  600|       |
  601|  2.47k|	memset(outbuf, 0, outlen);
  602|  2.47k|	zero_bits = *in & 0x07;
  603|  2.47k|	in++;
  604|  2.47k|	octets_left = inlen - 1;
  605|  2.47k|	if (outlen < octets_left)
  ------------------
  |  Branch (605:6): [True: 5, False: 2.47k]
  ------------------
  606|      5|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      5|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  607|       |
  608|   136k|	while (octets_left) {
  ------------------
  |  Branch (608:9): [True: 133k, False: 2.46k]
  ------------------
  609|       |		/* 1st octet of input:  ABCDEFGH, where A is the MSB */
  610|       |		/* 1st octet of output: HGFEDCBA, where A is the LSB */
  611|       |		/* first bit in bit string is the LSB in first resulting octet */
  612|   133k|		int bits_to_go;
  613|       |
  614|   133k|		*out = 0;
  615|   133k|		if (octets_left == 1 && zero_bits > 0) {
  ------------------
  |  Branch (615:7): [True: 2.41k, False: 131k]
  |  Branch (615:27): [True: 421, False: 1.99k]
  ------------------
  616|    421|			bits_to_go = 8 - zero_bits;
  617|       |			/* Verify the padding is zero bits */
  618|    421|			if (*in & (1 << (zero_bits-1))) {
  ------------------
  |  Branch (618:8): [True: 13, False: 408]
  ------------------
  619|     13|				return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     13|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  620|     13|			}
  621|    421|		} else
  622|   133k|			bits_to_go = 8;
  623|   133k|		if (invert)
  ------------------
  |  Branch (623:7): [True: 783, False: 132k]
  ------------------
  624|  6.02k|			for (i = 0; i < bits_to_go; i++) {
  ------------------
  |  Branch (624:16): [True: 5.24k, False: 783]
  ------------------
  625|  5.24k|				*out |= ((*in >> (7 - i)) & 1) << i;
  626|  5.24k|			}
  627|   132k|		else {
  628|   132k|			*out = *in;
  629|   132k|		}
  630|   133k|		out++;
  631|   133k|		in++;
  632|   133k|		octets_left--;
  633|   133k|		count++;
  634|   133k|	}
  635|  2.46k|	return (count * 8) - zero_bits;
  636|  2.47k|}
asn1.c:asn1_write_element:
 1056|  26.8k|{
 1057|  26.8k|	unsigned char t;
 1058|  26.8k|	unsigned char *buf, *p;
 1059|  26.8k|	int c = 0;
 1060|  26.8k|	unsigned short_tag;
 1061|  26.8k|	unsigned char tag_char[3] = {0, 0, 0};
 1062|  26.8k|	size_t tag_len, ii;
 1063|       |
 1064|  26.8k|	short_tag = tag & SC_ASN1_TAG_MASK;
  ------------------
  |  |  144|  26.8k|#define SC_ASN1_TAG_MASK		0x00FFFFFF
  ------------------
 1065|  53.7k|	for (tag_len = 0; short_tag >> (8 * tag_len); tag_len++)
  ------------------
  |  Branch (1065:20): [True: 26.8k, False: 26.8k]
  ------------------
 1066|  26.8k|		tag_char[tag_len] = (short_tag >> (8 * tag_len)) & 0xFF;
 1067|  26.8k|	if (!tag_len)
  ------------------
  |  Branch (1067:6): [True: 0, False: 26.8k]
  ------------------
 1068|      0|		tag_len = 1;
 1069|       |
 1070|  26.8k|	if (tag_len > 1)   {
  ------------------
  |  Branch (1070:6): [True: 0, False: 26.8k]
  ------------------
 1071|      0|		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  191|      0|#define SC_ASN1_TAG_PRIMITIVE		0x1F
  ------------------
              		if ((tag_char[tag_len - 1] & SC_ASN1_TAG_PRIMITIVE) != SC_ASN1_TAG_ESCAPE_MARKER)
  ------------------
  |  |  222|      0|#define SC_ASN1_TAG_ESCAPE_MARKER	31
  ------------------
  |  Branch (1071:7): [True: 0, False: 0]
  ------------------
 1072|      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]
  |  |  ------------------
  ------------------
 1073|       |
 1074|      0|		for (ii = 1; ii < tag_len - 1; ii++)
  ------------------
  |  Branch (1074:16): [True: 0, False: 0]
  ------------------
 1075|      0|			if (!(tag_char[ii] & 0x80))
  ------------------
  |  Branch (1075:8): [True: 0, False: 0]
  ------------------
 1076|      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]
  |  |  ------------------
  ------------------
 1077|       |
 1078|      0|		if (tag_char[0] & 0x80)
  ------------------
  |  Branch (1078:7): [True: 0, False: 0]
  ------------------
 1079|      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]
  |  |  ------------------
  ------------------
 1080|      0|	}
 1081|       |
 1082|  26.8k|	t = tag_char[tag_len - 1] & 0x1F;
 1083|       |
 1084|  26.8k|	switch (tag & SC_ASN1_CLASS_MASK) {
  ------------------
  |  |  136|  26.8k|#define SC_ASN1_CLASS_MASK		0xC0000000
  ------------------
  |  Branch (1084:10): [True: 26.8k, False: 0]
  ------------------
 1085|  13.2k|	case SC_ASN1_UNI:
  ------------------
  |  |  137|  13.2k|#define SC_ASN1_UNI			0x00000000 /* Universal */
  ------------------
  |  Branch (1085:2): [True: 13.2k, False: 13.6k]
  ------------------
 1086|  13.2k|		break;
 1087|  13.6k|	case SC_ASN1_APP:
  ------------------
  |  |  138|  13.6k|#define SC_ASN1_APP			0x40000000 /* Application */
  ------------------
  |  Branch (1087:2): [True: 13.6k, False: 13.2k]
  ------------------
 1088|  13.6k|		t |= SC_ASN1_TAG_APPLICATION;
  ------------------
  |  |  186|  13.6k|#define SC_ASN1_TAG_APPLICATION		0x40
  ------------------
 1089|  13.6k|		break;
 1090|      0|	case SC_ASN1_CTX:
  ------------------
  |  |  139|      0|#define SC_ASN1_CTX			0x80000000 /* Context */
  ------------------
  |  Branch (1090:2): [True: 0, False: 26.8k]
  ------------------
 1091|      0|		t |= SC_ASN1_TAG_CONTEXT;
  ------------------
  |  |  187|      0|#define SC_ASN1_TAG_CONTEXT		0x80
  ------------------
 1092|      0|		break;
 1093|      0|	case SC_ASN1_PRV:
  ------------------
  |  |  140|      0|#define SC_ASN1_PRV			0xC0000000 /* Private */
  ------------------
  |  Branch (1093:2): [True: 0, False: 26.8k]
  ------------------
 1094|      0|		t |= SC_ASN1_TAG_PRIVATE;
  ------------------
  |  |  188|      0|#define SC_ASN1_TAG_PRIVATE		0xC0
  ------------------
 1095|      0|		break;
 1096|  26.8k|	}
 1097|  26.8k|	if (tag & SC_ASN1_CONS)
  ------------------
  |  |  141|  26.8k|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (1097:6): [True: 5.41k, False: 21.4k]
  ------------------
 1098|  5.41k|		t |= SC_ASN1_TAG_CONSTRUCTED;
  ------------------
  |  |  190|  5.41k|#define SC_ASN1_TAG_CONSTRUCTED		0x20
  ------------------
 1099|  26.8k|	if (datalen > 127) {
  ------------------
  |  Branch (1099:6): [True: 1.84k, False: 25.0k]
  ------------------
 1100|  1.84k|		c = 1;
 1101|  1.87k|		while (datalen >> (c << 3))
  ------------------
  |  Branch (1101:10): [True: 31, False: 1.84k]
  ------------------
 1102|     31|			c++;
 1103|  1.84k|	}
 1104|       |
 1105|  26.8k|	*outlen = tag_len + 1 + c + datalen;
 1106|  26.8k|	buf = malloc(*outlen);
 1107|  26.8k|	if (buf == NULL)
  ------------------
  |  Branch (1107:6): [True: 0, False: 26.8k]
  ------------------
 1108|      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]
  |  |  ------------------
  ------------------
 1109|       |
 1110|  26.8k|	*out = p = buf;
 1111|  26.8k|	*p++ = t;
 1112|  26.8k|	for (ii=1;ii<tag_len;ii++)
  ------------------
  |  Branch (1112:12): [True: 0, False: 26.8k]
  ------------------
 1113|      0|		*p++ = tag_char[tag_len - ii - 1];
 1114|       |
 1115|  26.8k|	if (c) {
  ------------------
  |  Branch (1115:6): [True: 1.84k, False: 25.0k]
  ------------------
 1116|  1.84k|		*p++ = 0x80 | c;
 1117|  3.71k|		while (c--)
  ------------------
  |  Branch (1117:10): [True: 1.87k, False: 1.84k]
  ------------------
 1118|  1.87k|			*p++ = (datalen >> (c << 3)) & 0xFF;
 1119|  1.84k|	}
 1120|  25.0k|	else   {
 1121|  25.0k|		*p++ = datalen & 0x7F;
 1122|  25.0k|	}
 1123|  26.8k|	if (datalen && data) {
  ------------------
  |  Branch (1123:6): [True: 26.4k, False: 461]
  |  Branch (1123:17): [True: 26.4k, False: 0]
  ------------------
 1124|  26.4k|		memcpy(p, data, datalen);
 1125|  26.4k|	}
 1126|       |
 1127|  26.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  26.8k|#define SC_SUCCESS				0
  ------------------
 1128|  26.8k|}
asn1.c:asn1_decode:
 1724|  47.9k|{
 1725|  47.9k|	int r, idx = 0;
 1726|  47.9k|	const u8 *p = in, *obj;
 1727|  47.9k|	struct sc_asn1_entry *entry = asn1;
 1728|  47.9k|	size_t left = len, objlen;
 1729|       |
 1730|  47.9k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|  95.9k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 6.36k, False: 41.5k]
  |  |  ------------------
  ------------------
 1731|  47.9k|		 "%*.*s""called, left=%"SC_FORMAT_LEN_SIZE_T"u, depth %d%s\n",
 1732|  47.9k|		 depth, depth, "", left, depth, choice ? ", choice" : "");
 1733|       |
 1734|  47.9k|	if (!p)
  ------------------
  |  Branch (1734:6): [True: 1, False: 47.9k]
  ------------------
 1735|      1|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|      1|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1736|  47.9k|	if (left < 2) {
  ------------------
  |  Branch (1736:6): [True: 1.73k, False: 46.2k]
  ------------------
 1737|  4.22k|		while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|  3.06k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1737:10): [True: 3.06k, False: 1.15k]
  |  Branch (1737:24): [True: 2.49k, False: 578]
  ------------------
 1738|  2.49k|			asn1++;
 1739|       |		/* If all elements were optional, there's nothing
 1740|       |		 * to complain about */
 1741|  1.73k|		if (asn1->name == NULL)
  ------------------
  |  Branch (1741:7): [True: 1.15k, False: 578]
  ------------------
 1742|  1.15k|			return 0;
 1743|    578|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "End of ASN.1 stream, "
  ------------------
  |  |   70|    578|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1744|    578|			      "non-optional field \"%s\" not found\n",
 1745|    578|			      asn1->name);
 1746|    578|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    578|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1747|  1.73k|	}
 1748|  46.2k|	if (p[0] == 0 || p[0] == 0xFF || len == 0)
  ------------------
  |  Branch (1748:6): [True: 1.36k, False: 44.8k]
  |  Branch (1748:19): [True: 599, False: 44.2k]
  |  Branch (1748:35): [True: 0, False: 44.2k]
  ------------------
 1749|  1.96k|		return SC_ERROR_ASN1_END_OF_CONTENTS;
  ------------------
  |  |   84|  1.96k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
 1750|       |
 1751|   157k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1751:16): [True: 125k, False: 32.5k]
  ------------------
 1752|   125k|		entry = &asn1[idx];
 1753|       |
 1754|   125k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "Looking for '%s', tag 0x%x%s%s\n",
  ------------------
  |  |   70|   125k|#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)
  |  |  ------------------
  |  |  |  | 1755|   125k|			entry->name, entry->tag, choice? ", CHOICE" : "",
  |  |  |  | 1756|   125k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
  |  |  |  |  ------------------
  |  |  |  |  |  |  148|   125k|#define SC_ASN1_OPTIONAL		0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1755|   125k|			entry->name, entry->tag, choice? ", CHOICE" : "",
 1756|   125k|			(entry->flags & SC_ASN1_OPTIONAL)? ", OPTIONAL": "");
 1757|       |
 1758|       |		/* Special case CHOICE has no tag */
 1759|   125k|		if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|   125k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1759:7): [True: 150, False: 125k]
  ------------------
 1760|    150|			r = asn1_decode(ctx,
 1761|    150|				(struct sc_asn1_entry *) entry->parm,
 1762|    150|				p, left, &p, &left, 1, depth + 1);
 1763|       |			/* When the inner call fails it returns before writing
 1764|       |			 * back to *newp and *len_left, so the caller's p/left are
 1765|       |			 * unchanged.  Swallowing the error for an optional
 1766|       |			 * CHOICE is therefore safe: the next field will be
 1767|       |			 * attempted at the same position. */
 1768|    150|			if (r >= 0 || (entry->flags & SC_ASN1_OPTIONAL))
  ------------------
  |  |  148|    149|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1768:8): [True: 1, False: 149]
  |  Branch (1768:18): [True: 1, False: 148]
  ------------------
 1769|      2|				r = 0;
 1770|    150|			goto decode_ok;
 1771|    150|		}
 1772|       |
 1773|   125k|		obj = sc_asn1_skip_tag(ctx, &p, &left, entry->tag, &objlen);
 1774|   125k|		if (obj == NULL) {
  ------------------
  |  Branch (1774:7): [True: 68.5k, False: 56.7k]
  ------------------
 1775|  68.5k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "'%s' not present\n", entry->name);
  ------------------
  |  |   70|  68.5k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1776|  68.5k|			if (choice)
  ------------------
  |  Branch (1776:8): [True: 22.1k, False: 46.3k]
  ------------------
 1777|  22.1k|				continue;
 1778|  46.3k|			if (entry->flags & SC_ASN1_OPTIONAL)
  ------------------
  |  |  148|  46.3k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
  |  Branch (1778:8): [True: 42.0k, False: 4.36k]
  ------------------
 1779|  42.0k|				continue;
 1780|  4.36k|			sc_debug(ctx, SC_LOG_DEBUG_ASN1, "mandatory ASN.1 object '%s' not found\n", entry->name);
  ------------------
  |  |   70|  4.36k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1781|  4.36k|			if (left) {
  ------------------
  |  Branch (1781:8): [True: 4.28k, False: 74]
  ------------------
 1782|  4.28k|				u8 line[128], *linep = line;
 1783|  4.28k|				size_t i;
 1784|       |
 1785|  4.28k|				line[0] = 0;
 1786|  41.8k|				for (i = 0; i < 10 && i < left; i++) {
  ------------------
  |  Branch (1786:17): [True: 38.3k, False: 3.48k]
  |  Branch (1786:27): [True: 37.5k, False: 801]
  ------------------
 1787|  37.5k|					sprintf((char *) linep, "%02X ", p[i]);
 1788|  37.5k|					linep += 3;
 1789|  37.5k|				}
 1790|  4.28k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "next tag: %s\n", line);
  ------------------
  |  |   70|  4.28k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1791|  4.28k|			}
 1792|  4.36k|			sc_free_entry(asn1);
 1793|  4.36k|			SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  153|  4.36k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  4.36k|	int _ret = r; \
  |  |  155|  4.36k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 4.36k, False: 0]
  |  |  ------------------
  |  |  156|  4.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|  4.36k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.36k, False: 0]
  |  |  ------------------
  |  |  157|  4.36k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  4.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|  4.36k|	return _ret; \
  |  |  163|  4.36k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1794|  4.36k|		}
 1795|  56.7k|		r = asn1_decode_entry(ctx, entry, obj, objlen, depth);
 1796|       |
 1797|  56.8k|decode_ok:
 1798|  56.8k|		if (r)
  ------------------
  |  Branch (1798:7): [True: 1.56k, False: 55.2k]
  ------------------
 1799|  1.56k|			return r;
 1800|  55.2k|		if (choice)
  ------------------
  |  Branch (1800:7): [True: 5.75k, False: 49.5k]
  ------------------
 1801|  5.75k|			break;
 1802|  55.2k| 	}
 1803|  38.3k| 	if (choice && asn1[idx].name == NULL) /* No match */
  ------------------
  |  Branch (1803:7): [True: 5.99k, False: 32.3k]
  |  Branch (1803:17): [True: 243, False: 5.75k]
  ------------------
 1804|    243|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
  ------------------
  |  |  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|    243|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 243, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1805|  38.0k| 	if (newp != NULL)
  ------------------
  |  Branch (1805:7): [True: 9.04k, False: 29.0k]
  ------------------
 1806|  9.04k|		*newp = p;
 1807|  38.0k| 	if (len_left != NULL)
  ------------------
  |  Branch (1807:7): [True: 9.04k, False: 29.0k]
  ------------------
 1808|  9.04k|		*len_left = left;
 1809|  38.0k|	if (choice)
  ------------------
  |  Branch (1809:6): [True: 5.75k, False: 32.3k]
  ------------------
 1810|  5.75k|		SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, idx);
  ------------------
  |  |  153|  5.75k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  5.75k|	int _ret = r; \
  |  |  155|  5.75k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.17k, False: 4.57k]
  |  |  ------------------
  |  |  156|  1.17k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 1.17k]
  |  |  ------------------
  |  |  157|  1.17k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  4.57k|	} else { \
  |  |  159|  4.57k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|  4.57k|			"returning with: %d\n", _ret); \
  |  |  161|  4.57k|	} \
  |  |  162|  5.75k|	return _ret; \
  |  |  163|  5.75k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1811|  32.3k|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, 0);
  ------------------
  |  |  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: 32.3k, False: 0]
  |  |  ------------------
  |  |  156|  32.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 32.3k]
  |  |  ------------------
  |  |  157|  32.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  32.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|  32.3k|	return _ret; \
  |  |  163|  32.3k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1812|  32.3k|}
asn1.c:sc_free_entry:
 1689|  12.5k|static void sc_free_entry(struct sc_asn1_entry *asn1) {
 1690|  12.5k|	int idx = 0;
 1691|  12.5k|	struct sc_asn1_entry *entry = asn1;
 1692|       |
 1693|  12.5k|	if (!asn1)
  ------------------
  |  Branch (1693:6): [True: 433, False: 12.0k]
  ------------------
 1694|    433|		return;
 1695|       |
 1696|  55.4k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (1696:16): [True: 43.4k, False: 12.0k]
  ------------------
 1697|  43.4k|		entry = &asn1[idx];
 1698|  43.4k|		switch (entry->type) {
 1699|  2.52k|		case SC_ASN1_CHOICE:
  ------------------
  |  |  170|  2.52k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1699:3): [True: 2.52k, False: 40.8k]
  ------------------
 1700|  8.16k|		case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  8.16k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1700:3): [True: 5.63k, False: 37.7k]
  ------------------
 1701|  8.16k|			sc_free_entry((struct sc_asn1_entry *) entry->parm);
 1702|  8.16k|			break;
 1703|  12.4k|		case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  12.4k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1703:3): [True: 12.4k, False: 30.9k]
  ------------------
 1704|  12.4k|		case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  12.4k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1704:3): [True: 35, False: 43.3k]
  ------------------
 1705|  12.5k|		case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  12.5k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1705:3): [True: 61, False: 43.3k]
  ------------------
 1706|  12.6k|		case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|  12.6k|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1706:3): [True: 155, False: 43.2k]
  ------------------
 1707|  12.9k|		case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|  12.9k|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1707:3): [True: 208, False: 43.1k]
  ------------------
 1708|  14.2k|		case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  14.2k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1708:3): [True: 1.31k, False: 42.0k]
  ------------------
 1709|  14.2k|			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  149|  14.2k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
              			if ((entry->flags & SC_ASN1_ALLOC) && (entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  1.10k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1709:8): [True: 1.10k, False: 13.1k]
  |  Branch (1709:42): [True: 336, False: 771]
  ------------------
 1710|    336|				u8 **buf = (u8 **)entry->parm;
 1711|    336|				free(*buf);
 1712|    336|				*buf = NULL;
 1713|    336|			}
 1714|  14.2k|			break;
 1715|  21.0k|		default:
  ------------------
  |  Branch (1715:3): [True: 21.0k, False: 22.3k]
  ------------------
 1716|  21.0k|			break;
 1717|  43.4k|		}
 1718|  43.4k|	}
 1719|  12.0k|}
asn1.c:asn1_decode_entry:
 1491|  56.7k|{
 1492|  56.7k|	void *parm = entry->parm;
 1493|  56.7k|	int (*callback_func)(sc_context_t *nctx, void *arg, const u8 *nobj,
 1494|  56.7k|			     size_t nobjlen, int ndepth);
 1495|  56.7k|	size_t *len = (size_t *) entry->arg;
 1496|  56.7k|	int r = 0;
 1497|       |
 1498|  56.7k|	callback_func = parm;
 1499|       |
 1500|  56.7k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s', raw data:%s%s\n",
  ------------------
  |  |   70|   226k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 16.0k, False: 40.6k]
  |  |  |  Branch (70:115): [True: 16.0k, False: 40.6k]
  |  |  ------------------
  ------------------
 1501|  56.7k|		depth, depth, "", entry->name,
 1502|  56.7k|		sc_dump_hex(obj, objlen > 16  ? 16 : objlen),
 1503|  56.7k|		objlen > 16 ? "..." : "");
 1504|       |
 1505|  56.7k|	switch (entry->type) {
 1506|  15.0k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  15.0k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1506:2): [True: 15.0k, False: 41.6k]
  ------------------
 1507|  15.0k|		if (parm != NULL)
  ------------------
  |  Branch (1507:7): [True: 10.7k, False: 4.28k]
  ------------------
 1508|  10.7k|			r = asn1_decode(ctx, (struct sc_asn1_entry *) parm, obj,
 1509|  10.7k|				       objlen, NULL, NULL, 0, depth + 1);
 1510|  15.0k|		break;
 1511|  1.55k|	case SC_ASN1_NULL:
  ------------------
  |  |  158|  1.55k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1511:2): [True: 1.55k, False: 55.1k]
  ------------------
 1512|  1.55k|		break;
 1513|     55|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|     55|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1513:2): [True: 55, False: 56.6k]
  ------------------
 1514|     55|		if (parm != NULL) {
  ------------------
  |  Branch (1514:7): [True: 55, False: 0]
  ------------------
 1515|     55|			if (objlen != 1) {
  ------------------
  |  Branch (1515:8): [True: 9, False: 46]
  ------------------
 1516|      9|				sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|      9|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1517|      9|					 "invalid ASN.1 object length: %"SC_FORMAT_LEN_SIZE_T"u\n",
 1518|      9|					 objlen);
 1519|      9|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      9|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1520|      9|			} else
 1521|     46|				*((int *) parm) = obj[0] ? 1 : 0;
  ------------------
  |  Branch (1521:23): [True: 45, False: 1]
  ------------------
 1522|     55|		}
 1523|     55|		break;
 1524|  3.07k|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|  3.07k|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1524:2): [True: 3.07k, False: 53.6k]
  ------------------
 1525|  3.07k|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|  3.07k|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1525:2): [True: 0, False: 56.7k]
  ------------------
 1526|  3.07k|		if (parm != NULL) {
  ------------------
  |  Branch (1526:7): [True: 3.07k, False: 0]
  ------------------
 1527|  3.07k|			r = sc_asn1_decode_integer(obj, objlen, (int *) entry->parm, 0);
 1528|  3.07k|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  3.07k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1528:8): [True: 3.06k, False: 14]
  ------------------
 1529|  3.06k|				sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sdecoding '%s' returned %d\n",
  ------------------
  |  |   70|  3.06k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1530|  3.06k|						depth, depth, "", entry->name, *((int *)entry->parm));
 1531|  3.06k|			}
 1532|  3.07k|		}
 1533|  3.07k|		break;
 1534|  1.99k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  1.99k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1534:2): [True: 1.99k, False: 54.7k]
  ------------------
 1535|  3.65k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  3.65k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1535:2): [True: 1.65k, False: 55.0k]
  ------------------
 1536|  3.65k|		if (parm != NULL) {
  ------------------
  |  Branch (1536:7): [True: 1.99k, False: 1.65k]
  ------------------
 1537|  1.99k|			int invert = entry->type == SC_ASN1_BIT_STRING ? 1 : 0;
  ------------------
  |  |  155|  1.99k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1537:17): [True: 0, False: 1.99k]
  ------------------
 1538|  1.99k|			if (len == NULL)
  ------------------
  |  Branch (1538:8): [True: 0, False: 1.99k]
  ------------------
 1539|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1540|  1.99k|			if (objlen < 1) {
  ------------------
  |  Branch (1540:8): [True: 6, False: 1.99k]
  ------------------
 1541|      6|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1542|      6|				break;
 1543|      6|			}
 1544|  1.99k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  1.99k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1544:8): [True: 1.99k, False: 0]
  ------------------
 1545|  1.99k|				u8 **buf = (u8 **) parm;
 1546|  1.99k|				if (objlen > 1) {
  ------------------
  |  Branch (1546:9): [True: 1.96k, False: 30]
  ------------------
 1547|  1.96k|					*buf = malloc(objlen-1);
 1548|  1.96k|					if (*buf == NULL) {
  ------------------
  |  Branch (1548:10): [True: 0, False: 1.96k]
  ------------------
 1549|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1550|      0|						break;
 1551|      0|					}
 1552|  1.96k|				}
 1553|  1.99k|				*len = objlen-1;
 1554|  1.99k|				parm = *buf;
 1555|  1.99k|			}
 1556|  1.99k|			r = decode_bit_string(obj, objlen, (u8 *) parm, *len, invert, 0);
 1557|  1.99k|			if (r >= 0) {
  ------------------
  |  Branch (1557:8): [True: 1.96k, False: 24]
  ------------------
 1558|  1.96k|				*len = r;
 1559|  1.96k|				r = 0;
 1560|  1.96k|			}
 1561|  1.99k|		}
 1562|  3.64k|		break;
 1563|  3.64k|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|    491|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1563:2): [True: 491, False: 56.2k]
  ------------------
 1564|    491|		if (parm != NULL)
  ------------------
  |  Branch (1564:7): [True: 491, False: 0]
  ------------------
 1565|    491|			r = decode_bit_field(obj, objlen, (u8 *) parm, *len, 0);
 1566|    491|		break;
 1567|  16.8k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  16.8k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1567:2): [True: 16.8k, False: 39.8k]
  ------------------
 1568|  16.8k|		if (parm != NULL) {
  ------------------
  |  Branch (1568:7): [True: 16.7k, False: 70]
  ------------------
 1569|  16.7k|			size_t c;
 1570|  16.7k|			if (len == NULL)
  ------------------
  |  Branch (1570:8): [True: 0, False: 16.7k]
  ------------------
 1571|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1572|       |
 1573|       |			/* Strip off padding zero */
 1574|  16.7k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  16.7k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1574:8): [True: 3.12k, False: 13.6k]
  ------------------
 1575|  3.12k|					&& objlen > 1 && obj[0] == 0x00) {
  ------------------
  |  Branch (1575:9): [True: 3.00k, False: 127]
  |  Branch (1575:23): [True: 1.83k, False: 1.16k]
  ------------------
 1576|  1.83k|				objlen--;
 1577|  1.83k|				obj++;
 1578|  1.83k|			}
 1579|       |
 1580|       |			/* Allocate buffer if needed */
 1581|  16.7k|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|  16.7k|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1581:8): [True: 10.2k, False: 6.56k]
  ------------------
 1582|  10.2k|				u8 **buf = (u8 **) parm;
 1583|  10.2k|				if (objlen > 0) {
  ------------------
  |  Branch (1583:9): [True: 8.32k, False: 1.90k]
  ------------------
 1584|  8.32k|					*buf = malloc(objlen);
 1585|  8.32k|					if (*buf == NULL) {
  ------------------
  |  Branch (1585:10): [True: 0, False: 8.32k]
  ------------------
 1586|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1587|      0|						break;
 1588|      0|					}
 1589|  8.32k|				}
 1590|  10.2k|				c = *len = objlen;
 1591|  10.2k|				parm = *buf;
 1592|  10.2k|			} else
 1593|  6.56k|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1593:9): [True: 178, False: 6.38k]
  ------------------
 1594|       |
 1595|  16.7k|			memcpy(parm, obj, c);
 1596|  16.7k|			*len = c;
 1597|  16.7k|		}
 1598|  16.8k|		break;
 1599|  16.8k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|     13|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1599:2): [True: 13, False: 56.6k]
  ------------------
 1600|     13|		if (parm != NULL) {
  ------------------
  |  Branch (1600:7): [True: 13, False: 0]
  ------------------
 1601|     13|			size_t c;
 1602|     13|			if (len == NULL)
  ------------------
  |  Branch (1602:8): [True: 0, False: 13]
  ------------------
 1603|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1604|     13|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|     13|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1604:8): [True: 0, False: 13]
  ------------------
 1605|      0|				u8 **buf = (u8 **) parm;
 1606|      0|				if (objlen > 0) {
  ------------------
  |  Branch (1606:9): [True: 0, False: 0]
  ------------------
 1607|      0|					*buf = malloc(objlen);
 1608|      0|					if (*buf == NULL) {
  ------------------
  |  Branch (1608:10): [True: 0, False: 0]
  ------------------
 1609|      0|						r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1610|      0|						break;
 1611|      0|					}
 1612|      0|				}
 1613|      0|				c = *len = objlen;
 1614|      0|				parm = *buf;
 1615|      0|			} else
 1616|     13|				c = objlen > *len ? *len : objlen;
  ------------------
  |  Branch (1616:9): [True: 1, False: 12]
  ------------------
 1617|       |
 1618|     13|			memcpy(parm, obj, c);
 1619|     13|			*len = c;
 1620|     13|		}
 1621|     13|		break;
 1622|  4.74k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  4.74k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1622:2): [True: 4.74k, False: 51.9k]
  ------------------
 1623|  4.74k|		if (parm != NULL)
  ------------------
  |  Branch (1623:7): [True: 4.74k, False: 5]
  ------------------
 1624|  4.74k|			r = sc_asn1_decode_object_id(obj, objlen, (struct sc_object_id *) parm);
 1625|  4.74k|		break;
 1626|     16|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|     16|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1626:2): [True: 16, False: 56.6k]
  ------------------
 1627|    246|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|    246|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1627:2): [True: 230, False: 56.4k]
  ------------------
 1628|    246|		if (parm != NULL) {
  ------------------
  |  Branch (1628:7): [True: 242, False: 4]
  ------------------
 1629|    242|			if (len == NULL)
  ------------------
  |  Branch (1629:8): [True: 0, False: 242]
  ------------------
 1630|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1631|    242|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    242|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1631:8): [True: 0, False: 242]
  ------------------
 1632|      0|				u8 **buf = (u8 **) parm;
 1633|      0|				*buf = malloc(objlen+1);
 1634|      0|				if (*buf == NULL) {
  ------------------
  |  Branch (1634:9): [True: 0, False: 0]
  ------------------
 1635|      0|					r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1636|      0|					break;
 1637|      0|				}
 1638|      0|				*len = objlen+1;
 1639|      0|				parm = *buf;
 1640|      0|			}
 1641|    242|			r = sc_asn1_decode_utf8string(obj, objlen, (u8 *) parm, len);
 1642|    242|			if (entry->flags & SC_ASN1_ALLOC) {
  ------------------
  |  |  149|    242|#define SC_ASN1_ALLOC			0x00000004
  ------------------
  |  Branch (1642:8): [True: 0, False: 242]
  ------------------
 1643|      0|				*len -= 1;
 1644|      0|			}
 1645|    242|		}
 1646|    246|		break;
 1647|  4.95k|	case SC_ASN1_PATH:
  ------------------
  |  |  174|  4.95k|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1647:2): [True: 4.95k, False: 51.7k]
  ------------------
 1648|  4.95k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1648:7): [True: 4.94k, False: 10]
  ------------------
 1649|  4.94k|			r = asn1_decode_path(ctx, obj, objlen, (sc_path_t *) parm, depth);
 1650|  4.95k|		break;
 1651|     45|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|     45|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1651:2): [True: 45, False: 56.6k]
  ------------------
 1652|     45|		if (entry->parm != NULL) {
  ------------------
  |  Branch (1652:7): [True: 45, False: 0]
  ------------------
 1653|     45|			struct sc_pkcs15_id *id = (struct sc_pkcs15_id *) parm;
 1654|     45|			size_t c = objlen > sizeof(id->value) ? sizeof(id->value) : objlen;
  ------------------
  |  Branch (1654:15): [True: 0, False: 45]
  ------------------
 1655|       |
 1656|     45|			memcpy(id->value, obj, c);
 1657|     45|			id->len = c;
 1658|     45|		}
 1659|     45|		break;
 1660|     91|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|     91|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1660:2): [True: 91, False: 56.6k]
  ------------------
 1661|     91|		if (entry->parm != NULL)
  ------------------
  |  Branch (1661:7): [True: 90, False: 1]
  ------------------
 1662|     90|			r = asn1_decode_p15_object(ctx, obj, objlen, (struct sc_asn1_pkcs15_object *) parm, depth);
 1663|     91|		break;
 1664|  3.75k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|  3.75k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1664:2): [True: 3.75k, False: 52.9k]
  ------------------
 1665|  3.75k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1665:7): [True: 3.75k, False: 0]
  ------------------
 1666|  3.75k|			r = sc_asn1_decode_algorithm_id(ctx, obj, objlen, (struct sc_algorithm_id *) parm, depth);
 1667|  3.75k|		break;
 1668|     50|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|     50|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1668:2): [True: 50, False: 56.6k]
  ------------------
 1669|     50|		if (entry->parm != NULL)
  ------------------
  |  Branch (1669:7): [True: 50, False: 0]
  ------------------
 1670|     50|			r = asn1_decode_se_info(ctx, obj, objlen, (sc_pkcs15_sec_env_info_t ***)entry->parm, len, depth);
 1671|     50|		break;
 1672|  2.09k|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|  2.09k|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1672:2): [True: 2.09k, False: 54.6k]
  ------------------
 1673|  2.09k|		if (entry->parm != NULL)
  ------------------
  |  Branch (1673:7): [True: 2.09k, False: 0]
  ------------------
 1674|  2.09k|			r = callback_func(ctx, entry->arg, obj, objlen, depth);
 1675|  2.09k|		break;
 1676|      0|	default:
  ------------------
  |  Branch (1676:2): [True: 0, False: 56.7k]
  ------------------
 1677|      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__
  |  |  ------------------
  ------------------
 1678|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1679|  56.7k|	}
 1680|  56.7k|	if (r) {
  ------------------
  |  Branch (1680:6): [True: 1.42k, False: 55.2k]
  ------------------
 1681|  1.42k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|  1.42k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1682|  1.42k|		      sc_strerror(r));
 1683|  1.42k|		return r;
 1684|  1.42k|	}
 1685|  55.2k|	entry->flags |= SC_ASN1_PRESENT;
  ------------------
  |  |  147|  55.2k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
 1686|  55.2k|	return 0;
 1687|  56.7k|}
asn1.c:decode_bit_field:
  692|    491|{
  693|    491|	u8		data[sizeof(unsigned int)];
  694|    491|	unsigned int	field = 0;
  695|    491|	int		i, n;
  696|       |
  697|    491|	if (outlen != sizeof(data))
  ------------------
  |  Branch (697:6): [True: 0, False: 491]
  ------------------
  698|      0|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  699|       |
  700|    491|	n = decode_bit_string(inbuf, inlen, data, sizeof(data), 1, strict);
  701|    491|	if (n < 0)
  ------------------
  |  Branch (701:6): [True: 31, False: 460]
  ------------------
  702|     31|		return n;
  703|       |
  704|  1.23k|	for (i = 0; i < n; i += 8) {
  ------------------
  |  Branch (704:14): [True: 774, False: 460]
  ------------------
  705|    774|		field |= ((unsigned int) data[i/8] << i);
  706|    774|	}
  707|    460|	memcpy(outbuf, &field, outlen);
  708|    460|	return 0;
  709|    491|}
asn1.c:sc_asn1_decode_utf8string:
  968|    242|{
  969|    242|	if (inlen+1 > *outlen)
  ------------------
  |  Branch (969:6): [True: 3, False: 239]
  ------------------
  970|      3|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      3|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  971|    239|	*outlen = inlen+1;
  972|    239|	memcpy(out, inbuf, inlen);
  973|    239|	out[inlen] = 0;
  974|    239|	return 0;
  975|    242|}
asn1.c:asn1_decode_path:
 1150|  4.94k|{
 1151|  4.94k|	int idx, count, r;
 1152|  4.94k|	struct sc_asn1_entry asn1_path_ext[3], asn1_path[5];
 1153|  4.94k|	unsigned char path_value[SC_MAX_PATH_SIZE], aid_value[SC_MAX_AID_SIZE];
 1154|  4.94k|	size_t path_len = sizeof(path_value), aid_len = sizeof(aid_value);
 1155|       |
 1156|  4.94k|	memset(path, 0, sizeof(struct sc_path));
 1157|       |
 1158|  4.94k|	sc_copy_asn1_entry(c_asn1_path_ext, asn1_path_ext);
 1159|  4.94k|	sc_copy_asn1_entry(c_asn1_path, asn1_path);
 1160|       |
 1161|  4.94k|	sc_format_asn1_entry(asn1_path_ext + 0, aid_value, &aid_len, 0);
 1162|  4.94k|	sc_format_asn1_entry(asn1_path_ext + 1, path_value, &path_len, 0);
 1163|       |
 1164|  4.94k|	sc_format_asn1_entry(asn1_path + 0, path_value, &path_len, 0);
 1165|  4.94k|	sc_format_asn1_entry(asn1_path + 1, &idx, NULL, 0);
 1166|  4.94k|	sc_format_asn1_entry(asn1_path + 2, &count, NULL, 0);
 1167|  4.94k|	sc_format_asn1_entry(asn1_path + 3, asn1_path_ext, NULL, 0);
 1168|       |
 1169|  4.94k|	r = asn1_decode(ctx, asn1_path, in, len, NULL, NULL, 0, depth + 1);
 1170|  4.94k|	if (r)
  ------------------
  |  Branch (1170:6): [True: 12, False: 4.93k]
  ------------------
 1171|     12|		return r;
 1172|       |
 1173|  4.93k|	if (asn1_path[3].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|  4.93k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1173:6): [True: 0, False: 4.93k]
  ------------------
 1174|       |		/* extended path present: set 'path' and 'aid' */
 1175|      0|		memcpy(path->aid.value, aid_value, aid_len);
 1176|      0|		path->aid.len = aid_len;
 1177|       |
 1178|      0|		memcpy(path->value, path_value, path_len);
 1179|      0|		path->len = path_len;
 1180|      0|	}
 1181|  4.93k|	else if (asn1_path[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|  4.93k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1181:11): [True: 4.90k, False: 29]
  ------------------
 1182|       |		/* path present: set 'path' */
 1183|  4.90k|		memcpy(path->value, path_value, path_len);
 1184|  4.90k|		path->len = path_len;
 1185|  4.90k|	}
 1186|     29|	else   {
 1187|       |		/* failed if both 'path' and 'pathExtended' are absent */
 1188|     29|		return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|     29|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
 1189|     29|	}
 1190|       |
 1191|  4.90k|	if (path->len == 2)
  ------------------
  |  Branch (1191:6): [True: 1.63k, False: 3.26k]
  ------------------
 1192|  1.63k|		path->type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  1.63k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1193|  3.26k|	else   if (path->aid.len && path->len > 2)
  ------------------
  |  Branch (1193:13): [True: 0, False: 3.26k]
  |  Branch (1193:30): [True: 0, False: 0]
  ------------------
 1194|      0|		path->type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 1195|  3.26k|	else
 1196|  3.26k|		path->type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  3.26k|#define SC_PATH_TYPE_PATH		2
  ------------------
 1197|       |
 1198|  4.90k|	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  4.90k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
              	if ((asn1_path[1].flags & SC_ASN1_PRESENT) && (asn1_path[2].flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  1.82k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1198:6): [True: 1.82k, False: 3.08k]
  |  Branch (1198:48): [True: 0, False: 1.82k]
  ------------------
 1199|      0|		path->index = idx;
 1200|      0|		path->count = count;
 1201|      0|	}
 1202|  4.90k|	else {
 1203|  4.90k|		path->index = 0;
 1204|  4.90k|		path->count = -1;
 1205|  4.90k|	}
 1206|       |
 1207|  4.90k|	return SC_SUCCESS;
  ------------------
  |  |   28|  4.90k|#define SC_SUCCESS				0
  ------------------
 1208|  4.93k|}
asn1.c:asn1_decode_p15_object:
 1396|     90|{
 1397|     90|	struct sc_pkcs15_object *p15_obj = obj->p15_obj;
 1398|     90|	struct sc_asn1_entry asn1_c_attr[6], asn1_p15_obj[5];
 1399|     90|	struct sc_asn1_entry asn1_ac_rules[SC_PKCS15_MAX_ACCESS_RULES + 1], asn1_ac_rule[SC_PKCS15_MAX_ACCESS_RULES][3];
 1400|     90|	size_t flags_len = sizeof(p15_obj->flags);
 1401|     90|	size_t label_len = sizeof(p15_obj->label);
 1402|     90|	size_t access_mode_len = sizeof(p15_obj->access_rules[0].access_mode);
 1403|     90|	int r, ii;
 1404|       |
 1405|    810|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)
  ------------------
  |  |   42|    810|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1405:13): [True: 720, False: 90]
  ------------------
 1406|    720|		sc_copy_asn1_entry(c_asn1_access_control_rule, asn1_ac_rule[ii]);
 1407|     90|	sc_copy_asn1_entry(c_asn1_access_control_rules, asn1_ac_rules);
 1408|       |
 1409|       |
 1410|     90|	sc_copy_asn1_entry(c_asn1_com_obj_attr, asn1_c_attr);
 1411|     90|	sc_copy_asn1_entry(c_asn1_p15_obj, asn1_p15_obj);
 1412|     90|	sc_format_asn1_entry(asn1_c_attr + 0, p15_obj->label, &label_len, 0);
 1413|     90|	sc_format_asn1_entry(asn1_c_attr + 1, &p15_obj->flags, &flags_len, 0);
 1414|     90|	sc_format_asn1_entry(asn1_c_attr + 2, &p15_obj->auth_id, NULL, 0);
 1415|     90|	sc_format_asn1_entry(asn1_c_attr + 3, &p15_obj->user_consent, NULL, 0);
 1416|       |
 1417|    810|	for (ii=0; ii<SC_PKCS15_MAX_ACCESS_RULES; ii++)   {
  ------------------
  |  |   42|    810|#define SC_PKCS15_MAX_ACCESS_RULES      8
  ------------------
  |  Branch (1417:13): [True: 720, False: 90]
  ------------------
 1418|    720|		sc_format_asn1_entry(asn1_ac_rule[ii] + 0, &p15_obj->access_rules[ii].access_mode, &access_mode_len, 0);
 1419|    720|		sc_format_asn1_entry(asn1_ac_rule[ii] + 1, &p15_obj->access_rules[ii].auth_id, NULL, 0);
 1420|    720|		sc_format_asn1_entry(asn1_ac_rules + ii, asn1_ac_rule[ii], NULL, 0);
 1421|    720|	}
 1422|     90|	sc_format_asn1_entry(asn1_c_attr + 4, asn1_ac_rules, NULL, 0);
 1423|       |
 1424|     90|	sc_format_asn1_entry(asn1_p15_obj + 0, asn1_c_attr, NULL, 0);
 1425|     90|	sc_format_asn1_entry(asn1_p15_obj + 1, obj->asn1_class_attr, NULL, 0);
 1426|     90|	sc_format_asn1_entry(asn1_p15_obj + 2, obj->asn1_subclass_attr, NULL, 0);
 1427|     90|	sc_format_asn1_entry(asn1_p15_obj + 3, obj->asn1_type_attr, NULL, 0);
 1428|       |
 1429|     90|	r = asn1_decode(ctx, asn1_p15_obj, in, len, NULL, NULL, 0, depth + 1);
 1430|     90|	return r;
 1431|     90|}
asn1.c:asn1_decode_se_info:
 1244|     50|{
 1245|     50|	struct sc_pkcs15_sec_env_info **ses;
 1246|     50|	const unsigned char *ptr = obj;
 1247|     50|	size_t idx, ptrlen = objlen;
 1248|     50|	int ret;
 1249|       |
 1250|     50|	LOG_FUNC_CALLED(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1251|       |
 1252|     50|	ses = calloc(SC_MAX_SE_NUM, sizeof(sc_pkcs15_sec_env_info_t *));
  ------------------
  |  |   51|     50|#define SC_MAX_SE_NUM			8
  ------------------
 1253|     50|	if (ses == NULL) {
  ------------------
  |  Branch (1253:6): [True: 0, False: 50]
  ------------------
 1254|      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]
  |  |  ------------------
  ------------------
 1255|      0|	}
 1256|       |
 1257|     59|	for (idx=0; idx < SC_MAX_SE_NUM && ptrlen; )   {
  ------------------
  |  |   51|    118|#define SC_MAX_SE_NUM			8
  ------------------
  |  Branch (1257:14): [True: 59, False: 0]
  |  Branch (1257:37): [True: 17, False: 42]
  ------------------
 1258|     17|		struct sc_asn1_entry asn1_se[2];
 1259|     17|		struct sc_asn1_entry asn1_se_info[4];
 1260|     17|		struct sc_pkcs15_sec_env_info si;
 1261|       |
 1262|     17|		sc_copy_asn1_entry(c_asn1_se, asn1_se);
 1263|     17|		sc_copy_asn1_entry(c_asn1_se_info, asn1_se_info);
 1264|       |
 1265|     17|		si.aid.len = sizeof(si.aid.value);
 1266|     17|		sc_format_asn1_entry(asn1_se_info + 0, &si.se, NULL, 0);
 1267|     17|		sc_format_asn1_entry(asn1_se_info + 1, &si.owner, NULL, 0);
 1268|     17|		sc_format_asn1_entry(asn1_se_info + 2, &si.aid.value, &si.aid.len, 0);
 1269|     17|		sc_format_asn1_entry(asn1_se + 0, asn1_se_info, NULL, 0);
 1270|       |
 1271|     17|		ret = asn1_decode(ctx, asn1_se, ptr, ptrlen, &ptr, &ptrlen, 0, depth+1);
 1272|     17|		if (ret != SC_SUCCESS)
  ------------------
  |  |   28|     17|#define SC_SUCCESS				0
  ------------------
  |  Branch (1272:7): [True: 8, False: 9]
  ------------------
 1273|      8|			goto err;
 1274|      9|		if (!(asn1_se_info[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|      9|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1274:7): [True: 5, False: 4]
  ------------------
 1275|      5|			sc_init_oid(&si.owner);
 1276|       |
 1277|      9|		ses[idx] = calloc(1, sizeof(sc_pkcs15_sec_env_info_t));
 1278|      9|		if (ses[idx] == NULL) {
  ------------------
  |  Branch (1278:7): [True: 0, False: 9]
  ------------------
 1279|      0|			ret = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1280|      0|			goto err;
 1281|      0|		}
 1282|       |
 1283|      9|		memcpy(ses[idx], &si, sizeof(struct sc_pkcs15_sec_env_info));
 1284|      9|		idx++;
 1285|      9|	}
 1286|       |
 1287|     42|	*se  = ses;
 1288|     42|	*num = idx;
 1289|     42|	ret = SC_SUCCESS;
  ------------------
  |  |   28|     42|#define SC_SUCCESS				0
  ------------------
 1290|     50|err:
 1291|     50|	if (ret != SC_SUCCESS) {
  ------------------
  |  |   28|     50|#define SC_SUCCESS				0
  ------------------
  |  Branch (1291:6): [True: 8, False: 42]
  ------------------
 1292|      8|		size_t i;
 1293|     14|		for (i = 0; i < idx; i++)
  ------------------
  |  Branch (1293:15): [True: 6, False: 8]
  ------------------
 1294|      6|			if (ses[i])
  ------------------
  |  Branch (1294:8): [True: 6, False: 0]
  ------------------
 1295|      6|				free(ses[i]);
 1296|      8|		free(ses);
 1297|      8|	}
 1298|       |
 1299|     50|	SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_ASN1, ret);
  ------------------
  |  |  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|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 8, False: 42]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 1300|     50|}
asn1.c:asn1_encode:
 2045|  24.6k|{
 2046|  24.6k|	int r, idx = 0;
 2047|  24.6k|	u8 *obj = NULL, *buf = NULL, *tmp;
 2048|  24.6k|	size_t total = 0, objsize;
 2049|       |
 2050|  24.6k|	if (asn1 == NULL) {
  ------------------
  |  Branch (2050:6): [True: 0, False: 24.6k]
  ------------------
 2051|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2052|      0|	}
 2053|       |
 2054|  65.9k|	for (idx = 0; asn1[idx].name != NULL; idx++) {
  ------------------
  |  Branch (2054:16): [True: 41.3k, False: 24.6k]
  ------------------
 2055|  41.3k|		r = asn1_encode_entry(ctx, &asn1[idx], &obj, &objsize, depth);
 2056|  41.3k|		if (r) {
  ------------------
  |  Branch (2056:7): [True: 34, False: 41.3k]
  ------------------
 2057|     34|			if (obj)
  ------------------
  |  Branch (2057:8): [True: 0, False: 34]
  ------------------
 2058|      0|				free(obj);
 2059|     34|			if (buf)
  ------------------
  |  Branch (2059:8): [True: 10, False: 24]
  ------------------
 2060|     10|				free(buf);
 2061|     34|			return r;
 2062|     34|		}
 2063|       |		/* in case of an empty (optional) element continue with
 2064|       |		 * the next asn1 element */
 2065|  41.3k|		if (!objsize)
  ------------------
  |  Branch (2065:7): [True: 14.4k, False: 26.8k]
  ------------------
 2066|  14.4k|			continue;
 2067|  26.8k|		tmp = (u8 *) realloc(buf, total + objsize);
 2068|  26.8k|		if (!tmp) {
  ------------------
  |  Branch (2068:7): [True: 0, False: 26.8k]
  ------------------
 2069|      0|			if (obj)
  ------------------
  |  Branch (2069:8): [True: 0, False: 0]
  ------------------
 2070|      0|				free(obj);
 2071|      0|			if (buf)
  ------------------
  |  Branch (2071:8): [True: 0, False: 0]
  ------------------
 2072|      0|				free(buf);
 2073|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2074|      0|		}
 2075|  26.8k|		buf = tmp;
 2076|  26.8k|		memcpy(buf + total, obj, objsize);
 2077|  26.8k|		free(obj);
 2078|  26.8k|		obj = NULL;
 2079|  26.8k|		total += objsize;
 2080|  26.8k|	}
 2081|  24.6k|	*ptr = buf;
 2082|  24.6k|	*size = total;
 2083|  24.6k|	return 0;
 2084|  24.6k|}
asn1.c:asn1_encode_entry:
 1828|  41.3k|{
 1829|  41.3k|	void *parm = entry->parm;
 1830|  41.3k|	int (*callback_func)(sc_context_t *nctx, void *arg, u8 **nobj,
 1831|  41.3k|			     size_t *nobjlen, int ndepth);
 1832|  41.3k|	const size_t *len = (const size_t *) entry->arg;
 1833|  41.3k|	int r = 0;
 1834|  41.3k|	u8 * buf = NULL;
 1835|  41.3k|	size_t buflen = 0;
 1836|       |
 1837|  41.3k|	callback_func = parm;
 1838|       |
 1839|  41.3k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1, "%*.*sencoding '%s'%s\n",
  ------------------
  |  |   70|  41.3k|#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)
  |  |  ------------------
  |  |  |  | 1840|  41.3k|	       	depth, depth, "", entry->name,
  |  |  |  | 1841|  41.3k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
  |  |  |  |  ------------------
  |  |  |  |  |  |  147|  41.3k|#define SC_ASN1_PRESENT			0x00000001
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1840|  41.3k|	       	depth, depth, "", entry->name,
 1841|  41.3k|		(entry->flags & SC_ASN1_PRESENT)? "" : " (not present)");
 1842|  41.3k|	if (!(entry->flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  41.3k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1842:6): [True: 14.4k, False: 26.9k]
  ------------------
 1843|  14.4k|		goto no_object;
 1844|  26.9k|	sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|  53.8k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (70:115): [True: 19.8k, False: 7.07k]
  |  |  ------------------
  ------------------
 1845|  26.9k|		 "%*.*stype=%d, tag=0x%02x, parm=%p, len=%"SC_FORMAT_LEN_SIZE_T"u\n",
 1846|  26.9k|		 depth, depth, "", entry->type, entry->tag, parm,
 1847|  26.9k|		 len ? *len : 0);
 1848|       |
 1849|  26.9k|	if (entry->type == SC_ASN1_CHOICE) {
  ------------------
  |  |  170|  26.9k|#define SC_ASN1_CHOICE			130
  ------------------
  |  Branch (1849:6): [True: 0, False: 26.9k]
  ------------------
 1850|      0|		const struct sc_asn1_entry *list, *choice = NULL;
 1851|       |
 1852|      0|		list = (const struct sc_asn1_entry *) parm;
 1853|      0|		while (list->name != NULL) {
  ------------------
  |  Branch (1853:10): [True: 0, False: 0]
  ------------------
 1854|      0|			if (list->flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|      0|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (1854:8): [True: 0, False: 0]
  ------------------
 1855|      0|				if (choice) {
  ------------------
  |  Branch (1855:9): [True: 0, False: 0]
  ------------------
 1856|      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__
  |  |  ------------------
  ------------------
 1857|      0|						"ASN.1 problem: more than "
 1858|      0|						"one CHOICE when encoding %s: "
 1859|      0|						"%s and %s both present\n",
 1860|      0|						entry->name,
 1861|      0|						choice->name,
 1862|      0|						list->name);
 1863|      0|					return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1864|      0|				}
 1865|      0|				choice = list;
 1866|      0|			}
 1867|      0|			list++;
 1868|      0|		}
 1869|      0|		if (choice == NULL)
  ------------------
  |  Branch (1869:7): [True: 0, False: 0]
  ------------------
 1870|      0|			goto no_object;
 1871|      0|		return asn1_encode_entry(ctx, choice, obj, objlen, depth + 1);
 1872|      0|	}
 1873|       |
 1874|  26.9k|	if (entry->type != SC_ASN1_NULL && parm == NULL) {
  ------------------
  |  |  158|  53.8k|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1874:6): [True: 26.4k, False: 461]
  |  Branch (1874:37): [True: 11, False: 26.4k]
  ------------------
 1875|     11|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "unexpected parm == NULL\n");
  ------------------
  |  |   70|     11|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1876|     11|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     11|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1877|     11|	}
 1878|       |
 1879|  26.8k|	switch (entry->type) {
 1880|  1.81k|	case SC_ASN1_STRUCT:
  ------------------
  |  |  169|  1.81k|#define SC_ASN1_STRUCT			129
  ------------------
  |  Branch (1880:2): [True: 1.81k, False: 25.0k]
  ------------------
 1881|  1.81k|		r = asn1_encode(ctx, (const struct sc_asn1_entry *) parm, &buf,
 1882|  1.81k|				&buflen, depth + 1);
 1883|  1.81k|		break;
 1884|    461|	case SC_ASN1_NULL:
  ------------------
  |  |  158|    461|#define SC_ASN1_NULL                    5
  ------------------
  |  Branch (1884:2): [True: 461, False: 26.4k]
  ------------------
 1885|    461|		buf = NULL;
 1886|    461|		buflen = 0;
 1887|    461|		break;
 1888|      0|	case SC_ASN1_BOOLEAN:
  ------------------
  |  |  153|      0|#define SC_ASN1_BOOLEAN                 1
  ------------------
  |  Branch (1888:2): [True: 0, False: 26.8k]
  ------------------
 1889|      0|		buf = malloc(1);
 1890|      0|		if (buf == NULL) {
  ------------------
  |  Branch (1890:7): [True: 0, False: 0]
  ------------------
 1891|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1892|      0|			break;
 1893|      0|		}
 1894|      0|		buf[0] = *((int *) parm) ? 0xFF : 0;
  ------------------
  |  Branch (1894:12): [True: 0, False: 0]
  ------------------
 1895|      0|		buflen = 1;
 1896|      0|		break;
 1897|      0|	case SC_ASN1_INTEGER:
  ------------------
  |  |  154|      0|#define SC_ASN1_INTEGER                 2
  ------------------
  |  Branch (1897:2): [True: 0, False: 26.8k]
  ------------------
 1898|      0|	case SC_ASN1_ENUMERATED:
  ------------------
  |  |  160|      0|#define SC_ASN1_ENUMERATED              10
  ------------------
  |  Branch (1898:2): [True: 0, False: 26.8k]
  ------------------
 1899|      0|		r = asn1_encode_integer(*((int *) entry->parm), &buf, &buflen);
 1900|      0|		break;
 1901|  1.29k|	case SC_ASN1_BIT_STRING_NI:
  ------------------
  |  |  156|  1.29k|#define SC_ASN1_BIT_STRING_NI           128
  ------------------
  |  Branch (1901:2): [True: 1.29k, False: 25.6k]
  ------------------
 1902|  1.29k|	case SC_ASN1_BIT_STRING:
  ------------------
  |  |  155|  1.29k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1902:2): [True: 0, False: 26.8k]
  ------------------
 1903|  1.29k|		if (len != NULL) {
  ------------------
  |  Branch (1903:7): [True: 1.29k, False: 0]
  ------------------
 1904|  1.29k|			if (entry->type == SC_ASN1_BIT_STRING)
  ------------------
  |  |  155|  1.29k|#define SC_ASN1_BIT_STRING              3
  ------------------
  |  Branch (1904:8): [True: 0, False: 1.29k]
  ------------------
 1905|      0|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 1);
 1906|  1.29k|			else
 1907|  1.29k|				r = encode_bit_string((const u8 *) parm, *len, &buf, &buflen, 0);
 1908|  1.29k|		} else {
 1909|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1910|      0|		}
 1911|  1.29k|		break;
 1912|      0|	case SC_ASN1_BIT_FIELD:
  ------------------
  |  |  171|      0|#define SC_ASN1_BIT_FIELD		131	/* bit string as integer */
  ------------------
  |  Branch (1912:2): [True: 0, False: 26.8k]
  ------------------
 1913|      0|		if (len != NULL) {
  ------------------
  |  Branch (1913:7): [True: 0, False: 0]
  ------------------
 1914|      0|			r = encode_bit_field((const u8 *) parm, *len, &buf, &buflen);
 1915|      0|		} else {
 1916|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1917|      0|		}
 1918|      0|		break;
 1919|      0|	case SC_ASN1_PRINTABLESTRING:
  ------------------
  |  |  164|      0|#define SC_ASN1_PRINTABLESTRING         19
  ------------------
  |  Branch (1919:2): [True: 0, False: 26.8k]
  ------------------
 1920|  18.5k|	case SC_ASN1_OCTET_STRING:
  ------------------
  |  |  157|  18.5k|#define SC_ASN1_OCTET_STRING            4
  ------------------
  |  Branch (1920:2): [True: 18.5k, False: 8.37k]
  ------------------
 1921|  18.5k|	case SC_ASN1_UTF8STRING:
  ------------------
  |  |  161|  18.5k|#define SC_ASN1_UTF8STRING              12
  ------------------
  |  Branch (1921:2): [True: 0, False: 26.8k]
  ------------------
 1922|  18.5k|		if (len != NULL) {
  ------------------
  |  Branch (1922:7): [True: 18.5k, False: 0]
  ------------------
 1923|  18.5k|			buf = malloc(*len + 1);
 1924|  18.5k|			if (buf == NULL) {
  ------------------
  |  Branch (1924:8): [True: 0, False: 18.5k]
  ------------------
 1925|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1926|      0|				break;
 1927|      0|			}
 1928|  18.5k|			buflen = 0;
 1929|       |			/* If the integer is supposed to be unsigned, insert
 1930|       |			 * a padding byte if the MSB is one */
 1931|  18.5k|			if ((entry->flags & SC_ASN1_UNSIGNED)
  ------------------
  |  |  150|  18.5k|#define SC_ASN1_UNSIGNED		0x00000008
  ------------------
  |  Branch (1931:8): [True: 1.02k, False: 17.4k]
  ------------------
 1932|  1.02k|					&& (((u8 *) parm)[0] & 0x80)) {
  ------------------
  |  Branch (1932:9): [True: 452, False: 572]
  ------------------
 1933|    452|				buf[buflen++] = 0x00;
 1934|    452|			}
 1935|  18.5k|			memcpy(buf + buflen, parm, *len);
 1936|  18.5k|			buflen += *len;
 1937|  18.5k|		} else {
 1938|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1939|      0|		}
 1940|  18.5k|		break;
 1941|  18.5k|	case SC_ASN1_GENERALIZEDTIME:
  ------------------
  |  |  166|      0|#define SC_ASN1_GENERALIZEDTIME         24
  ------------------
  |  Branch (1941:2): [True: 0, False: 26.8k]
  ------------------
 1942|      0|		if (len != NULL) {
  ------------------
  |  Branch (1942:7): [True: 0, False: 0]
  ------------------
 1943|      0|			buf = malloc(*len);
 1944|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1944:8): [True: 0, False: 0]
  ------------------
 1945|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1946|      0|				break;
 1947|      0|			}
 1948|      0|			memcpy(buf, parm, *len);
 1949|      0|			buflen = *len;
 1950|      0|		} else {
 1951|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1952|      0|		}
 1953|      0|		break;
 1954|  3.50k|	case SC_ASN1_OBJECT:
  ------------------
  |  |  159|  3.50k|#define SC_ASN1_OBJECT                  6
  ------------------
  |  Branch (1954:2): [True: 3.50k, False: 23.3k]
  ------------------
 1955|  3.50k|		r = sc_asn1_encode_object_id(&buf, &buflen, (struct sc_object_id *) parm);
 1956|  3.50k|		break;
 1957|      0|	case SC_ASN1_PATH:
  ------------------
  |  |  174|      0|#define SC_ASN1_PATH			256
  ------------------
  |  Branch (1957:2): [True: 0, False: 26.8k]
  ------------------
 1958|      0|		r = asn1_encode_path(ctx, (const sc_path_t *) parm, &buf, &buflen, depth, entry->flags);
 1959|      0|		break;
 1960|      0|	case SC_ASN1_PKCS15_ID:
  ------------------
  |  |  175|      0|#define SC_ASN1_PKCS15_ID		257
  ------------------
  |  Branch (1960:2): [True: 0, False: 26.8k]
  ------------------
 1961|      0|		{
 1962|      0|			const struct sc_pkcs15_id *id = (const struct sc_pkcs15_id *) parm;
 1963|       |
 1964|      0|			buf = malloc(id->len);
 1965|      0|			if (buf == NULL) {
  ------------------
  |  Branch (1965:8): [True: 0, False: 0]
  ------------------
 1966|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1967|      0|				break;
 1968|      0|			}
 1969|      0|			memcpy(buf, id->value, id->len);
 1970|      0|			buflen = id->len;
 1971|      0|		}
 1972|      0|		break;
 1973|      0|	case SC_ASN1_PKCS15_OBJECT:
  ------------------
  |  |  176|      0|#define SC_ASN1_PKCS15_OBJECT		258
  ------------------
  |  Branch (1973:2): [True: 0, False: 26.8k]
  ------------------
 1974|      0|		r = asn1_encode_p15_object(ctx, (const struct sc_asn1_pkcs15_object *) parm, &buf, &buflen, depth);
 1975|      0|		break;
 1976|  1.29k|	case SC_ASN1_ALGORITHM_ID:
  ------------------
  |  |  177|  1.29k|#define SC_ASN1_ALGORITHM_ID		259
  ------------------
  |  Branch (1976:2): [True: 1.29k, False: 25.6k]
  ------------------
 1977|  1.29k|		r = sc_asn1_encode_algorithm_id(ctx, &buf, &buflen, (const struct sc_algorithm_id *) parm, depth);
 1978|  1.29k|		break;
 1979|      0|	case SC_ASN1_SE_INFO:
  ------------------
  |  |  178|      0|#define SC_ASN1_SE_INFO			260
  ------------------
  |  Branch (1979:2): [True: 0, False: 26.8k]
  ------------------
 1980|      0|		if (!len)
  ------------------
  |  Branch (1980:7): [True: 0, False: 0]
  ------------------
 1981|      0|			return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1982|      0|		r = asn1_encode_se_info(ctx, (struct sc_pkcs15_sec_env_info **)parm, *len, &buf, &buflen, depth);
 1983|      0|		break;
 1984|      0|	case SC_ASN1_CALLBACK:
  ------------------
  |  |  181|      0|#define SC_ASN1_CALLBACK		384
  ------------------
  |  Branch (1984:2): [True: 0, False: 26.8k]
  ------------------
 1985|      0|		r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
 1986|      0|		break;
 1987|      0|	default:
  ------------------
  |  Branch (1987:2): [True: 0, False: 26.8k]
  ------------------
 1988|      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__
  |  |  ------------------
  ------------------
 1989|      0|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 1990|  26.8k|	}
 1991|  26.8k|	if (r) {
  ------------------
  |  Branch (1991:6): [True: 17, False: 26.8k]
  ------------------
 1992|     17|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
  ------------------
  |  |   70|     17|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1993|     17|		      sc_strerror(r));
 1994|     17|		if (buf)
  ------------------
  |  Branch (1994:7): [True: 0, False: 17]
  ------------------
 1995|      0|			free(buf);
 1996|     17|		return r;
 1997|     17|	}
 1998|       |
 1999|       |	/* Treatment of OPTIONAL elements:
 2000|       |	 *  -	if the encoding has 0 length, and the element is OPTIONAL,
 2001|       |	 *	we don't write anything (unless it's an ASN1 NULL and the
 2002|       |	 *      SC_ASN1_PRESENT flag is set).
 2003|       |	 *  -	if the encoding has 0 length, but the element is non-OPTIONAL,
 2004|       |	 *	constructed, we write a empty element (e.g. a SEQUENCE of
 2005|       |	 *      length 0). In case of an ASN1 NULL just write the tag and
 2006|       |	 *      length (i.e. 0x05,0x00).
 2007|       |	 *  -	any other empty objects are considered bogus
 2008|       |	 */
 2009|  41.3k|no_object:
 2010|  41.3k|	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  148|  56.2k|#define SC_ASN1_OPTIONAL		0x00000002
  ------------------
              	if (!buflen && entry->flags & SC_ASN1_OPTIONAL && !(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|  14.8k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2010:6): [True: 14.9k, False: 26.4k]
  |  Branch (2010:17): [True: 14.8k, False: 6]
  |  Branch (2010:52): [True: 14.4k, False: 461]
  ------------------
 2011|       |		/* This happens when we try to encode e.g. the
 2012|       |		 * subClassAttributes, which may be empty */
 2013|  14.4k|		*obj = NULL;
 2014|  14.4k|		*objlen = 0;
 2015|  14.4k|		r = 0;
 2016|  26.8k|	} else if (!buflen && (entry->flags & SC_ASN1_EMPTY_ALLOWED)) {
  ------------------
  |  |  151|    467|#define SC_ASN1_EMPTY_ALLOWED           0x00000010
  ------------------
  |  Branch (2016:13): [True: 467, False: 26.4k]
  |  Branch (2016:24): [True: 0, False: 467]
  ------------------
 2017|      0|		*obj = NULL;
 2018|      0|		*objlen = 0;
 2019|      0|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2020|      0|		if (r)
  ------------------
  |  Branch (2020:7): [True: 0, False: 0]
  ------------------
 2021|      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__
  |  |  ------------------
  ------------------
 2022|  26.8k|	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  158|  27.3k|#define SC_ASN1_NULL                    5
  ------------------
              	} else if (buflen || entry->type == SC_ASN1_NULL || entry->tag & SC_ASN1_CONS) {
  ------------------
  |  |  141|      6|#define SC_ASN1_CONS			0x20000000
  ------------------
  |  Branch (2022:13): [True: 26.4k, False: 467]
  |  Branch (2022:23): [True: 461, False: 6]
  |  Branch (2022:54): [True: 0, False: 6]
  ------------------
 2023|  26.8k|		r = asn1_write_element(ctx, entry->tag, buf, buflen, obj, objlen);
 2024|  26.8k|		if (r)
  ------------------
  |  Branch (2024:7): [True: 0, False: 26.8k]
  ------------------
 2025|      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__
  |  |  ------------------
  ------------------
 2026|  26.8k|					sc_strerror(r));
 2027|  26.8k|	} else if (!(entry->flags & SC_ASN1_PRESENT)) {
  ------------------
  |  |  147|      6|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (2027:13): [True: 0, False: 6]
  ------------------
 2028|      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__
  |  |  ------------------
  ------------------
 2029|      0|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2030|      6|	} else {
 2031|      6|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "cannot encode empty non-optional ASN.1 object\n");
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2032|      6|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2033|      6|	}
 2034|  41.3k|	if (buf)
  ------------------
  |  Branch (2034:6): [True: 26.4k, False: 14.8k]
  ------------------
 2035|  26.4k|		free(buf);
 2036|  41.3k|	if (r >= 0)
  ------------------
  |  Branch (2036:6): [True: 41.3k, False: 6]
  ------------------
 2037|  41.3k|		sc_debug(ctx, SC_LOG_DEBUG_ASN1,
  ------------------
  |  |   70|  41.3k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2038|  41.3k|			 "%*.*slength of encoded item=%"SC_FORMAT_LEN_SIZE_T"u\n",
 2039|  41.3k|			 depth, depth, "", *objlen);
 2040|  41.3k|	return r;
 2041|  26.8k|}
asn1.c:encode_bit_string:
  652|  1.29k|{
  653|  1.29k|	const u8 *in = inbuf;
  654|  1.29k|	u8 *out;
  655|  1.29k|	size_t bytes, skipped = 0;
  656|       |
  657|  1.29k|	bytes = BYTES4BITS(bits_left) + 1;
  ------------------
  |  |  146|  1.29k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  658|  1.29k|	*outbuf = out = malloc(bytes);
  659|  1.29k|	if (out == NULL)
  ------------------
  |  Branch (659:6): [True: 0, False: 1.29k]
  ------------------
  660|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  661|  1.29k|	*outlen = bytes;
  662|  1.29k|	out += 1;
  663|  67.5k|	while (bits_left) {
  ------------------
  |  Branch (663:9): [True: 66.2k, False: 1.29k]
  ------------------
  664|  66.2k|		size_t i, bits_to_go = 8;
  665|       |
  666|  66.2k|		*out = 0;
  667|  66.2k|		if (bits_left < 8) {
  ------------------
  |  Branch (667:7): [True: 0, False: 66.2k]
  ------------------
  668|      0|			bits_to_go = bits_left;
  669|      0|			skipped = 8 - bits_left;
  670|      0|		}
  671|  66.2k|		if (invert) {
  ------------------
  |  Branch (671:7): [True: 0, False: 66.2k]
  ------------------
  672|      0|			for (i = 0; i < bits_to_go; i++)
  ------------------
  |  Branch (672:16): [True: 0, False: 0]
  ------------------
  673|      0|				*out |= ((*in >> i) & 1) << (7 - i);
  674|  66.2k|		} else {
  675|  66.2k|			*out = *in;
  676|  66.2k|			if (bits_left < 8)
  ------------------
  |  Branch (676:8): [True: 0, False: 66.2k]
  ------------------
  677|      0|				return SC_ERROR_NOT_SUPPORTED; /* FIXME */
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  678|  66.2k|		}
  679|  66.2k|		bits_left -= bits_to_go;
  680|  66.2k|		out++, in++;
  681|  66.2k|	}
  682|  1.29k|	out = *outbuf;
  683|  1.29k|	out[0] = skipped;
  684|  1.29k|	return 0;
  685|  1.29k|}

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

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

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

sc_get_authentic_driver:
 2178|  15.3k|{
 2179|  15.3k|	return sc_get_driver();
 2180|  15.3k|}
card-authentic.c:sc_get_driver:
 2143|  15.3k|{
 2144|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2145|       |
 2146|  15.3k|	if (!iso_ops)
  ------------------
  |  Branch (2146:6): [True: 1, False: 15.3k]
  ------------------
 2147|      1|		iso_ops = iso_drv->ops;
 2148|       |
 2149|  15.3k|	authentic_ops = *iso_ops;
 2150|       |
 2151|  15.3k|	authentic_ops.match_card = authentic_match_card;
 2152|  15.3k|	authentic_ops.init = authentic_init;
 2153|  15.3k|	authentic_ops.finish = authentic_finish;
 2154|  15.3k|	authentic_ops.read_binary = authentic_read_binary;
 2155|  15.3k|	authentic_ops.write_binary = authentic_write_binary;
 2156|  15.3k|	authentic_ops.update_binary = authentic_update_binary;
 2157|  15.3k|	authentic_ops.erase_binary = authentic_erase_binary;
 2158|       |	/* authentic_ops.resize_file = authentic_resize_file; */
 2159|  15.3k|	authentic_ops.select_file = authentic_select_file;
 2160|       |	/* get_response: Untested */
 2161|  15.3k|	authentic_ops.get_challenge = authentic_get_challenge;
 2162|  15.3k|	authentic_ops.set_security_env = authentic_set_security_env;
 2163|       |	/* decipher: Untested */
 2164|  15.3k|	authentic_ops.decipher = authentic_decipher;
 2165|       |	/* authentic_ops.compute_signature = authentic_compute_signature; */
 2166|  15.3k|	authentic_ops.create_file = authentic_create_file;
 2167|  15.3k|	authentic_ops.delete_file = authentic_delete_file;
 2168|  15.3k|	authentic_ops.card_ctl = authentic_card_ctl;
 2169|  15.3k|	authentic_ops.process_fci = authentic_process_fci;
 2170|  15.3k|	authentic_ops.pin_cmd = authentic_pin_cmd;
 2171|  15.3k|	authentic_ops.card_reader_lock_obtained = authentic_card_reader_lock_obtained;
 2172|       |
 2173|  15.3k|	return &authentic_drv;
 2174|  15.3k|}
card-authentic.c:authentic_match_card:
  390|  10.2k|{
  391|  10.2k|	struct sc_context *ctx = card->ctx;
  392|  10.2k|	int i;
  393|       |
  394|  10.2k|	sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
  ------------------
  |  |  129|  10.2k|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|  10.2k|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  395|  10.2k|	i = _sc_match_atr(card, authentic_known_atrs, &card->type);
  396|  10.2k|	if (i < 0)   {
  ------------------
  |  Branch (396:6): [True: 9.88k, False: 330]
  ------------------
  397|  9.88k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  9.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__
  |  |  ------------------
  ------------------
  398|  9.88k|		return 0;
  399|  9.88k|	}
  400|       |
  401|    330|	sc_log(ctx, "'%s' card matched", authentic_known_atrs[i].name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  402|    330|	return 1;
  403|  10.2k|}
card-authentic.c:authentic_init:
  442|    330|{
  443|    330|	struct sc_context *ctx = card->ctx;
  444|    330|	int ii, rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|    330|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  445|       |
  446|    330|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    330|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    330|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    330|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    330|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 330]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  447|    330|	for(ii=0;authentic_known_atrs[ii].atr;ii++)   {
  ------------------
  |  Branch (447:11): [True: 330, False: 0]
  ------------------
  448|    330|		if (card->type == authentic_known_atrs[ii].type)   {
  ------------------
  |  Branch (448:7): [True: 330, False: 0]
  ------------------
  449|    330|			card->name = authentic_known_atrs[ii].name;
  450|    330|			card->flags = authentic_known_atrs[ii].flags;
  451|    330|			break;
  452|    330|		}
  453|    330|	}
  454|       |
  455|    330|	if (!authentic_known_atrs[ii].atr)
  ------------------
  |  Branch (455:6): [True: 0, False: 330]
  ------------------
  456|    330|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  457|       |
  458|    330|	card->cla  = 0x00;
  459|    330|	card->drv_data = (struct authentic_private_data *) calloc(1, sizeof(struct authentic_private_data));
  460|    330|	if (!card->drv_data)
  ------------------
  |  Branch (460:6): [True: 0, False: 330]
  ------------------
  461|    330|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  462|       |
  463|    330|	if (card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (463:6): [True: 330, False: 0]
  ------------------
  464|    330|		rv = authentic_init_oberthur_authentic_3_2(card);
  465|       |
  466|    330|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    330|#define SC_SUCCESS				0
  ------------------
  |  Branch (466:6): [True: 155, False: 175]
  ------------------
  467|    155|		rv = authentic_get_serialnr(card, NULL);
  468|       |
  469|    330|	if (rv != SC_SUCCESS)
  ------------------
  |  |   28|    330|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 43, False: 287]
  ------------------
  470|     43|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     43|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  471|       |
  472|       |	/* Free private data on error */
  473|    330|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    330|#define SC_SUCCESS				0
  ------------------
  |  Branch (473:6): [True: 43, False: 287]
  ------------------
  474|     43|		free(card->drv_data);
  475|     43|		card->drv_data = NULL;
  476|     43|	}
  477|    330|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    330|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    330|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    330|	int _ret = r; \
  |  |  |  |  155|    330|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 330, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    330|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     43|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 43, False: 287]
  |  |  |  |  ------------------
  |  |  |  |  157|    330|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    330|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    330|	return _ret; \
  |  |  |  |  163|    330|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  478|    330|}
card-authentic.c:authentic_init_oberthur_authentic_3_2:
  408|    330|{
  409|    330|	struct sc_context *ctx = card->ctx;
  410|    330|	unsigned int flags;
  411|    330|	int rv = 0;
  412|       |
  413|    330|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    330|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    330|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    330|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    330|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 330]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  414|       |
  415|    330|	flags = AUTHENTIC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   43|    330|#define AUTHENTIC_CARD_DEFAULT_FLAGS ( 0		\
  |  |   44|    330|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |  102|    330|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   45|    330|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  115|    330|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   46|    330|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  120|    330|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  118|    330|#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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  119|    330|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   47|    330|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  142|    330|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   48|    330|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  143|    330|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   49|    330|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  147|    330|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  416|       |
  417|    330|	card->caps = SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    330|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  418|    330|	card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|    330|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  419|    330|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  564|    330|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  420|       |
  421|    330|#ifdef ENABLE_SM
  422|    330|	card->sm_ctx.ops.open = authentic_sm_open;
  423|    330|	card->sm_ctx.ops.get_sm_apdu = authentic_sm_get_wrapped_apdu;
  424|    330|	card->sm_ctx.ops.free_sm_apdu = authentic_sm_free_wrapped_apdu;
  425|    330|#endif
  426|       |
  427|    330|	rv = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
  428|    330|	LOG_TEST_RET(ctx, rv, "AuthentIC application select error");
  ------------------
  |  |  174|    330|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    330|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    330|	int _ret = (r); \
  |  |  |  |  168|    330|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 140, False: 190]
  |  |  |  |  ------------------
  |  |  |  |  169|    140|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    140|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    140|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    140|		return _ret; \
  |  |  |  |  172|    140|	} \
  |  |  |  |  173|    330|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 190]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|       |
  430|    190|	rv = authentic_select_mf(card, NULL);
  431|    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: 15, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  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|    190|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 175]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  432|       |
  433|    175|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  434|    175|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  435|       |
  436|    175|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    175|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    175|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    175|	int _ret = r; \
  |  |  |  |  155|    175|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 175, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    175|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  157|    175|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    175|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    175|	return _ret; \
  |  |  |  |  163|    175|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  437|    175|}
card-authentic.c:authentic_select_mf:
  544|    190|{
  545|    190|	struct sc_context *ctx = card->ctx;
  546|    190|	struct sc_path mfpath;
  547|    190|	int rv;
  548|       |
  549|    190|	struct sc_apdu apdu;
  550|    190|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  551|       |
  552|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  553|       |
  554|    190|	sc_format_path("3F00", &mfpath);
  555|    190|	mfpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|    190|#define SC_PATH_TYPE_PATH		2
  ------------------
  556|       |
  557|    190|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  292|    190|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  558|       |
  559|    190|	apdu.resp = rbuf;
  560|    190|	apdu.resplen = sizeof(rbuf);
  561|       |
  562|    190|	rv = sc_transmit_apdu(card, &apdu);
  563|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  564|    188|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  565|    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: 6, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  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|    188|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 182]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  566|       |
  567|    182|	rv = authentic_set_current_files(card, &mfpath, apdu.resp, apdu.resplen, file_out);
  568|    182|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  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: 7, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  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|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 175]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|       |
  570|    175|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    175|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    175|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    175|	int _ret = r; \
  |  |  |  |  155|    175|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 175, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    175|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 175]
  |  |  |  |  ------------------
  |  |  |  |  157|    175|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    175|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    175|	return _ret; \
  |  |  |  |  163|    175|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  571|    175|}
card-authentic.c:authentic_set_current_files:
  505|    870|{
  506|    870|	struct sc_context *ctx = card->ctx;
  507|    870|	struct sc_file *file = NULL;
  508|    870|	int rv;
  509|       |
  510|    870|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    870|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    870|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    870|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    870|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 870]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  511|    870|	if (resplen)   {
  ------------------
  |  Branch (511:6): [True: 343, False: 527]
  ------------------
  512|    343|		switch (resp[0]) {
  513|     73|		case 0x62:
  ------------------
  |  Branch (513:3): [True: 73, False: 270]
  ------------------
  514|    214|		case 0x6F:
  ------------------
  |  Branch (514:3): [True: 141, False: 202]
  ------------------
  515|    214|			file = sc_file_new();
  516|    214|			if (file == NULL)
  ------------------
  |  Branch (516:8): [True: 0, False: 214]
  ------------------
  517|    214|				LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  518|    214|			if (path)
  ------------------
  |  Branch (518:8): [True: 214, False: 0]
  ------------------
  519|    214|				file->path = *path;
  520|       |
  521|    214|			rv = authentic_process_fci(card, file, resp, resplen);
  522|    214|			if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    214|#define SC_SUCCESS				0
  ------------------
  |  Branch (522:8): [True: 27, False: 187]
  ------------------
  523|     27|				sc_file_free(file);
  524|     27|				LOG_TEST_RET(ctx, rv, "cannot set 'current file': FCI process error");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  525|     27|			}
  526|       |
  527|    187|			break;
  528|    187|		default:
  ------------------
  |  Branch (528:3): [True: 129, False: 214]
  ------------------
  529|    129|			LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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: 129, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    129|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    129|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    129|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    129|	return _ret; \
  |  |  |  |  163|    129|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  530|    343|		}
  531|       |
  532|    187|		if (file_out)
  ------------------
  |  Branch (532:7): [True: 62, False: 125]
  ------------------
  533|     62|			*file_out = file;
  534|    125|		else
  535|    125|			sc_file_free(file);
  536|    187|	}
  537|       |
  538|    714|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    714|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    714|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    714|	int _ret = r; \
  |  |  |  |  155|    714|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 714, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    714|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 714]
  |  |  |  |  ------------------
  |  |  |  |  157|    714|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    714|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    714|	return _ret; \
  |  |  |  |  163|    714|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    714|}
card-authentic.c:authentic_get_serialnr:
 1485|    327|{
 1486|    327|	struct sc_context *ctx = card->ctx;
 1487|    327|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1488|    327|	int rv;
 1489|       |
 1490|    327|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    327|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    327|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    327|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    327|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 327]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1491|    327|	if (!card->serialnr.len)   {
  ------------------
  |  Branch (1491:6): [True: 251, False: 76]
  ------------------
 1492|    251|		rv = authentic_get_cplc(card);
 1493|    251|		LOG_TEST_RET(ctx, rv, "get CPLC data error");
  ------------------
  |  |  174|    251|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    251|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    251|	int _ret = (r); \
  |  |  |  |  168|    251|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 118, False: 133]
  |  |  |  |  ------------------
  |  |  |  |  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|    251|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 133]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1494|       |
 1495|    133|		card->serialnr.len = 4;
 1496|    133|		memcpy(card->serialnr.value, prv_data->cplc.value + 15, 4);
 1497|       |
 1498|    133|		sc_log(ctx, "serial %02X%02X%02X%02X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1499|    133|				card->serialnr.value[0], card->serialnr.value[1],
 1500|    133|				card->serialnr.value[2], card->serialnr.value[3]);
 1501|    133|	}
 1502|       |
 1503|    209|	if (serial)
  ------------------
  |  Branch (1503:6): [True: 97, False: 112]
  ------------------
 1504|     97|		memcpy(serial, &card->serialnr, sizeof(*serial));
 1505|       |
 1506|    209|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    209|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    209|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    209|	int _ret = r; \
  |  |  |  |  155|    209|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 209, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    209|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 209]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1507|    209|}
card-authentic.c:authentic_get_cplc:
  360|    251|{
  361|    251|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
  362|    251|	struct sc_apdu apdu;
  363|    251|	int rv, ii;
  364|    251|	unsigned char p1, p2;
  365|       |
  366|    251|	p1 = (SC_CPLC_TAG >> 8) & 0xFF;
  ------------------
  |  |  345|    251|#define SC_CPLC_TAG		0x9F7F
  ------------------
  367|    251|	p2 = SC_CPLC_TAG & 0xFF;
  ------------------
  |  |  345|    251|#define SC_CPLC_TAG		0x9F7F
  ------------------
  368|    251|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, p1, p2);
  ------------------
  |  |  292|    251|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  369|    254|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (369:12): [True: 253, False: 1]
  ------------------
  370|    253|		apdu.le = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    253|#define SC_CPLC_DER_SIZE	45
  ------------------
  371|    253|		apdu.resplen = sizeof(prv_data->cplc.value);
  372|    253|		apdu.resp = prv_data->cplc.value;
  373|       |
  374|    253|		rv = sc_transmit_apdu(card, &apdu);
  375|    253|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    253|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    253|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    253|	int _ret = (r); \
  |  |  |  |  168|    253|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 249]
  |  |  |  |  ------------------
  |  |  |  |  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|    253|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 249]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    249|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  377|    249|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    249|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (377:7): [True: 246, False: 3]
  ------------------
  378|    246|			break;
  379|       |
  380|      3|		apdu.cla = 0x80;
  381|      3|	}
  382|    247|        LOG_TEST_RET(card->ctx, rv, "'GET CPLC' error");
  ------------------
  |  |  174|    247|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    247|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    247|	int _ret = (r); \
  |  |  |  |  168|    247|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 114, False: 133]
  |  |  |  |  ------------------
  |  |  |  |  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|    247|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 133]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  383|       |
  384|    133|	prv_data->cplc.len = SC_CPLC_DER_SIZE;
  ------------------
  |  |  346|    133|#define SC_CPLC_DER_SIZE	45
  ------------------
  385|    133|	return SC_SUCCESS;
  ------------------
  |  |   28|    133|#define SC_SUCCESS				0
  ------------------
  386|    247|}
card-authentic.c:authentic_finish:
 1874|    287|{
 1875|    287|	struct sc_context *ctx = card->ctx;
 1876|       |
 1877|    287|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    287|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    287|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    287|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    287|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 287]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1878|       |
 1879|    287|#ifdef ENABLE_SM
 1880|    287|	if (card->sm_ctx.ops.close)
  ------------------
  |  Branch (1880:6): [True: 0, False: 287]
  ------------------
 1881|      0|		card->sm_ctx.ops.close(card);
 1882|    287|#endif
 1883|       |
 1884|    287|	if (card->drv_data)
  ------------------
  |  Branch (1884:6): [True: 287, False: 0]
  ------------------
 1885|    287|		free(card->drv_data);
 1886|    287|	card->drv_data = NULL;
 1887|    287|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    287|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    287|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    287|	int _ret = r; \
  |  |  |  |  155|    287|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 287, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    287|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 287]
  |  |  |  |  ------------------
  |  |  |  |  157|    287|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    287|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    287|	return _ret; \
  |  |  |  |  163|    287|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1888|    287|}
card-authentic.c:authentic_read_binary:
  643|    101|{
  644|    101|	struct sc_context *ctx = card->ctx;
  645|    101|	struct sc_apdu apdu;
  646|    101|	size_t sz, rest, ret_count = 0;
  647|    101|	int rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|    101|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  648|       |
  649|    101|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    101|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    101|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    101|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    101|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 101]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|    101|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  651|    101|	       "offs:%i,count:%"SC_FORMAT_LEN_SIZE_T"u,max_recv_size:%"SC_FORMAT_LEN_SIZE_T"u",
  652|    101|	       idx, count, card->max_recv_size);
  653|       |
  654|    101|	rest = count;
  655|  1.23k|	while(rest)   {
  ------------------
  |  Branch (655:8): [True: 1.13k, False: 100]
  ------------------
  656|  1.13k|		sz = rest > 256 ? 256 : rest;
  ------------------
  |  Branch (656:8): [True: 1.03k, False: 101]
  ------------------
  657|  1.13k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  292|  1.13k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  658|  1.13k|		apdu.le = sz;
  659|  1.13k|		apdu.resplen = sz;
  660|  1.13k|		apdu.resp = (buf + ret_count);
  661|       |
  662|  1.13k|		rv = sc_transmit_apdu(card, &apdu);
  663|  1.13k|		if(!rv)
  ------------------
  |  Branch (663:6): [True: 1.13k, False: 1]
  ------------------
  664|  1.13k|			ret_count += apdu.resplen;
  665|      1|		else
  666|      1|			break;
  667|       |
  668|  1.13k|		idx += sz;
  669|  1.13k|		rest -= sz;
  670|  1.13k|	}
  671|       |
  672|    101|	if (rv)   {
  ------------------
  |  Branch (672:6): [True: 1, False: 100]
  ------------------
  673|      1|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "authentic_read_binary() 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  674|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  675|      0|	}
  676|       |
  677|    100|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  678|    100|	if (!rv)
  ------------------
  |  Branch (678:6): [True: 71, False: 29]
  ------------------
  679|     71|		count = ret_count;
  680|       |
  681|    100|	LOG_TEST_RET(ctx, rv, "authentic_read_binary() failed");
  ------------------
  |  |  174|    100|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    100|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    100|	int _ret = (r); \
  |  |  |  |  168|    100|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 29, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  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|    100|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  682|     71|	LOG_FUNC_RETURN(ctx, (int)count);
  ------------------
  |  |  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: 3, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  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|     68|	} 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|     71|	return _ret; \
  |  |  |  |  163|     71|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  683|     71|}
card-authentic.c:authentic_select_file:
  576|  1.84k|{
  577|  1.84k|	struct sc_context *ctx = card->ctx;
  578|  1.84k|	struct sc_apdu apdu;
  579|  1.84k|	struct sc_path lpath;
  580|  1.84k|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  581|  1.84k|	size_t pathlen;
  582|  1.84k|	int rv;
  583|       |
  584|  1.84k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.84k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.84k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.84k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.84k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.84k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  585|       |
  586|  1.84k|	memcpy(&lpath, path, sizeof(struct sc_path));
  587|       |
  588|  1.84k|	if (lpath.type == SC_PATH_TYPE_PATH && (lpath.len == 2))
  ------------------
  |  |  119|  3.68k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (588:6): [True: 1.11k, False: 731]
  |  Branch (588:41): [True: 252, False: 860]
  ------------------
  589|    252|		lpath.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    252|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  590|       |
  591|  1.84k|	pathlen = lpath.len;
  592|  1.84k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  1.84k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  593|       |
  594|  1.84k|	if (card->type != SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)
  ------------------
  |  Branch (594:6): [True: 0, False: 1.84k]
  ------------------
  595|  1.84k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  596|       |
  597|  1.84k|	if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  1.84k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (597:6): [True: 252, False: 1.59k]
  ------------------
  598|    252|		apdu.p1 = 0x00;
  599|    252|	}
  600|  1.59k|	else if (lpath.type == SC_PATH_TYPE_PATH)  {
  ------------------
  |  |  119|  1.59k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (600:11): [True: 860, False: 731]
  ------------------
  601|    860|		apdu.p1 = 0x08;
  602|    860|	}
  603|    731|	else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|    731|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (603:11): [True: 0, False: 731]
  ------------------
  604|      0|		apdu.p1 = 0x09;
  605|      0|	}
  606|    731|	else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|    731|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (606:11): [True: 731, False: 0]
  ------------------
  607|    731|		apdu.p1 = 4;
  608|    731|	}
  609|      0|	else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|      0|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (609:11): [True: 0, False: 0]
  ------------------
  610|      0|		apdu.p1 = 0x03;
  611|      0|		pathlen = 0;
  612|      0|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  613|      0|	}
  614|      0|	else   {
  615|      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__
  |  |  ------------------
  ------------------
  616|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  617|      0|	}
  618|       |
  619|  1.84k|	apdu.lc = pathlen;
  620|  1.84k|	apdu.data = lpath.value;
  621|  1.84k|	apdu.datalen = pathlen;
  622|       |
  623|  1.84k|	if (apdu.cse == SC_APDU_CASE_4_SHORT || apdu.cse == SC_APDU_CASE_2_SHORT)   {
  ------------------
  |  |  294|  3.68k|#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 (623:6): [True: 1.84k, False: 0]
  |  Branch (623:42): [True: 0, False: 0]
  ------------------
  624|  1.84k|		apdu.resp = rbuf;
  625|  1.84k|		apdu.resplen = sizeof(rbuf);
  626|  1.84k|		apdu.le = 256;
  627|  1.84k|	}
  628|       |
  629|  1.84k|	rv = sc_transmit_apdu(card, &apdu);
  630|  1.84k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.84k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.84k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.84k|	int _ret = (r); \
  |  |  |  |  168|  1.84k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 1.82k]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|  1.84k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.82k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  631|  1.82k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  632|  1.82k|	LOG_TEST_RET(ctx, rv, "authentic_select_file() check SW failed");
  ------------------
  |  |  174|  1.82k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.82k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.82k|	int _ret = (r); \
  |  |  |  |  168|  1.82k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.13k, False: 688]
  |  |  |  |  ------------------
  |  |  |  |  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|  1.82k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 688]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  633|       |
  634|    688|	rv = authentic_set_current_files(card, &lpath, apdu.resp, apdu.resplen, file_out);
  635|    688|	LOG_TEST_RET(ctx, rv, "authentic_select_file() cannot set 'current_file'");
  ------------------
  |  |  174|    688|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    688|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    688|	int _ret = (r); \
  |  |  |  |  168|    688|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 149, False: 539]
  |  |  |  |  ------------------
  |  |  |  |  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|    688|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 539]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|    539|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    539|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    539|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    539|	int _ret = r; \
  |  |  |  |  155|    539|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 539, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    539|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 539]
  |  |  |  |  ------------------
  |  |  |  |  157|    539|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    539|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    539|	return _ret; \
  |  |  |  |  163|    539|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|    539|}
card-authentic.c:authentic_set_security_env:
 1790|    402|{
 1791|    402|	struct sc_context *ctx = card->ctx;
 1792|    402|	struct sc_apdu apdu;
 1793|    402|	unsigned char cse_crt_dst[] = {
 1794|    402|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|    402|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1795|    402|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|    402|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1796|    402|	};
 1797|    402|	unsigned char cse_crt_ct[] = {
 1798|    402|		0x80, 0x01, AUTHENTIC_ALGORITHM_RSA_PKCS1,
  ------------------
  |  |  101|    402|#define AUTHENTIC_ALGORITHM_RSA_PKCS1	0x11
  ------------------
 1799|    402|		0x83, 0x01, env->key_ref[0] & ~AUTHENTIC_OBJECT_REF_FLAG_LOCAL,
  ------------------
  |  |   49|    402|#define AUTHENTIC_OBJECT_REF_FLAG_LOCAL	0x80
  ------------------
 1800|    402|	};
 1801|    402|	int rv;
 1802|       |
 1803|    402|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    402|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    402|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    402|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    402|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 402]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1804|    402|	sc_log(ctx, "set SE#%i(op:0x%X,algo:0x%lX,algo_ref:0x%lX,flags:0x%lX), key_ref:0x%X",
  ------------------
  |  |   71|    402|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1805|    402|			se_num, env->operation, env->algorithm, env->algorithm_ref, env->algorithm_flags, env->key_ref[0]);
 1806|    402|	switch (env->operation)  {
 1807|    340|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|    340|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1807:2): [True: 340, False: 62]
  ------------------
 1808|    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
  ------------------
 1809|    340|		apdu.data = cse_crt_dst;
 1810|    340|		apdu.datalen = sizeof(cse_crt_dst);
 1811|    340|		apdu.lc = sizeof(cse_crt_dst);
 1812|    340|		break;
 1813|     62|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|     62|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1813:2): [True: 62, False: 340]
  ------------------
 1814|     62|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  293|     62|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, AUTHENTIC_TAG_CRT_CT);
  ------------------
  |  |  110|     62|#define AUTHENTIC_TAG_CRT_CT	0xB8
  ------------------
 1815|     62|		apdu.data = cse_crt_ct;
 1816|     62|		apdu.datalen = sizeof(cse_crt_ct);
 1817|     62|		apdu.lc = sizeof(cse_crt_ct);
 1818|     62|		break;
 1819|      0|	default:
  ------------------
  |  Branch (1819:2): [True: 0, False: 402]
  ------------------
 1820|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1821|    402|	}
 1822|       |
 1823|    402|	rv = sc_transmit_apdu(card, &apdu);
 1824|    402|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    402|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    402|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    402|	int _ret = (r); \
  |  |  |  |  168|    402|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 384]
  |  |  |  |  ------------------
  |  |  |  |  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|    402|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 384]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1825|    384|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1826|    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: 223, False: 161]
  |  |  |  |  ------------------
  |  |  |  |  169|    223|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    223|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    223|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    223|		return _ret; \
  |  |  |  |  172|    223|	} \
  |  |  |  |  173|    384|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 161]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1827|       |
 1828|    161|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1829|    161|}
card-authentic.c:authentic_decipher:
 1835|     32|{
 1836|     32|	struct sc_context *ctx = card->ctx;
 1837|     32|	struct sc_apdu apdu;
 1838|     32|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1839|     32|	int rv;
 1840|       |
 1841|     32|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     32|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     32|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     32|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     32|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1842|     32|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1843|     32|	       "crgram_len %"SC_FORMAT_LEN_SIZE_T"u;  outlen %"SC_FORMAT_LEN_SIZE_T"u",
 1844|     32|	       in_len, out_len);
 1845|     32|	if (!out || !out_len || in_len > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|     32|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1845:6): [True: 0, False: 32]
  |  Branch (1845:14): [True: 0, False: 32]
  |  Branch (1845:26): [True: 5, False: 27]
  ------------------
 1846|     32|		LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1847|       |
 1848|     27|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     27|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1849|     27|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     27|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1850|     27|	apdu.data = in;
 1851|     27|	apdu.datalen = in_len;
 1852|     27|	apdu.lc = in_len;
 1853|     27|	apdu.resp = resp;
 1854|     27|	apdu.resplen = sizeof(resp);
 1855|     27|	apdu.le = 256;
 1856|       |
 1857|     27|	rv = sc_transmit_apdu(card, &apdu);
 1858|     27|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  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: 8, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 19]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1859|     19|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1860|     19|	LOG_TEST_RET(ctx, rv, "Card returned error");
  ------------------
  |  |  174|     19|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     19|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     19|	int _ret = (r); \
  |  |  |  |  168|     19|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     19|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1861|       |
 1862|     13|	if (out_len > apdu.resplen)
  ------------------
  |  Branch (1862:6): [True: 13, False: 0]
  ------------------
 1863|     13|		out_len = apdu.resplen;
 1864|       |
 1865|     13|	memcpy(out, apdu.resp, out_len);
 1866|     13|	rv = (int)out_len;
 1867|       |
 1868|     13|	LOG_FUNC_RETURN(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: 8, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|      5|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      5|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      5|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1869|     13|}
card-authentic.c:authentic_card_ctl:
 1763|    172|{
 1764|    172|	struct sc_context *ctx = card->ctx;
 1765|    172|	struct sc_authentic_sdo *sdo = (struct sc_authentic_sdo *) ptr;
 1766|       |
 1767|    172|	switch (cmd) {
  ------------------
  |  Branch (1767:10): [True: 172, False: 0]
  ------------------
 1768|    172|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1768:2): [True: 172, False: 0]
  ------------------
 1769|    172|		return authentic_get_serialnr(card, (struct sc_serial_number *)ptr);
 1770|      0|	case SC_CARDCTL_AUTHENTIC_SDO_CREATE:
  ------------------
  |  Branch (1770:2): [True: 0, False: 172]
  ------------------
 1771|      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__
  |  |  ------------------
  ------------------
 1772|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1773|      0|	case SC_CARDCTL_AUTHENTIC_SDO_DELETE:
  ------------------
  |  Branch (1773:2): [True: 0, False: 172]
  ------------------
 1774|      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__
  |  |  ------------------
  ------------------
 1775|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1776|      0|	case SC_CARDCTL_AUTHENTIC_SDO_STORE:
  ------------------
  |  Branch (1776:2): [True: 0, False: 172]
  ------------------
 1777|      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__
  |  |  ------------------
  ------------------
 1778|      0|		return authentic_manage_sdo(card, (struct sc_authentic_sdo *) ptr, cmd);
 1779|      0|	case SC_CARDCTL_AUTHENTIC_SDO_GENERATE:
  ------------------
  |  Branch (1779:2): [True: 0, False: 172]
  ------------------
 1780|      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__
  |  |  ------------------
  ------------------
 1781|      0|		return authentic_manage_sdo_generate(card, (struct sc_authentic_sdo *) ptr);
 1782|    172|	}
 1783|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1784|    172|}
card-authentic.c:authentic_get_tagged_data:
  177|    674|{
  178|    674|	size_t size_len, tag_len, offs, size;
  179|    674|	int rv;
  180|    674|	unsigned tag;
  181|       |
  182|    674|	if (!out || !out_len)
  ------------------
  |  Branch (182:6): [True: 0, False: 674]
  |  Branch (182:14): [True: 0, False: 674]
  ------------------
  183|    674|		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|  6.32k|	for (offs = 0; offs < in_len; )   {
  ------------------
  |  Branch (185:17): [True: 6.19k, False: 122]
  ------------------
  186|  6.19k|		if ((*(in + offs) == 0x7F) || (*(in + offs) == 0x5F))   {
  ------------------
  |  Branch (186:7): [True: 1.24k, False: 4.95k]
  |  Branch (186:33): [True: 208, False: 4.74k]
  ------------------
  187|  1.45k|			if (offs + 1 >= in_len)
  ------------------
  |  Branch (187:8): [True: 4, False: 1.45k]
  ------------------
  188|  1.45k|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      4|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      4|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      4|	int _ret = (r); \
  |  |  |  |  168|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|  1.45k|			tag = *(in + offs) * 0x100 + *(in + offs + 1);
  190|  1.45k|			tag_len = 2;
  191|  1.45k|		}
  192|  4.74k|		else   {
  193|  4.74k|			tag = *(in + offs);
  194|  4.74k|			tag_len = 1;
  195|  4.74k|		}
  196|       |
  197|  6.19k|		if (offs + tag_len >= in_len)
  ------------------
  |  Branch (197:7): [True: 33, False: 6.16k]
  ------------------
  198|  6.19k|			LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|     33|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     33|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     33|	int _ret = (r); \
  |  |  |  |  168|     33|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 33, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     33|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     33|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     33|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     33|		return _ret; \
  |  |  |  |  172|     33|	} \
  |  |  |  |  173|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|       |
  200|  6.16k|		rv = authentic_parse_size(in + offs + tag_len, in_len - (offs + tag_len), &size);
  201|  6.16k|		LOG_TEST_RET(ctx, rv, "parse error: invalid size data");
  ------------------
  |  |  174|  6.16k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.16k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.16k|	int _ret = (r); \
  |  |  |  |  168|  6.16k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 69, False: 6.09k]
  |  |  |  |  ------------------
  |  |  |  |  169|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     69|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     69|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     69|		return _ret; \
  |  |  |  |  172|     69|	} \
  |  |  |  |  173|  6.16k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.09k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  202|  6.09k|		size_len = rv;
  203|       |
  204|  6.09k|		if (tag == in_tag)   {
  ------------------
  |  Branch (204:7): [True: 446, False: 5.64k]
  ------------------
  205|    446|			if (in_len - (offs + tag_len + size_len) < size)
  ------------------
  |  Branch (205:8): [True: 7, False: 439]
  ------------------
  206|    446|				LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "parse error: invalid data");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      7|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      7|		return _ret; \
  |  |  |  |  172|      7|	} \
  |  |  |  |  173|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  207|       |
  208|    439|			*out = in + offs + tag_len + size_len;
  209|    439|			*out_len = size;
  210|       |
  211|    439|			return SC_SUCCESS;
  ------------------
  |  |   28|    439|#define SC_SUCCESS				0
  ------------------
  212|    446|		}
  213|       |
  214|  5.64k|		offs += tag_len + size_len + size;
  215|  5.64k|	}
  216|       |
  217|    122|	return SC_ERROR_ASN1_OBJECT_NOT_FOUND;
  ------------------
  |  |   83|    122|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
  218|    674|}
card-authentic.c:authentic_parse_size:
  149|  6.16k|{
  150|  6.16k|	if (!in || !out || in_len < 1)
  ------------------
  |  Branch (150:6): [True: 0, False: 6.16k]
  |  Branch (150:13): [True: 0, False: 6.16k]
  |  Branch (150:21): [True: 0, False: 6.16k]
  ------------------
  151|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  152|       |
  153|  6.16k|	if (*in < 0x80)   {
  ------------------
  |  Branch (153:6): [True: 4.50k, False: 1.65k]
  ------------------
  154|  4.50k|		*out = *in;
  155|  4.50k|		return 1;
  156|  4.50k|	}
  157|  1.65k|	else if (*in == 0x81)   {
  ------------------
  |  Branch (157:11): [True: 1.52k, False: 139]
  ------------------
  158|  1.52k|		if (in_len < 2)
  ------------------
  |  Branch (158:7): [True: 1, False: 1.51k]
  ------------------
  159|      1|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      1|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  160|  1.51k|		*out = *(in + 1);
  161|  1.51k|		return 2;
  162|  1.52k|	}
  163|    139|	else if (*in == 0x82)   {
  ------------------
  |  Branch (163:11): [True: 74, False: 65]
  ------------------
  164|     74|		if (in_len < 3)
  ------------------
  |  Branch (164:7): [True: 3, False: 71]
  ------------------
  165|      3|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  166|     71|		*out = *(in + 1) * 0x100 + *(in + 2);
  167|     71|		return 3;
  168|     74|	}
  169|       |
  170|     65|	return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     65|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  171|  6.16k|}
card-authentic.c:authentic_process_fci:
  775|    214|{
  776|    214|	struct sc_context *ctx = card->ctx;
  777|    214|	size_t taglen;
  778|    214|	int rv;
  779|    214|	unsigned ii;
  780|    214|	const unsigned char *tag = NULL;
  781|    214|	unsigned char ops_DF[8] = {
  782|    214|		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  169|    214|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  168|    214|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_CREATE, SC_AC_OP_DELETE, SC_AC_OP_CRYPTO, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  173|    214|#define SC_AC_OP_CRYPTO			7
  ------------------
  783|    214|	};
  784|    214|	unsigned char ops_EF[8] = {
  785|    214|		SC_AC_OP_READ, SC_AC_OP_DELETE, SC_AC_OP_UPDATE, SC_AC_OP_RESIZE, 0xFF, 0xFF, 0xFF, 0xFF
  ------------------
  |  |  188|    214|#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|    214|#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|    214|#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|    214|#define SC_AC_OP_RESIZE			25
  ------------------
  786|    214|	};
  787|       |
  788|    214|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    214|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    214|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    214|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    214|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 214]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  789|       |
  790|    214|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x6F, &taglen);
  791|    214|	if (tag != NULL) {
  ------------------
  |  Branch (791:6): [True: 136, False: 78]
  ------------------
  792|    136|		sc_log(ctx, "  FCP length %"SC_FORMAT_LEN_SIZE_T"u", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  793|    136|		buf = tag;
  794|    136|		buflen = taglen;
  795|    136|	}
  796|       |
  797|    214|	tag = sc_asn1_find_tag(card->ctx,  buf, buflen, 0x62, &taglen);
  798|    214|	if (tag != NULL) {
  ------------------
  |  Branch (798:6): [True: 59, False: 155]
  ------------------
  799|     59|		sc_log(ctx, "  FCP length %"SC_FORMAT_LEN_SIZE_T"u", taglen);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  800|     59|		buf = tag;
  801|     59|		buflen = taglen;
  802|     59|	}
  803|       |
  804|    214|	rv = iso_ops->process_fci(card, file, buf, buflen);
  805|    214|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  174|    214|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    214|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    214|	int _ret = (r); \
  |  |  |  |  168|    214|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 214]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    214|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 214]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  806|       |
  807|    214|	if (!file->sec_attr_len)   {
  ------------------
  |  Branch (807:6): [True: 81, False: 133]
  ------------------
  808|     81|		sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
  ------------------
  |  |  129|     81|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     81|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  809|     81|		sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  810|     81|		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  118|    162|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              		if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|     75|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (810:7): [True: 6, False: 75]
  |  Branch (810:50): [True: 48, False: 27]
  ------------------
  811|     54|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     54|#define SC_FILE_TYPE_DF			0x04
  ------------------
  812|     54|		}
  813|     27|		else   {
  814|     27|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|     27|		}
  816|     81|	}
  817|       |
  818|    187|	sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
  ------------------
  |  |  129|    187|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    187|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  819|    725|	for (ii = 0; ii < file->sec_attr_len / 2 && ii < sizeof ops_DF; ii++)  {
  ------------------
  |  Branch (819:15): [True: 538, False: 187]
  |  Branch (819:46): [True: 538, False: 0]
  ------------------
  820|    538|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|    538|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (820:22): [True: 67, False: 471]
  ------------------
  821|    538|		unsigned char acl = *(file->sec_attr + ii*2);
  822|    538|		unsigned char cred_id = *(file->sec_attr + ii*2 + 1);
  823|    538|		unsigned sc = acl * 0x100 + cred_id;
  824|       |
  825|    538|		sc_log(ctx, "ACL(%i) op 0x%X, acl %X:%X", ii, op, acl, cred_id);
  ------------------
  |  |   71|    538|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  826|    538|		if (op == 0xFF)
  ------------------
  |  Branch (826:7): [True: 100, False: 438]
  ------------------
  827|    100|			;
  828|    438|		else if (!acl && !cred_id)
  ------------------
  |  Branch (828:12): [True: 99, False: 339]
  |  Branch (828:20): [True: 55, False: 44]
  ------------------
  829|     55|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|     55|#define SC_AC_NONE			0x00000000
  ------------------
  830|    383|		else if (acl == 0xFF)
  ------------------
  |  Branch (830:12): [True: 66, False: 317]
  ------------------
  831|     66|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     66|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  832|    317|		else if (acl & AUTHENTIC_AC_SM_MASK)
  ------------------
  |  |  119|    317|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (832:12): [True: 148, False: 169]
  ------------------
  833|    148|			sc_file_add_acl_entry(file, op, SC_AC_SCB, sc);
  ------------------
  |  |  157|    148|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  834|    169|		else if (cred_id)
  ------------------
  |  Branch (834:12): [True: 137, False: 32]
  ------------------
  835|    137|			sc_file_add_acl_entry(file, op, SC_AC_CHV, cred_id);
  ------------------
  |  |  151|    137|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  836|     32|		else
  837|     32|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|     32|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  838|    538|	}
  839|       |
  840|    187|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    187|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 187]
  |  |  |  |  ------------------
  |  |  |  |  157|    187|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    187|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    187|	return _ret; \
  |  |  |  |  163|    187|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  841|    187|}
card-authentic.c:authentic_pin_cmd:
 1450|    465|{
 1451|    465|	struct sc_context *ctx = card->ctx;
 1452|    465|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    465|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1453|       |
 1454|    465|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    465|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    465|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    465|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    465|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 465]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1455|    465|	sc_log(ctx, "PIN-CMD:%X,PIN(type:%X,ret:%i)", data->cmd, data->pin_type, data->pin_reference);
  ------------------
  |  |   71|    465|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1456|    465|	sc_log(ctx, "PIN1(%p,len:%zu,tries-left:%i)", data->pin1.data, data->pin1.len, data->pin1.tries_left);
  ------------------
  |  |   71|    465|#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|    465|	sc_log(ctx, "PIN2(%p,len:%zu)", data->pin2.data, data->pin2.len);
  ------------------
  |  |   71|    465|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1458|       |
 1459|    465|	switch (data->cmd)   {
 1460|     47|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|     47|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1460:2): [True: 47, False: 418]
  ------------------
 1461|     47|		rv = authentic_pin_verify(card, data);
 1462|     47|		break;
 1463|     34|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|     34|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1463:2): [True: 34, False: 431]
  ------------------
 1464|     34|		rv = authentic_pin_change(card, data, tries_left);
 1465|     34|		break;
 1466|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1466:2): [True: 0, False: 465]
  ------------------
 1467|      0|		rv = authentic_pin_reset(card, data, tries_left);
 1468|      0|		break;
 1469|    384|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|    384|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1469:2): [True: 384, False: 81]
  ------------------
 1470|    384|		rv = authentic_pin_get_policy(card, data, NULL);
 1471|    384|		break;
 1472|      0|	default:
  ------------------
  |  Branch (1472:2): [True: 0, False: 465]
  ------------------
 1473|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1474|    465|	}
 1475|       |
 1476|    465|	if (rv == SC_ERROR_PIN_CODE_INCORRECT && tries_left)
  ------------------
  |  |   64|    930|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1476:6): [True: 10, False: 455]
  |  Branch (1476:43): [True: 4, False: 6]
  ------------------
 1477|      4|		*tries_left = data->pin1.tries_left;
 1478|       |
 1479|    465|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    465|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    465|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    465|	int _ret = r; \
  |  |  |  |  155|    465|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 465, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    465|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    353|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 353, False: 112]
  |  |  |  |  ------------------
  |  |  |  |  157|    465|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    465|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    465|	return _ret; \
  |  |  |  |  163|    465|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1480|    465|}
card-authentic.c:authentic_pin_verify:
 1107|     47|{
 1108|     47|	struct sc_context *ctx = card->ctx;
 1109|     47|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1110|     47|	unsigned char pin_sha1[SHA_DIGEST_LENGTH];
 1111|     47|	int rv;
 1112|       |
 1113|     47|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     47|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     47|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     47|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     47|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1114|     47|	sc_log(ctx, "PIN(type:%X,reference:%X,data:%p,length:%zu)",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1115|     47|			pin_cmd->pin_type, pin_cmd->pin_reference, pin_cmd->pin1.data, pin_cmd->pin1.len);
 1116|       |
 1117|     47|	if (pin_cmd->pin_reference < 0 || pin_cmd->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|     47|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1117:6): [True: 0, False: 47]
  |  Branch (1117:36): [True: 0, False: 47]
  ------------------
 1118|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1119|      0|	}
 1120|       |
 1121|     47|	if (pin_cmd->pin1.data && !pin_cmd->pin1.len)   {
  ------------------
  |  Branch (1121:6): [True: 47, False: 0]
  |  Branch (1121:28): [True: 0, False: 47]
  ------------------
 1122|      0|		pin_cmd->pin1.tries_left = -1;
 1123|      0|		rv = authentic_pin_is_verified(card, pin_cmd, &pin_cmd->pin1.tries_left);
 1124|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1125|      0|	}
 1126|       |
 1127|     47|	if (pin_cmd->pin1.data)
  ------------------
  |  Branch (1127:6): [True: 47, False: 0]
  ------------------
 1128|     47|		SHA1(pin_cmd->pin1.data, pin_cmd->pin1.len, pin_sha1);
 1129|      0|	else
 1130|      0|		SHA1((unsigned char *)"", 0, pin_sha1);
 1131|       |
 1132|     47|	if (!memcmp(pin_sha1, prv_data->pins_sha1[pin_cmd->pin_reference], SHA_DIGEST_LENGTH))   {
  ------------------
  |  Branch (1132:6): [True: 0, False: 47]
  ------------------
 1133|      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__
  |  |  ------------------
  ------------------
 1134|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1135|      0|	}
 1136|       |
 1137|     47|	memset(prv_data->pins_sha1[pin_cmd->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1138|       |
 1139|     47|	rv = authentic_pin_get_policy(card, pin_cmd, NULL);
 1140|     47|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  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: 35, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  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|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|       |
 1142|     12|	if (pin_cmd->pin1.len > pin_cmd->pin1.max_length)
  ------------------
  |  Branch (1142:6): [True: 0, False: 12]
  ------------------
 1143|     12|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1144|       |
 1145|     12|	pin_cmd->pin1.tries_left = -1;
 1146|     12|	rv = authentic_chv_verify(card, pin_cmd, &pin_cmd->pin1.tries_left);
 1147|     12|	LOG_TEST_RET(ctx, rv, "PIN CHV verification 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: 9, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1148|       |
 1149|      3|	memcpy(prv_data->pins_sha1[pin_cmd->pin_reference], pin_sha1, SHA_DIGEST_LENGTH);
 1150|      3|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|      3|}
card-authentic.c:authentic_chv_verify:
 1021|     12|{
 1022|     12|	struct sc_context *ctx = card->ctx;
 1023|     12|	struct sc_apdu apdu;
 1024|     12|	struct sc_pin_cmd_pin *pin1 = &pin_cmd->pin1;
 1025|     12|	unsigned char pin_buff[SC_MAX_APDU_BUFFER_SIZE];
 1026|     12|	size_t pin_len;
 1027|     12|	int rv;
 1028|       |
 1029|     12|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1030|     12|	sc_log(ctx, "CHV PIN reference %i, pin1(%p,len:%zu)", pin_cmd->pin_reference, pin1->data, pin1->len);
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1031|       |
 1032|     12|	if (pin1->data && !pin1->len)   {
  ------------------
  |  Branch (1032:6): [True: 12, False: 0]
  |  Branch (1032:20): [True: 0, False: 12]
  ------------------
 1033|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1034|      0|	}
 1035|     12|	else if (pin1->data && pin1->len)   {
  ------------------
  |  Branch (1035:11): [True: 12, False: 0]
  |  Branch (1035:25): [True: 12, False: 0]
  ------------------
 1036|     12|		if (pin1->len > sizeof(pin_buff)) {
  ------------------
  |  Branch (1036:7): [True: 0, False: 12]
  ------------------
 1037|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1038|      0|		}
 1039|     12|		memcpy(pin_buff, pin1->data, pin1->len);
 1040|     12|		pin_len = pin1->len;
 1041|       |
 1042|     12|		if (pin1->pad_length && pin_cmd->flags & SC_PIN_CMD_NEED_PADDING)   {
  ------------------
  |  |  429|     12|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1042:7): [True: 12, False: 0]
  |  Branch (1042:27): [True: 12, False: 0]
  ------------------
 1043|     12|			if (pin1->len > pin1->pad_length || pin1->pad_length > sizeof(pin_buff)) {
  ------------------
  |  Branch (1043:8): [True: 0, False: 12]
  |  Branch (1043:40): [True: 0, False: 12]
  ------------------
 1044|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1045|      0|			}
 1046|     12|			if (pin1->len < sizeof(pin_buff)) {
  ------------------
  |  Branch (1046:8): [True: 12, False: 0]
  ------------------
 1047|     12|				memset(pin_buff + pin1->len, pin1->pad_char,
 1048|     12|						pin1->pad_length - pin1->len);
 1049|     12|			}
 1050|     12|			pin_len = pin1->pad_length;
 1051|     12|		}
 1052|       |
 1053|     12|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x20, 0, pin_cmd->pin_reference);
  ------------------
  |  |  293|     12|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1054|     12|		apdu.data = pin_buff;
 1055|     12|		apdu.datalen = pin_len;
 1056|     12|		apdu.lc = pin_len;
 1057|     12|	}
 1058|      0|	else if ((card->reader->capabilities & SC_READER_CAP_PIN_PAD) && !pin1->data && !pin1->len)   {
  ------------------
  |  |  383|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1058:11): [True: 0, False: 0]
  |  Branch (1058:67): [True: 0, False: 0]
  |  Branch (1058:82): [True: 0, False: 0]
  ------------------
 1059|      0|		rv = authentic_chv_verify_pinpad(card, pin_cmd, tries_left);
 1060|      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__
  |  |  ------------------
  ------------------
 1061|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1062|      0|	}
 1063|      0|	else   {
 1064|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1065|      0|	}
 1066|       |
 1067|     12|	rv = sc_transmit_apdu(card, &apdu);
 1068|     12|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1069|       |
 1070|     11|	if (apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)   {
  ------------------
  |  Branch (1070:6): [True: 2, False: 9]
  |  Branch (1070:26): [True: 1, False: 1]
  ------------------
 1071|      1|		pin1->tries_left = apdu.sw2 & 0x0F;
 1072|      1|		if (tries_left)
  ------------------
  |  Branch (1072:7): [True: 1, False: 0]
  ------------------
 1073|      1|			*tries_left = apdu.sw2 & 0x0F;
 1074|      1|	}
 1075|       |
 1076|     11|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1077|       |
 1078|     11|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8, False: 3]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1079|     11|}
card-authentic.c:authentic_pin_change:
 1206|     34|{
 1207|     34|	struct sc_context *ctx = card->ctx;
 1208|     34|	struct authentic_private_data *prv_data = (struct authentic_private_data *) card->drv_data;
 1209|     34|	struct sc_apdu apdu;
 1210|     34|	unsigned char pin_data[SC_MAX_APDU_BUFFER_SIZE];
 1211|     34|	size_t offs;
 1212|     34|	int rv;
 1213|       |
 1214|     34|	rv = authentic_pin_get_policy(card, data, NULL);
 1215|     34|	LOG_TEST_RET(ctx, rv, "Get 'PIN policy' error");
  ------------------
  |  |  174|     34|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     34|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     34|	int _ret = (r); \
  |  |  |  |  168|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 27, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1216|       |
 1217|      7|	if (data->pin_reference < 0 || data->pin_reference >= AUTHENTIC_N_PINS) {
  ------------------
  |  |   64|      7|#define AUTHENTIC_N_PINS 8
  ------------------
  |  Branch (1217:6): [True: 0, False: 7]
  |  Branch (1217:33): [True: 0, False: 7]
  ------------------
 1218|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1219|      0|	}
 1220|       |
 1221|      7|	memset(prv_data->pins_sha1[data->pin_reference], 0, sizeof(prv_data->pins_sha1[0]));
 1222|       |
 1223|      7|	if (!data->pin1.data && !data->pin1.len && !data->pin2.data && !data->pin2.len)   {
  ------------------
  |  Branch (1223:6): [True: 0, False: 7]
  |  Branch (1223:26): [True: 0, False: 0]
  |  Branch (1223:45): [True: 0, False: 0]
  |  Branch (1223:65): [True: 0, False: 0]
  ------------------
 1224|      0|		if (!(card->reader->capabilities & SC_READER_CAP_PIN_PAD))
  ------------------
  |  |  383|      0|#define SC_READER_CAP_PIN_PAD	0x00000002
  ------------------
  |  Branch (1224:7): [True: 0, False: 0]
  ------------------
 1225|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1226|      0|		rv = authentic_pin_change_pinpad(card, data->pin_reference, tries_left);
 1227|      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__
  |  |  ------------------
  ------------------
 1228|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1229|      0|	}
 1230|       |
 1231|      7|	if (card->max_send_size && (data->pin1.len + data->pin2.len > card->max_send_size))
  ------------------
  |  Branch (1231:6): [True: 7, False: 0]
  |  Branch (1231:29): [True: 0, False: 7]
  ------------------
 1232|      7|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1233|       |
 1234|      7|	memset(pin_data, data->pin1.pad_char, sizeof(pin_data));
 1235|      7|	offs = 0;
 1236|      7|	if (data->pin1.data && data->pin1.len)   {
  ------------------
  |  Branch (1236:6): [True: 7, False: 0]
  |  Branch (1236:25): [True: 7, False: 0]
  ------------------
 1237|      7|		if (data->pin1.len > sizeof(pin_data)) {
  ------------------
  |  Branch (1237:7): [True: 0, False: 7]
  ------------------
 1238|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1239|      0|		}
 1240|      7|		memcpy(pin_data, data->pin1.data, data->pin1.len);
 1241|      7|		offs += data->pin1.pad_length;
 1242|      7|	}
 1243|      7|	if (data->pin2.data && data->pin2.len) {
  ------------------
  |  Branch (1243:6): [True: 7, False: 0]
  |  Branch (1243:25): [True: 7, False: 0]
  ------------------
 1244|      7|		if (data->pin2.len + offs > sizeof(pin_data)) {
  ------------------
  |  Branch (1244:7): [True: 0, False: 7]
  ------------------
 1245|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1246|      0|		}
 1247|      7|		memcpy(pin_data + offs, data->pin2.data, data->pin2.len);
 1248|      7|	}
 1249|       |
 1250|      7|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, offs ? 0x00 : 0x01, data->pin_reference);
  ------------------
  |  |  293|      7|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1250:58): [True: 7, False: 0]
  ------------------
 1251|      7|	apdu.data = pin_data;
 1252|      7|	apdu.datalen = offs + data->pin1.pad_length;
 1253|      7|	apdu.lc = offs + data->pin1.pad_length;
 1254|       |
 1255|      7|	rv = sc_transmit_apdu(card, &apdu);
 1256|      7|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|      7|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      7|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      7|	int _ret = (r); \
  |  |  |  |  168|      7|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1257|      6|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1258|       |
 1259|      6|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      6|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      6|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      6|	int _ret = r; \
  |  |  |  |  155|      6|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1260|      6|}
card-authentic.c:authentic_pin_get_policy:
 1309|    465|{
 1310|    465|	struct sc_context *ctx = card->ctx;
 1311|    465|	struct sc_apdu apdu;
 1312|    465|	unsigned char rbuf[0x100];
 1313|    465|	int ii, rv;
 1314|       |
 1315|    465|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    465|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    465|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    465|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    465|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 465]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1316|    465|	sc_log(ctx, "get PIN(type:%X,ref:%X,tries-left:%i)", data->pin_type, data->pin_reference, data->pin1.tries_left);
  ------------------
  |  |   71|    465|#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|       |
 1318|    465|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x5F, data->pin_reference);
  ------------------
  |  |  292|    465|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1319|    468|	for (ii=0;ii<2;ii++)   {
  ------------------
  |  Branch (1319:12): [True: 467, False: 1]
  ------------------
 1320|    467|		apdu.le = sizeof(rbuf);
 1321|    467|		apdu.resp = rbuf;
 1322|    467|		apdu.resplen = sizeof(rbuf);
 1323|       |
 1324|    467|		rv = sc_transmit_apdu(card, &apdu);
 1325|    467|		LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    467|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    467|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    467|	int _ret = (r); \
  |  |  |  |  168|    467|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 449]
  |  |  |  |  ------------------
  |  |  |  |  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|    467|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 449]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1326|    449|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1327|       |
 1328|    449|		if (rv != SC_ERROR_CLASS_NOT_SUPPORTED)
  ------------------
  |  |   53|    449|#define SC_ERROR_CLASS_NOT_SUPPORTED		-1203
  ------------------
  |  Branch (1328:7): [True: 446, False: 3]
  ------------------
 1329|    446|			break;
 1330|       |
 1331|      3|		apdu.cla = 0x80;
 1332|      3|	}
 1333|    447|        LOG_TEST_RET(ctx, rv, "'GET DATA' error");
  ------------------
  |  |  174|    447|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    447|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    447|	int _ret = (r); \
  |  |  |  |  168|    447|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 202, False: 245]
  |  |  |  |  ------------------
  |  |  |  |  169|    202|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    202|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    202|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    202|		return _ret; \
  |  |  |  |  172|    202|	} \
  |  |  |  |  173|    447|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 245]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1334|       |
 1335|    245|	data->pin1.tries_left = -1;
 1336|       |
 1337|    245|	rv = authentic_parse_credential_data(ctx, data, acls, apdu.resp, apdu.resplen);
 1338|    245|        LOG_TEST_RET(ctx, rv, "Cannot parse credential data");
  ------------------
  |  |  174|    245|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    245|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    245|	int _ret = (r); \
  |  |  |  |  168|    245|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 118, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  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|    245|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 127]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1339|       |
 1340|    127|	data->pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|    127|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1341|    127|	data->pin1.offset = 5;
 1342|    127|	data->pin1.pad_char = 0xFF;
 1343|    127|	data->pin1.pad_length = data->pin1.max_length;
 1344|    127|	data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|    127|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 1345|       |
 1346|    127|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|    127|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1347|       |
 1348|    127|	sc_log(ctx,
  ------------------
  |  |   71|    127|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1349|    127|	       "PIN policy: size max/min/pad %"SC_FORMAT_LEN_SIZE_T"u/%"SC_FORMAT_LEN_SIZE_T"u/%"SC_FORMAT_LEN_SIZE_T"u, tries max/left %i/%i",
 1350|    127|	       data->pin1.max_length, data->pin1.min_length,
 1351|    127|	       data->pin1.pad_length, data->pin1.max_tries,
 1352|    127|	       data->pin1.tries_left);
 1353|       |
 1354|    127|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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: 127, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    127|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 127]
  |  |  |  |  ------------------
  |  |  |  |  157|    127|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    127|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    127|	return _ret; \
  |  |  |  |  163|    127|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1355|    127|}
card-authentic.c:authentic_parse_credential_data:
  286|    245|{
  287|    245|	unsigned char *data;
  288|    245|	size_t data_len;
  289|    245|	int rv, ii;
  290|    245|	unsigned tag = AUTHENTIC_TAG_CREDENTIAL | pin_cmd->pin_reference;
  ------------------
  |  |   94|    245|#define AUTHENTIC_TAG_CREDENTIAL			0x5F00
  ------------------
  291|       |
  292|    245|	rv = authentic_get_tagged_data(ctx, blob, blob_len, tag, &blob, &blob_len);
  293|    245|	LOG_TEST_RET(ctx, rv, "cannot get credential data");
  ------------------
  |  |  174|    245|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    245|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    245|	int _ret = (r); \
  |  |  |  |  168|    245|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 89, False: 156]
  |  |  |  |  ------------------
  |  |  |  |  169|     89|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     89|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     89|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     89|		return _ret; \
  |  |  |  |  172|     89|	} \
  |  |  |  |  173|    245|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 156]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  294|       |
  295|    156|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT, &data, &data_len);
  ------------------
  |  |   95|    156|#define AUTHENTIC_TAG_CREDENTIAL_TRYLIMIT		0x91
  ------------------
  296|    156|	LOG_TEST_RET(ctx, rv, "cannot get try limit");
  ------------------
  |  |  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: 12, False: 144]
  |  |  |  |  ------------------
  |  |  |  |  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|    156|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 144]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|    144|	pin_cmd->pin1.max_tries = *data;
  298|       |
  299|    144|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_DOCP_MECH, &data, &data_len);
  ------------------
  |  |   73|    144|#define AUTHENTIC_TAG_DOCP_MECH			0x80
  ------------------
  300|    144|	LOG_TEST_RET(ctx, rv, "cannot get PIN type");
  ------------------
  |  |  174|    144|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    144|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    144|	int _ret = (r); \
  |  |  |  |  168|    144|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  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|    144|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 138]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|    138|	if (data_len > 0 && *data == 0)
  ------------------
  |  Branch (301:6): [True: 134, False: 4]
  |  Branch (301:22): [True: 49, False: 85]
  ------------------
  302|     49|		pin_cmd->pin_type = SC_AC_CHV;
  ------------------
  |  |  151|     49|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  303|     89|	else if (data_len > 0 && *data >= 2 && *data <= 7)
  ------------------
  |  Branch (303:11): [True: 85, False: 4]
  |  Branch (303:27): [True: 84, False: 1]
  |  Branch (303:41): [True: 79, False: 5]
  ------------------
  304|     79|		pin_cmd->pin_type = SC_AC_AUT;
  ------------------
  |  |  154|     79|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  305|     10|	else
  306|     10|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unsupported Credential type");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  307|       |
  308|       |	/* Parse optional ACLs when requested */
  309|    128|	if (acls) {
  ------------------
  |  Branch (309:6): [True: 0, False: 128]
  ------------------
  310|      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
  ------------------
  311|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  312|      0|		sc_log(ctx, "data_len:%"SC_FORMAT_LEN_SIZE_T"u", 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__
  |  |  ------------------
  ------------------
  313|      0|		if (data_len == 10)   {
  ------------------
  |  Branch (313:7): [True: 0, False: 0]
  ------------------
  314|      0|			for (ii=0; ii<5; ii++)   {
  ------------------
  |  Branch (314:15): [True: 0, False: 0]
  ------------------
  315|      0|				unsigned char acl = *(data + ii*2);
  316|      0|				unsigned char cred_id = *(data + ii*2 + 1);
  317|      0|				unsigned sc = acl * 0x100 + cred_id;
  318|       |
  319|      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__
  |  |  ------------------
  ------------------
  320|      0|				if (!sc)
  ------------------
  |  Branch (320:9): [True: 0, False: 0]
  ------------------
  321|      0|					continue;
  322|       |
  323|      0|				if (acl & AUTHENTIC_AC_SM_MASK)   {
  ------------------
  |  |  119|      0|#define AUTHENTIC_AC_SM_MASK	0x60
  ------------------
  |  Branch (323:9): [True: 0, False: 0]
  ------------------
  324|      0|					acls[ii].method = SC_AC_SCB;
  ------------------
  |  |  157|      0|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
  325|      0|					acls[ii].key_ref = sc;
  326|      0|				}
  327|      0|				else if (acl!=0xFF && cred_id)   {
  ------------------
  |  Branch (327:14): [True: 0, False: 0]
  |  Branch (327:27): [True: 0, False: 0]
  ------------------
  328|      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__
  |  |  ------------------
  ------------------
  329|      0|					acls[ii].method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  330|      0|					acls[ii].key_ref = cred_id;
  331|      0|				}
  332|      0|				else   {
  333|      0|					acls[ii].method = SC_AC_NEVER;
  ------------------
  |  |  163|      0|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  334|      0|					acls[ii].key_ref = 0;
  335|      0|				}
  336|      0|			}
  337|      0|		}
  338|      0|	}
  339|       |
  340|    128|	rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY, &data, &data_len);
  ------------------
  |  |   96|    128|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY		0xA1
  ------------------
  341|    128|	if (!rv)   {
  ------------------
  |  Branch (341:6): [True: 1, False: 127]
  ------------------
  342|      1|		blob = data;
  343|      1|		blob_len = data_len;
  344|       |
  345|      1|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH, &data, &data_len);
  ------------------
  |  |   97|      1|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MAXLENGTH	0x83
  ------------------
  346|      1|		LOG_TEST_RET(ctx, rv, "failed to get PIN max.length value");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  347|      0|		pin_cmd->pin1.max_length = *data;
  348|       |
  349|      0|		rv = authentic_get_tagged_data(ctx, blob, blob_len, AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH, &data, &data_len);
  ------------------
  |  |   98|      0|#define AUTHENTIC_TAG_CREDENTIAL_PINPOLICY_MINLENGTH	0x84
  ------------------
  350|      0|		LOG_TEST_RET(ctx, rv, "failed to get PIN min.length value");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  351|      0|		pin_cmd->pin1.min_length = *data;
  352|      0|	}
  353|       |
  354|    127|	return SC_SUCCESS;
  ------------------
  |  |   28|    127|#define SC_SUCCESS				0
  ------------------
  355|    128|}
card-authentic.c:authentic_card_reader_lock_obtained:
 1892|  1.65k|{
 1893|  1.65k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  1.65k|#define SC_SUCCESS				0
  ------------------
 1894|       |
 1895|  1.65k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.65k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.65k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.65k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.65k]
  |  |  ------------------
  ------------------
 1896|       |
 1897|  1.65k|	if (was_reset > 0
  ------------------
  |  Branch (1897:6): [True: 0, False: 1.65k]
  ------------------
 1898|      0|			&& card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2) {
  ------------------
  |  Branch (1898:7): [True: 0, False: 0]
  ------------------
 1899|      0|		r = iso7816_select_aid(card, aid_AuthentIC_3_2, sizeof(aid_AuthentIC_3_2), NULL, NULL);
 1900|      0|	}
 1901|       |
 1902|  1.65k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.65k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.65k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.65k|	int _ret = r; \
  |  |  |  |  155|  1.65k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.65k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.65k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.65k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.65k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.65k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.65k|	return _ret; \
  |  |  |  |  163|  1.65k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1903|  1.65k|}

sc_get_belpic_driver:
  447|  15.3k|{
  448|  15.3k|	return sc_get_driver();
  449|  15.3k|}
card-belpic.c:sc_get_driver:
  424|  15.3k|{
  425|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (425:6): [True: 1, False: 15.3k]
  ------------------
  426|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  427|       |
  428|  15.3k|	belpic_ops.match_card = belpic_match_card;
  429|  15.3k|	belpic_ops.init = belpic_init;
  430|       |
  431|  15.3k|	belpic_ops.update_binary = iso_ops->update_binary;
  432|  15.3k|	belpic_ops.select_file = belpic_select_file;
  433|  15.3k|	belpic_ops.read_binary = belpic_read_binary;
  434|  15.3k|	belpic_ops.pin_cmd = belpic_pin_cmd;
  435|  15.3k|	belpic_ops.set_security_env = belpic_set_security_env;
  436|       |
  437|  15.3k|	belpic_ops.compute_signature = iso_ops->compute_signature;
  438|  15.3k|	belpic_ops.get_challenge = iso_ops->get_challenge;
  439|  15.3k|	belpic_ops.get_response = iso_ops->get_response;
  440|  15.3k|	belpic_ops.check_sw = iso_ops->check_sw;
  441|       |
  442|  15.3k|	return &belpic_drv;
  443|  15.3k|}
card-belpic.c:belpic_match_card:
  209|  9.09k|{
  210|  9.09k|	int i;
  211|       |
  212|  9.09k|	i = _sc_match_atr(card, belpic_atrs, &card->type);
  213|  9.09k|	if (i < 0)
  ------------------
  |  Branch (213:6): [True: 9.03k, False: 61]
  ------------------
  214|  9.03k|		return 0;
  215|     61|	return 1;
  216|  9.09k|}
card-belpic.c:belpic_init:
  219|     61|{
  220|     61|	int key_size = 1024;
  221|     61|	unsigned long flags = 0;
  222|       |
  223|     61|	sc_log(card->ctx,  "Belpic V%s\n", BELPIC_VERSION);
  ------------------
  |  |   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__
  |  |  ------------------
  |  |               #define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |  223|     61|	sc_log(card->ctx,  "Belpic V%s\n", BELPIC_VERSION);
  |  |  |  |  ------------------
  |  |  |  |  |  |   97|     61|#define BELPIC_VERSION			"1.4"
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  224|       |
  225|     61|	if (card->type < 0)
  ------------------
  |  Branch (225:6): [True: 0, False: 61]
  ------------------
  226|      0|		card->type = SC_CARD_TYPE_BELPIC_EID;	/* Unknown card: assume it's the Belpic Card */
  227|       |
  228|     61|	card->cla = 0x00;
  229|     61|	if (card->type == SC_CARD_TYPE_BELPIC_EID) {
  ------------------
  |  Branch (229:6): [True: 61, False: 0]
  ------------------
  230|     61|		u8 carddata[BELPIC_CARDDATA_RESP_LEN];
  231|     61|		memset(carddata, 0, sizeof(carddata));
  232|       |
  233|     61|		if(get_carddata(card, carddata, sizeof(carddata)) < 0) {
  ------------------
  |  Branch (233:6): [True: 12, False: 49]
  ------------------
  234|     12|			return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     12|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  235|     12|		}
  236|     49|		if (carddata[BELPIC_CARDDATA_OFF_APPLETVERS] >= 0x18) {
  ------------------
  |  |  131|     49|#define BELPIC_CARDDATA_OFF_APPLETVERS 21
  ------------------
  |  Branch (236:7): [True: 16, False: 33]
  ------------------
  237|     16|			flags = SC_ALGORITHM_ECDSA_HASH_NONE | SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  184|     16|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|     16|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
              			flags = SC_ALGORITHM_ECDSA_HASH_NONE | SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  183|     16|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  238|     16|			_sc_card_add_ec_alg(card, 256, flags, 0, NULL);
  239|     16|			_sc_card_add_ec_alg(card, 384, flags, 0, NULL);
  240|     16|			_sc_card_add_ec_alg(card, 512, flags, 0, NULL);
  241|     16|			_sc_card_add_ec_alg(card, 521, flags, 0, NULL);
  242|     33|		} else {
  243|     33|			if (carddata[BELPIC_CARDDATA_OFF_APPLETVERS] >= 0x17) {
  ------------------
  |  |  131|     33|#define BELPIC_CARDDATA_OFF_APPLETVERS 21
  ------------------
  |  Branch (243:8): [True: 1, False: 32]
  ------------------
  244|      1|				key_size = 2048;
  245|      1|			}
  246|     33|			_sc_card_add_rsa_alg(card, key_size,
  247|     33|					SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE, 0);
  ------------------
  |  |  120|     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) */
  |  |  ------------------
  |  |  |  |  118|     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) */
  |  |  ------------------
  |  |  |  |  119|     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);
  ------------------
  |  |  142|     33|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  248|     33|		}
  249|     49|	}
  250|       |
  251|       |	/* State that we have an RNG */
  252|     49|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     49|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  253|       |
  254|     49|	card->max_pin_len = BELPIC_MAX_USER_PIN_LEN;
  ------------------
  |  |  106|     49|#define BELPIC_MAX_USER_PIN_LEN		12
  ------------------
  255|       |
  256|     49|	return 0;
  257|     61|}
card-belpic.c:get_carddata:
  170|     61|{
  171|     61|	sc_apdu_t apdu;
  172|     61|	u8 carddata_cmd[] = { 0x80, 0xE4, 0x00, 0x00, 0x1C };
  173|     61|	int r;
  174|       |
  175|     61|	if (carddataloc_len != BELPIC_CARDDATA_RESP_LEN)
  ------------------
  |  |  143|     61|#define BELPIC_CARDDATA_RESP_LEN 28
  ------------------
  |  Branch (175:6): [True: 0, False: 61]
  ------------------
  176|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  177|       |
  178|     61|	r = sc_bytes2apdu(card->ctx, carddata_cmd, sizeof(carddata_cmd), &apdu);
  179|     61|	if(r) {
  ------------------
  |  Branch (179:5): [True: 0, False: 61]
  ------------------
  180|      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__
  |  |  ------------------
  ------------------
  181|      0|		return r;
  182|      0|	}
  183|       |
  184|     61|	apdu.resp = carddata_loc;
  185|     61|	apdu.resplen = carddataloc_len;
  186|       |
  187|     61|	r = sc_transmit_apdu(card, &apdu);
  188|     61|	if(r) {
  ------------------
  |  Branch (188:5): [True: 4, False: 57]
  ------------------
  189|      4|		sc_log(card->ctx,  "GetCardData command failed: %d\n", 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__
  |  |  ------------------
  ------------------
  190|      4|		return r;
  191|      4|	}
  192|       |
  193|     57|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  194|     57|	if(r) {
  ------------------
  |  Branch (194:5): [True: 7, False: 50]
  ------------------
  195|      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__
  |  |  ------------------
  ------------------
  196|      7|		return r;
  197|      7|	}
  198|     50|	if(apdu.resplen < carddataloc_len) {
  ------------------
  |  Branch (198:5): [True: 1, False: 49]
  ------------------
  199|      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__
  |  |  ------------------
  ------------------
  200|      1|			 "GetCardData: card returned %"SC_FORMAT_LEN_SIZE_T"u bytes rather than expected %d\n",
  201|      1|			 apdu.resplen, carddataloc_len);
  202|      1|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      1|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  203|      1|	}
  204|       |
  205|     49|	return 0;
  206|     50|}
card-belpic.c:belpic_select_file:
  261|    252|{
  262|    252|	sc_apdu_t apdu;
  263|    252|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  264|    252|	int r;
  265|    252|	size_t pathlen;
  266|    252|	sc_file_t *file = NULL;
  267|       |
  268|    252|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (268:6): [True: 0, False: 252]
  |  Branch (268:22): [True: 0, False: 252]
  ------------------
  269|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  270|    252|	memcpy(path, in_path->value, in_path->len);
  271|    252|	pathlen = in_path->len;
  272|       |
  273|    252|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x08, 0x0C);
  ------------------
  |  |  293|    252|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  274|       |
  275|    252|	apdu.lc = pathlen;
  276|    252|	apdu.data = path;
  277|    252|	apdu.datalen = pathlen;
  278|       |
  279|    252|	apdu.resplen = 0;
  280|    252|	apdu.le = 0;
  281|       |
  282|    252|	r = sc_transmit_apdu(card, &apdu);
  283|       |
  284|    252|	LOG_TEST_RET(card->ctx, r, "Select File APDU transmit failed");
  ------------------
  |  |  174|    252|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    252|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    252|	int _ret = (r); \
  |  |  |  |  168|    252|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 242]
  |  |  |  |  ------------------
  |  |  |  |  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|    252|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 242]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  285|       |
  286|    242|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  287|    242|	if (r)
  ------------------
  |  Branch (287:6): [True: 173, False: 69]
  ------------------
  288|    173|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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|    173|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 173, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  289|       |
  290|     69|	next_idx = (size_t)-1;		/* reset */
  291|       |
  292|     69|	if (file_out != NULL) {
  ------------------
  |  Branch (292:6): [True: 51, False: 18]
  ------------------
  293|     51|		file = sc_file_new();
  294|     51|		file->path = *in_path;
  295|     51|		if (pathlen >= 2)
  ------------------
  |  Branch (295:7): [True: 51, False: 0]
  ------------------
  296|     51|			file->id = (in_path->value[pathlen - 2] << 8) | in_path->value[pathlen - 1];
  297|     51|		file->size = BELPIC_MAX_FILE_SIZE;
  ------------------
  |  |  103|     51|#define BELPIC_MAX_FILE_SIZE		65535
  ------------------
  298|     51|		file->shareable = 1;
  299|     51|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     51|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  300|     51|		if (pathlen == 2 && memcmp("\x3F\x00", in_path->value, 2) == 0)
  ------------------
  |  Branch (300:7): [True: 7, False: 44]
  |  Branch (300:23): [True: 0, False: 7]
  ------------------
  301|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  302|     51|		else
  303|     51|			file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|     51|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  304|     51|		*file_out = file;
  305|     51|	}
  306|       |
  307|     69|	return 0;
  308|    242|}
card-belpic.c:belpic_read_binary:
  312|    175|{
  313|    175|	int r;
  314|       |
  315|    175|	if (next_idx == idx)
  ------------------
  |  Branch (315:6): [True: 20, False: 155]
  ------------------
  316|     20|		return 0;	/* File was already read entirely */
  317|       |
  318|    155|	t1 = clock();
  319|    155|	r = iso_ops->read_binary(card, idx, buf, count, flags);
  320|    155|	t2 = clock();
  321|       |
  322|       |	/* If the 'next_idx trick' shouldn't work, we hope this error
  323|       |	 * means that an attempt was made to read beyond the file's
  324|       |	 * contents, so we'll return 0 to end the loop in sc_read_binary()*/
  325|    155|	if (r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    155|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (325:6): [True: 6, False: 149]
  ------------------
  326|      6|		return 0;
  327|       |
  328|    149|	if (r >= 0 && (size_t)r < count)
  ------------------
  |  Branch (328:6): [True: 125, False: 24]
  |  Branch (328:16): [True: 21, False: 104]
  ------------------
  329|     21|		next_idx = idx + (size_t)r;
  330|       |
  331|    149|	dur = t2 - t1;
  332|    149|	tot_dur += dur;
  333|    149|	tot_read += r;
  334|    149|	return r;
  335|    155|}
card-belpic.c:belpic_pin_cmd:
  338|      2|{
  339|      2|	data->pin1.encoding = data->pin2.encoding = BELPIC_PIN_ENCODING;
  ------------------
  |  |  107|      2|#define BELPIC_PIN_ENCODING		SC_PIN_ENCODING_GLP
  |  |  ------------------
  |  |  |  |  434|      2|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  |  |  ------------------
  ------------------
  340|      2|	data->pin1.pad_char = data->pin2.pad_char = BELPIC_PAD_CHAR;
  ------------------
  |  |  108|      2|#define BELPIC_PAD_CHAR			0xFF
  ------------------
  341|      2|	data->pin1.min_length = data->pin2.min_length = BELPIC_MIN_USER_PIN_LEN;
  ------------------
  |  |  105|      2|#define BELPIC_MIN_USER_PIN_LEN		4
  ------------------
  342|      2|	data->pin1.max_length = data->pin2.max_length = BELPIC_MAX_USER_PIN_LEN;
  ------------------
  |  |  106|      2|#define BELPIC_MAX_USER_PIN_LEN		12
  ------------------
  343|      2|	data->apdu = NULL;
  344|       |
  345|      2|	return iso_ops->pin_cmd(card, data, tries_left);
  346|      2|}

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

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

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

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

coolkey_get_attribute_data:
  602|  2.50k|{
  603|       |	/* handle the V0 objects first */
  604|  2.50k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  2.50k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (604:6): [True: 108, False: 2.39k]
  ------------------
  605|    108|		return coolkey_v0_get_attribute_data(attr, buf_len, attr_out);
  606|    108|	}
  607|       |
  608|       |	/* don't crash if we encounter some new or corrupted coolkey device */
  609|  2.39k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  2.39k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (609:6): [True: 0, False: 2.39k]
  ------------------
  610|      0|		return SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  611|      0|	}
  612|       |
  613|  2.39k|	return coolkey_v1_get_attribute_data(attr, buf_len, attr_out);
  614|       |
  615|  2.39k|}
coolkey_compare_id:
  757|   246k|{
  758|   246k|	if (a == NULL || b == NULL)
  ------------------
  |  Branch (758:6): [True: 0, False: 246k]
  |  Branch (758:19): [True: 0, False: 246k]
  ------------------
  759|      0|		return 1;
  760|   246k|	return ((sc_cardctl_coolkey_object_t *)a)->id
  761|   246k|	    != ((sc_cardctl_coolkey_object_t *)b)->id;
  762|   246k|}
coolkey_list_meter:
  765|  8.38k|size_t coolkey_list_meter(const void *el) {
  766|  8.38k|	return sizeof(sc_cardctl_coolkey_object_t);
  767|  8.38k|}
coolkey_fill_object:
 1372|  33.3k|{
 1373|  33.3k|	int r;
 1374|  33.3k|	size_t buf_len = obj->length;
 1375|  33.3k|	u8 *new_obj_data = NULL;
 1376|  33.3k|	sc_cardctl_coolkey_object_t *obj_entry;
 1377|  33.3k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  33.3k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1378|       |
 1379|  33.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  33.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  33.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  33.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  33.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 33.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1380|       |
 1381|  33.3k|	if (obj->data != NULL) {
  ------------------
  |  Branch (1381:6): [True: 0, False: 33.3k]
  ------------------
 1382|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 1383|      0|	}
 1384|  33.3k|	new_obj_data = malloc(buf_len);
 1385|  33.3k|	if (new_obj_data == NULL) {
  ------------------
  |  Branch (1385:6): [True: 0, False: 33.3k]
  ------------------
 1386|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1387|      0|	}
 1388|  33.3k|	r = coolkey_read_object(card, obj->id, 0, new_obj_data, buf_len,
 1389|  33.3k|				priv->nonce, sizeof(priv->nonce));
 1390|  33.3k|	if (r != (int)buf_len) {
  ------------------
  |  Branch (1390:6): [True: 31.2k, False: 2.09k]
  ------------------
 1391|  31.2k|		free(new_obj_data);
 1392|  31.2k|		if (r < 0) {
  ------------------
  |  Branch (1392:7): [True: 31.2k, False: 0]
  ------------------
 1393|  31.2k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  31.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  31.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  31.2k|	int _ret = r; \
  |  |  |  |  155|  31.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  31.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  31.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  31.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  31.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|  31.2k|	return _ret; \
  |  |  |  |  163|  31.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1394|  31.2k|		}
 1395|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1396|      0|	}
 1397|  2.09k|	obj_entry = coolkey_find_object_by_id(&priv->objects_list, obj->id);
 1398|  2.09k|	if (obj_entry == NULL) {
  ------------------
  |  Branch (1398:6): [True: 0, False: 2.09k]
  ------------------
 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|  2.09k|	if (obj_entry->data != NULL) {
  ------------------
  |  Branch (1402:6): [True: 0, False: 2.09k]
  ------------------
 1403|      0|		free(new_obj_data);
 1404|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1405|      0|	}
 1406|       |	/* Make sure we will not go over the allocated limits in the other
 1407|       |	 * objects if they somehow got different lengths in matching objects */
 1408|  2.09k|	if (obj_entry->length != obj->length) {
  ------------------
  |  Branch (1408:6): [True: 0, False: 2.09k]
  ------------------
 1409|      0|		free(new_obj_data);
 1410|      0|		return SC_ERROR_INTERNAL; /* shouldn't happen */
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1411|      0|	}
 1412|  2.09k|	obj_entry->data = new_obj_data;
 1413|  2.09k|	obj->data = new_obj_data;
 1414|  2.09k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.09k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.09k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.09k|	int _ret = r; \
  |  |  |  |  155|  2.09k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.09k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.09k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.09k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.09k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.09k|	return _ret; \
  |  |  |  |  163|  2.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1415|  2.09k|}
coolkey_find_object_by_template:
 1504|  1.43k|{
 1505|  1.43k|	list_t *list;
 1506|  1.43k|	sc_cardctl_coolkey_object_t *current, *rv = NULL;
 1507|  1.43k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.43k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1508|  1.43k|	int i, r;
 1509|  1.43k|	unsigned int tmp_pos = (unsigned int) -1;
 1510|       |
 1511|  1.43k|	list = &priv->objects_list;
 1512|  1.43k|	if (list->iter_active) {
  ------------------
  |  Branch (1512:6): [True: 1.43k, False: 0]
  ------------------
 1513|       |		/* workaround missing functionality of second iterator */
 1514|  1.43k|		tmp_pos = list->iter_pos;
 1515|  1.43k|		list_iterator_stop(list);
 1516|  1.43k|	}
 1517|       |
 1518|  1.43k|	list_iterator_start(list);
 1519|  22.4k|	while (list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1519:9): [True: 21.9k, False: 501]
  ------------------
 1520|  21.9k|		sc_cardctl_coolkey_attribute_t attribute;
 1521|  21.9k|		current = list_iterator_next(list);
 1522|  21.9k|		attribute.object = current;
 1523|       |
 1524|  25.3k|		for (i=0; i < count; i++) {
  ------------------
  |  Branch (1524:13): [True: 24.4k, False: 934]
  ------------------
 1525|  24.4k|			attribute.attribute_type = template[i].attribute_type;
 1526|  24.4k|			r = coolkey_find_attribute(card, &attribute);
 1527|  24.4k|			if (r < 0) {
  ------------------
  |  Branch (1527:8): [True: 15.7k, False: 8.64k]
  ------------------
 1528|  15.7k|				break;
 1529|  15.7k|			}
 1530|  8.64k|			if (template[i].attribute_data_type != attribute.attribute_data_type) {
  ------------------
  |  Branch (1530:8): [True: 85, False: 8.56k]
  ------------------
 1531|     85|				break;
 1532|     85|			}
 1533|  8.56k|			if (template[i].attribute_length != attribute.attribute_length) {
  ------------------
  |  Branch (1533:8): [True: 74, False: 8.48k]
  ------------------
 1534|     74|				break;
 1535|     74|			}
 1536|  8.48k|			if (memcmp(attribute.attribute_value, template[i].attribute_value,
  ------------------
  |  Branch (1536:8): [True: 5.12k, False: 3.35k]
  ------------------
 1537|  8.48k|							attribute.attribute_length) != 0) {
 1538|  5.12k|				break;
 1539|  5.12k|			}
 1540|  8.48k|		}
 1541|       |		/* just return the first one */
 1542|  21.9k|		if (i == count) {
  ------------------
  |  Branch (1542:7): [True: 934, False: 21.0k]
  ------------------
 1543|    934|			rv = current;
 1544|    934|			break;
 1545|    934|		}
 1546|  21.9k|	}
 1547|       |
 1548|  1.43k|	list_iterator_stop(list);
 1549|  1.43k|	if (tmp_pos != (unsigned int)-1) {
  ------------------
  |  Branch (1549:6): [True: 1.43k, False: 0]
  ------------------
 1550|       |		/* workaround missing functionality of second iterator */
 1551|  1.43k|		list_iterator_start(list);
 1552|  17.5k|		while (list_iterator_hasnext(list) && list->iter_pos < tmp_pos)
  ------------------
  |  Branch (1552:10): [True: 17.4k, False: 121]
  |  Branch (1552:41): [True: 16.1k, False: 1.31k]
  ------------------
 1553|  16.1k|			(void) list_iterator_next(list);
 1554|  1.43k|	}
 1555|  1.43k|	return rv;
 1556|  1.43k|}
sc_get_coolkey_driver:
 2479|  15.3k|{
 2480|  15.3k|	return sc_get_driver();
 2481|  15.3k|}
card-coolkey.c:coolkey_v0_get_attribute_data:
  517|    108|{
  518|       |	/* we need to manually detect types CK_ULONG */
  519|    108|	CK_ATTRIBUTE_TYPE attr_type = coolkey_get_attribute_type(attr, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|    108|#define COOLKEY_V0_OBJECT 0
  ------------------
  520|    108|	int r;
  521|    108|	size_t len;
  522|       |
  523|    108|	attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1048|    108|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
  524|    108|	attr_out->attribute_length = 0;
  525|    108|	attr_out->attribute_value = NULL;
  526|       |
  527|    108|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  528|    108|	if (r < 0) {
  ------------------
  |  Branch (528:6): [True: 0, False: 108]
  ------------------
  529|      0|		return r;
  530|      0|	}
  531|    108|	if (len + sizeof(coolkey_v0_attribute_header_t) > buf_len) {
  ------------------
  |  Branch (531:6): [True: 29, False: 79]
  ------------------
  532|     29|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     29|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  533|     29|	}
  534|     79|	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  137|     79|#define CKA_CLASS 0x00000000UL
  ------------------
              	if ((attr_type == CKA_CLASS) || (attr_type == CKA_CERTIFICATE_TYPE)
  ------------------
  |  |  145|     16|#define CKA_CERTIFICATE_TYPE 0x00000080UL
  ------------------
  |  Branch (534:6): [True: 63, False: 16]
  |  Branch (534:34): [True: 0, False: 16]
  ------------------
  535|     65|									 || (attr_type == CKA_KEY_TYPE)) {
  ------------------
  |  |  159|     16|#define CKA_KEY_TYPE 0x00000100UL
  ------------------
  |  Branch (535:14): [True: 2, False: 14]
  ------------------
  536|     65|		if (len != 4) {
  ------------------
  |  Branch (536:7): [True: 45, False: 20]
  ------------------
  537|     45|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     45|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  538|     45|		}
  539|     20|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|     20|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  540|     20|	}
  541|       |	/* return the length and the data */
  542|     34|	attr_out->attribute_length = len;
  543|     34|	attr_out->attribute_value = attr + sizeof(coolkey_v0_attribute_header_t);
  544|     34|	return SC_SUCCESS;
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
  545|     79|}
card-coolkey.c:coolkey_get_attribute_type:
  410|  24.2k|{
  411|  24.2k|	coolkey_attribute_header_t *attribute_header = (coolkey_attribute_header_t *) attr;
  412|       |
  413|  24.2k|	return bebytes2ulong(attribute_header->attribute_attr_type);
  414|  24.2k|}
card-coolkey.c:coolkey_v0_get_attribute_len:
  350|  2.44k|{
  351|  2.44k|	coolkey_v0_attribute_header_t *attribute_head = (coolkey_v0_attribute_header_t *)attr;
  352|       |	/* don't reference beyond our buffer */
  353|  2.44k|	if (buf_len < sizeof(coolkey_v0_attribute_header_t)) {
  ------------------
  |  Branch (353:6): [True: 84, False: 2.36k]
  ------------------
  354|     84|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     84|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  355|     84|	}
  356|  2.36k|	*len = bebytes2ushort(attribute_head->attribute_data_len);
  357|  2.36k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.36k|#define SC_SUCCESS				0
  ------------------
  358|  2.44k|}
card-coolkey.c:coolkey_v1_get_attribute_data:
  552|  2.39k|{
  553|  2.39k|	int r;
  554|  2.39k|	size_t len;
  555|  2.39k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  556|       |
  557|  2.39k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (557:6): [True: 36, False: 2.35k]
  ------------------
  558|     36|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     36|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  559|     36|	}
  560|       |
  561|       |	/* we must have type V1. Process according to data type */
  562|  2.35k|	switch (attribute_head->attribute_data_type) {
  563|       |	/* ULONG has implied length of 4 */
  564|    180|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|    180|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (564:2): [True: 180, False: 2.17k]
  ------------------
  565|    180|		if (buf_len < (sizeof(coolkey_attribute_header_t) + 4)) {
  ------------------
  |  Branch (565:7): [True: 10, False: 170]
  ------------------
  566|     10|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     10|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  567|     10|		}
  568|    170|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|    170|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  569|    170|		attr_out->attribute_length = 4;
  570|    170|		attr_out->attribute_value = attr + sizeof(coolkey_attribute_header_t);
  571|    170|		return SC_SUCCESS;
  ------------------
  |  |   28|    170|#define SC_SUCCESS				0
  ------------------
  572|       |	/* BOOL_FALSE and BOOL_TRUE have implied length and data */
  573|       |	/* return type STRING for BOOLS */
  574|     20|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|     20|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (574:2): [True: 20, False: 2.33k]
  ------------------
  575|     20|		attr_out->attribute_length = 1;
  576|     20|		attr_out->attribute_value =  &coolkey_static_false;
  577|     20|		return SC_SUCCESS;
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
  578|     37|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|     37|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (578:2): [True: 37, False: 2.32k]
  ------------------
  579|     37|		attr_out->attribute_length = 1;
  580|     37|		attr_out->attribute_value =  &coolkey_static_true;
  581|     37|		return SC_SUCCESS;
  ------------------
  |  |   28|     37|#define SC_SUCCESS				0
  ------------------
  582|       |	/* string type has encoded length */
  583|  1.54k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  1.54k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (583:2): [True: 1.54k, False: 810]
  ------------------
  584|  1.54k|		r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 0);
  585|  1.54k|		if (r < SC_SUCCESS) {
  ------------------
  |  |   28|  1.54k|#define SC_SUCCESS				0
  ------------------
  |  Branch (585:7): [True: 65, False: 1.48k]
  ------------------
  586|     65|			return r;
  587|     65|		}
  588|  1.48k|		if (buf_len < (len + sizeof(coolkey_attribute_header_t) + 2)) {
  ------------------
  |  Branch (588:7): [True: 119, False: 1.36k]
  ------------------
  589|    119|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    119|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  590|    119|		}
  591|  1.36k|		attr_out->attribute_value = attr+sizeof(coolkey_attribute_header_t)+2;
  592|  1.36k|		attr_out->attribute_length = len;
  593|  1.36k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.36k|#define SC_SUCCESS				0
  ------------------
  594|    573|	default:
  ------------------
  |  Branch (594:2): [True: 573, False: 1.78k]
  ------------------
  595|    573|		break;
  596|  2.35k|	}
  597|    573|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    573|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  598|  2.35k|}
card-coolkey.c:coolkey_v1_get_attribute_len:
  313|   379k|{
  314|   379k|	coolkey_attribute_header_t *attribute_head = (coolkey_attribute_header_t *)attr;
  315|       |
  316|   379k|	*len = 0;
  317|       |	/* don't reference beyond our buffer */
  318|   379k|	if (buf_len < sizeof(coolkey_attribute_header_t)) {
  ------------------
  |  Branch (318:6): [True: 353k, False: 25.3k]
  ------------------
  319|   353k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|   353k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  320|   353k|	}
  321|  25.3k|	switch (attribute_head->attribute_data_type) {
  322|  13.8k|	case COOLKEY_ATTR_TYPE_STRING:
  ------------------
  |  |  246|  13.8k|#define COOLKEY_ATTR_TYPE_STRING      0
  ------------------
  |  Branch (322:2): [True: 13.8k, False: 11.5k]
  ------------------
  323|  13.8k|		if (buf_len < (sizeof(coolkey_attribute_header_t) +2)) {
  ------------------
  |  Branch (323:7): [True: 254, False: 13.6k]
  ------------------
  324|    254|			break;
  325|    254|		}
  326|  13.6k|		*len = bebytes2ushort(attr + sizeof(coolkey_attribute_header_t));
  327|  13.6k|		if (encoded_len) {
  ------------------
  |  Branch (327:7): [True: 12.1k, False: 1.48k]
  ------------------
  328|  12.1k|			*len += 2;
  329|  12.1k|		}
  330|  13.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  13.6k|#define SC_SUCCESS				0
  ------------------
  331|  1.43k|	case COOLKEY_ATTR_TYPE_BOOL_FALSE:
  ------------------
  |  |  248|  1.43k|#define COOLKEY_ATTR_TYPE_BOOL_FALSE  2
  ------------------
  |  Branch (331:2): [True: 1.43k, False: 23.9k]
  ------------------
  332|  1.91k|	case COOLKEY_ATTR_TYPE_BOOL_TRUE:
  ------------------
  |  |  249|  1.91k|#define COOLKEY_ATTR_TYPE_BOOL_TRUE   3
  ------------------
  |  Branch (332:2): [True: 481, False: 24.9k]
  ------------------
  333|       |		/* NOTE: there is no encoded data from TYPE_BOOL_XXX, so we return length 0, but the length
  334|       |		 * of the attribute is actually 1 byte, so if encoded_len == false, return 1 */
  335|  1.91k|		*len = encoded_len ? 0: 1;
  ------------------
  |  Branch (335:10): [True: 1.91k, False: 0]
  ------------------
  336|  1.91k|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.91k|#define SC_SUCCESS				0
  ------------------
  337|      0|		break;
  338|  3.52k|	case COOLKEY_ATTR_TYPE_INTEGER:
  ------------------
  |  |  247|  3.52k|#define COOLKEY_ATTR_TYPE_INTEGER     1
  ------------------
  |  Branch (338:2): [True: 3.52k, False: 21.8k]
  ------------------
  339|  3.52k|		*len = 4; /* length is 4 in both encoded length and attribute length */
  340|  3.52k|		return SC_SUCCESS;
  ------------------
  |  |   28|  3.52k|#define SC_SUCCESS				0
  ------------------
  341|  6.06k|	default:
  ------------------
  |  Branch (341:2): [True: 6.06k, False: 19.3k]
  ------------------
  342|  6.06k|		break;
  343|  25.3k|	}
  344|  6.32k|	return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  6.32k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
  345|  25.3k|}
card-coolkey.c:coolkey_read_object:
 1100|  33.7k|{
 1101|  33.7k|	coolkey_read_object_param_t params;
 1102|  33.7k|	u8 *out_ptr;
 1103|  33.7k|	size_t left = 0;
 1104|  33.7k|	size_t len;
 1105|  33.7k|	int r;
 1106|       |
 1107|  33.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  33.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  33.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  33.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 33.7k]
  |  |  ------------------
  ------------------
 1108|       |
 1109|  33.7k|	ulong2bebytes(&params.object_id[0], object_id);
 1110|       |
 1111|  33.7k|	out_ptr = out_buf;
 1112|  33.7k|	left = out_len;
 1113|  44.3k|	do {
 1114|  44.3k|		ulong2bebytes(&params.offset[0], offset);
 1115|  44.3k|		params.length = MIN(left, COOLKEY_MAX_CHUNK_SIZE);
  ------------------
  |  |   70|  44.3k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 35.2k, False: 9.09k]
  |  |  ------------------
  ------------------
 1116|  44.3k|		len = left;
 1117|  44.3k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   72|  44.3k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_READ_OBJECT, 0, 0,
  ------------------
  |  |   88|  44.3k|#define COOLKEY_INS_READ_OBJECT                0x56
  ------------------
 1118|  44.3k|			(u8 *)&params, sizeof(params), &out_ptr, &len, nonce, nonce_size);
 1119|  44.3k|		if (r < 0) {
  ------------------
  |  Branch (1119:7): [True: 29.6k, False: 14.6k]
  ------------------
 1120|  29.6k|			goto fail;
 1121|  29.6k|		}
 1122|       |		/* sanity check to make sure we don't overflow left */
 1123|  14.6k|		if ((left < len) || (len == 0)) {
  ------------------
  |  Branch (1123:7): [True: 267, False: 14.4k]
  |  Branch (1123:23): [True: 1.47k, False: 12.9k]
  ------------------
 1124|  1.74k|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.74k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1125|  1.74k|			goto fail;
 1126|  1.74k|		}
 1127|  12.9k|		out_ptr += len;
 1128|  12.9k|		offset += len;
 1129|  12.9k|		left -= len;
 1130|  12.9k|	} while (left != 0);
  ------------------
  |  Branch (1130:11): [True: 10.6k, False: 2.34k]
  ------------------
 1131|       |
 1132|  2.34k|	return (int)out_len;
 1133|       |
 1134|  31.3k|fail:
 1135|  31.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  31.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  31.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  31.3k|	int _ret = r; \
  |  |  |  |  155|  31.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 31.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  31.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|  31.3k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 31.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  31.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  31.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|  31.3k|	return _ret; \
  |  |  |  |  163|  31.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1136|  31.3k|}
card-coolkey.c:coolkey_apdu_io:
  912|  70.2k|{
  913|  70.2k|	int r;
  914|  70.2k|	sc_apdu_t apdu;
  915|  70.2k|	u8 rbufinitbuf[COOLKEY_MAX_SIZE];
  916|  70.2k|	u8 rsendbuf[COOLKEY_MAX_SIZE];
  917|  70.2k|	u8 *rbuf;
  918|  70.2k|	size_t rbuflen;
  919|  70.2k|	int cse = 0;
  920|       |
  921|       |
  922|  70.2k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  70.2k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  70.2k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  70.2k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 70.2k]
  |  |  ------------------
  ------------------
  923|       |
  924|  70.2k|	sc_log(card->ctx,
  ------------------
  |  |   71|  70.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__
  |  |  ------------------
  ------------------
  925|  70.2k|		 "%02x %02x %02x %"SC_FORMAT_LEN_SIZE_T"u : %"SC_FORMAT_LEN_SIZE_T"u %"SC_FORMAT_LEN_SIZE_T"u\n",
  926|  70.2k|		 ins, p1, p2, sendbuflen, card->max_send_size,
  927|  70.2k|		 card->max_recv_size);
  928|       |
  929|  70.2k|	rbuf = rbufinitbuf;
  930|  70.2k|	rbuflen = sizeof(rbufinitbuf);
  931|       |
  932|       |	/* if caller provided a buffer and length */
  933|  70.2k|	if (recvbuf && *recvbuf && recvbuflen && *recvbuflen) {
  ------------------
  |  Branch (933:6): [True: 58.2k, False: 12.0k]
  |  Branch (933:17): [True: 58.2k, False: 0]
  |  Branch (933:29): [True: 58.2k, False: 0]
  |  Branch (933:43): [True: 55.7k, False: 2.52k]
  ------------------
  934|  55.7k|		rbuf = *recvbuf;
  935|  55.7k|		rbuflen = *recvbuflen;
  936|  55.7k|	}
  937|       |
  938|  70.2k|	if (sendbuf || nonce) {
  ------------------
  |  Branch (938:6): [True: 56.5k, False: 13.7k]
  |  Branch (938:17): [True: 0, False: 13.7k]
  ------------------
  939|  56.5k|		if (recvbuf) {
  ------------------
  |  Branch (939:7): [True: 44.5k, False: 12.0k]
  ------------------
  940|  44.5k|			cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  44.5k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  941|  44.5k|		} else {
  942|  12.0k|			cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  12.0k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  943|  12.0k|		}
  944|  56.5k|	} else {
  945|  13.7k|		if (recvbuf) {
  ------------------
  |  Branch (945:7): [True: 13.7k, False: 0]
  ------------------
  946|  13.7k|			cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  13.7k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  947|  13.7k|		} else {
  948|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  949|      0|		}
  950|  13.7k|	}
  951|       |
  952|       |	/* append the nonce if we have it. Coolkey just blindly puts this at the end
  953|       |	 * of the APDU (while adjusting lc). This converts case 1 to case 3. coolkey
  954|       |	 * also always drops le in case 4 (which happens when proto = T0). nonces are
  955|       |	 * never used on case 2 commands, so we can simply append the nonce to the data
  956|       |	 * and we should be fine */
  957|  70.2k|	if (nonce) {
  ------------------
  |  Branch (957:6): [True: 46.3k, False: 23.9k]
  ------------------
  958|  46.3k|		u8 *buf = rsendbuf;
  959|  46.3k|		if (sendbuf) {
  ------------------
  |  Branch (959:7): [True: 46.3k, False: 0]
  ------------------
  960|  46.3k|			sendbuflen = MIN(sendbuflen,sizeof(rsendbuf)-nonce_len);
  ------------------
  |  |   70|  46.3k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 46.3k, False: 0]
  |  |  ------------------
  ------------------
  961|  46.3k|			memcpy(rsendbuf, sendbuf, sendbuflen);
  962|  46.3k|			buf += sendbuflen;
  963|  46.3k|		}
  964|  46.3k|		memcpy(buf, nonce, nonce_len);
  965|  46.3k|		sendbuflen += nonce_len;
  966|  46.3k|		sendbuf =rsendbuf;
  967|  46.3k|	}
  968|       |
  969|  70.2k|	sc_format_apdu(card, &apdu, cse, ins, p1, p2);
  970|       |
  971|  70.2k|	apdu.lc = sendbuflen;
  972|  70.2k|	apdu.datalen = sendbuflen;
  973|  70.2k|	apdu.data = sendbuf;
  974|       |
  975|       |
  976|       |	/* coolkey uses non-standard classes */
  977|  70.2k|	apdu.cla = cla;
  978|       |
  979|  70.2k|	if (recvbuf) {
  ------------------
  |  Branch (979:6): [True: 58.2k, False: 12.0k]
  ------------------
  980|  58.2k|		apdu.resp = rbuf;
  981|  58.2k|		apdu.le = (rbuflen > 255) ? 255 : rbuflen;
  ------------------
  |  Branch (981:13): [True: 10.4k, False: 47.7k]
  ------------------
  982|  58.2k|		apdu.resplen = rbuflen;
  983|  58.2k|	} else {
  984|  12.0k|		 apdu.resp =  rbuf;
  985|  12.0k|		 apdu.le = 0;
  986|  12.0k|		 apdu.resplen = 0;
  987|  12.0k|	}
  988|       |
  989|  70.2k|	sc_log(card->ctx,
  ------------------
  |  |   71|  70.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__
  |  |  ------------------
  ------------------
  990|  70.2k|		 "calling sc_transmit_apdu flags=%lx le=%"SC_FORMAT_LEN_SIZE_T"u, resplen=%"SC_FORMAT_LEN_SIZE_T"u, resp=%p",
  991|  70.2k|		 apdu.flags, apdu.le, apdu.resplen, apdu.resp);
  992|       |
  993|       |	/* with new adpu.c and chaining, this actually reads the whole object */
  994|  70.2k|	r = sc_transmit_apdu(card, &apdu);
  995|       |
  996|  70.2k|	sc_log(card->ctx,
  ------------------
  |  |   71|  70.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__
  |  |  ------------------
  ------------------
  997|  70.2k|		 "result r=%d apdu.resplen=%"SC_FORMAT_LEN_SIZE_T"u sw1=%02x sw2=%02x",
  998|  70.2k|		 r, apdu.resplen, apdu.sw1, apdu.sw2);
  999|       |
 1000|  70.2k|	if (r < 0) {
  ------------------
  |  Branch (1000:6): [True: 888, False: 69.3k]
  ------------------
 1001|    888|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    888|#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|    888|		goto err;
 1003|    888|	}
 1004|  69.3k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1005|  69.3k|	if (r < 0) {
  ------------------
  |  Branch (1005:6): [True: 36.9k, False: 32.3k]
  ------------------
 1006|  36.9k|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|  36.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__
  |  |  ------------------
  ------------------
 1007|  36.9k|		goto err;
 1008|  36.9k|	}
 1009|       |
 1010|  32.3k|	if (recvbuflen) {
  ------------------
  |  Branch (1010:6): [True: 27.6k, False: 4.71k]
  ------------------
 1011|  27.6k|		if (recvbuf && *recvbuf == NULL) {
  ------------------
  |  Branch (1011:7): [True: 27.6k, False: 62]
  |  Branch (1011:18): [True: 0, False: 27.6k]
  ------------------
 1012|      0|			*recvbuf =  malloc(apdu.resplen);
 1013|      0|			if (*recvbuf == NULL) {
  ------------------
  |  Branch (1013:8): [True: 0, False: 0]
  ------------------
 1014|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1015|      0|				goto err;
 1016|      0|			}
 1017|      0|			memcpy(*recvbuf, rbuf, apdu.resplen);
 1018|      0|		}
 1019|  27.6k|		*recvbuflen =  apdu.resplen;
 1020|  27.6k|		r = (int)*recvbuflen;
 1021|  27.6k|	}
 1022|       |
 1023|  70.2k|err:
 1024|  70.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  70.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  70.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  70.2k|	int _ret = r; \
  |  |  |  |  155|  70.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 44.1k, False: 26.0k]
  |  |  |  |  ------------------
  |  |  |  |  156|  44.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|  37.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 37.8k, False: 6.30k]
  |  |  |  |  ------------------
  |  |  |  |  157|  44.1k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  44.1k|	} else { \
  |  |  |  |  159|  26.0k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  26.0k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  26.0k|	} \
  |  |  |  |  162|  70.2k|	return _ret; \
  |  |  |  |  163|  70.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1025|  70.2k|}
card-coolkey.c:coolkey_find_object_by_id:
  825|  15.6k|{
  826|  15.6k|	int pos;
  827|  15.6k|	static sc_cardctl_coolkey_object_t cmp = {{
  828|  15.6k|		"", 0, 0, 0, SC_PATH_TYPE_DF_NAME,
  ------------------
  |  |  118|  15.6k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  829|  15.6k|		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  15.6k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
              		{ COOLKEY_AID, sizeof(COOLKEY_AID)-1 }
  ------------------
  |  |  822|  15.6k|#define COOLKEY_AID "\xA0\x00\x00\x01\x16"
  ------------------
  830|  15.6k|	}, 0, 0, NULL};
  831|       |
  832|  15.6k|	cmp.id = object_id;
  833|  15.6k|	if ((pos = list_locate(list, &cmp)) < 0)
  ------------------
  |  Branch (833:6): [True: 9.10k, False: 6.54k]
  ------------------
  834|  9.10k|		return NULL;
  835|       |
  836|  6.54k|	return list_get_at(list, pos);
  837|  15.6k|}
card-coolkey.c:coolkey_find_attribute:
 1424|  77.3k|{
 1425|  77.3k|	u8 object_record_type;
 1426|  77.3k|	CK_ATTRIBUTE_TYPE attr_type = attribute->attribute_type;
 1427|  77.3k|	const u8 *obj = attribute->object->data;
 1428|  77.3k|	const u8 *attr = NULL;
 1429|  77.3k|	size_t buf_len = attribute->object->length;
 1430|  77.3k|	coolkey_object_header_t *object_head;
 1431|  77.3k|	int attribute_count,i;
 1432|  77.3k|	attribute->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING;
  ------------------
  |  | 1048|  77.3k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_STRING 0
  ------------------
 1433|  77.3k|	attribute->attribute_length = 0;
 1434|  77.3k|	attribute->attribute_value = NULL;
 1435|       |
 1436|  77.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  77.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  77.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  77.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  77.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 77.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1437|       |
 1438|  77.3k|	if (obj == NULL) {
  ------------------
  |  Branch (1438:6): [True: 33.3k, False: 44.0k]
  ------------------
 1439|       |		/* cast away const so we can cache the data value */
 1440|  33.3k|		int r = coolkey_fill_object(card, (sc_cardctl_coolkey_object_t *)attribute->object);
 1441|  33.3k|		if (r < 0) {
  ------------------
  |  Branch (1441:7): [True: 31.2k, False: 2.08k]
  ------------------
 1442|  31.2k|			return r;
 1443|  31.2k|		}
 1444|  2.08k|		obj = attribute->object->data;
 1445|  2.08k|		if (obj == NULL) {
  ------------------
  |  Branch (1445:7): [True: 0, False: 2.08k]
  ------------------
 1446|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1447|      0|		}
 1448|  2.08k|	}
 1449|       |
 1450|       |	/* should be a static assert so we catch this at compile time */
 1451|  77.3k|	static_assert(sizeof(coolkey_object_header_t) >= sizeof(coolkey_v0_object_header_t), "internal error");
 1452|       |	/* make sure we have enough of the object to read the record_type */
 1453|  46.1k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (1453:6): [True: 511, False: 45.6k]
  ------------------
 1454|    511|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    511|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1455|    511|	}
 1456|  45.6k|	object_head = (coolkey_object_header_t *)obj;
 1457|  45.6k|	object_record_type = object_head->record_type;
 1458|       |	/* make sure it's a type we recognize */
 1459|  45.6k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  45.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  4.95k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (1459:6): [True: 4.95k, False: 40.6k]
  |  Branch (1459:51): [True: 3.53k, False: 1.42k]
  ------------------
 1460|  3.53k|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  3.53k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1461|  3.53k|	}
 1462|       |
 1463|       |	/*
 1464|       |	 * now loop through all the attributes in the list. first find the start of the list
 1465|       |	 */
 1466|  42.1k|	attr = coolkey_attribute_start(obj, object_record_type, buf_len);
 1467|  42.1k|	if (attr == NULL) {
  ------------------
  |  Branch (1467:6): [True: 79, False: 42.0k]
  ------------------
 1468|     79|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     79|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1469|     79|	}
 1470|  42.0k|	buf_len -= (attr-obj);
 1471|       |
 1472|       |	/* now get the count */
 1473|  42.0k|	attribute_count = coolkey_get_attribute_count(obj, object_record_type, buf_len);
 1474|  63.6k|	for (i=0; i < attribute_count; i++) {
  ------------------
  |  Branch (1474:12): [True: 25.0k, False: 38.6k]
  ------------------
 1475|  25.0k|		size_t record_len = coolkey_get_attribute_record_len(attr, object_record_type, buf_len);
 1476|       |		/* make sure we have the complete record */
 1477|  25.0k|		if (buf_len < record_len || record_len < 4) {
  ------------------
  |  Branch (1477:7): [True: 0, False: 25.0k]
  |  Branch (1477:31): [True: 917, False: 24.1k]
  ------------------
 1478|    917|			return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|    917|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 1479|    917|		}
 1480|       |		/* does the attribute match the one we are looking for */
 1481|  24.1k|		if (attr_type == coolkey_get_attribute_type(attr, object_record_type, record_len)) {
  ------------------
  |  Branch (1481:7): [True: 2.50k, False: 21.6k]
  ------------------
 1482|       |			/* yup, return it */
 1483|  2.50k|			return coolkey_get_attribute_data(attr, object_record_type, record_len, attribute);
 1484|  2.50k|		}
 1485|       |		/* go to the next attribute on the list */
 1486|  21.6k|		buf_len -= record_len;
 1487|  21.6k|		attr += record_len;
 1488|  21.6k|	}
 1489|       |	/* not find in attribute list, check the fixed attribute record */
 1490|  38.6k|	if (object_record_type == COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  38.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (1490:6): [True: 37.2k, False: 1.31k]
  ------------------
 1491|  37.2k|		unsigned long fixed_attributes = bebytes2ulong(object_head->fixed_attributes_values);
 1492|       |
 1493|  37.2k|		return coolkey_get_attribute_data_fixed(attr_type, fixed_attributes, attribute);
 1494|  37.2k|	}
 1495|  1.31k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_DATA_OBJECT_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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1496|  1.31k|}
card-coolkey.c:coolkey_attribute_start:
  421|  43.4k|{
  422|  43.4k|	size_t offset = object_record_type == COOLKEY_V1_OBJECT ? sizeof(coolkey_object_header_t) :
  ------------------
  |  |  229|  43.4k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (422:18): [True: 40.6k, False: 2.72k]
  ------------------
  423|  43.4k|			sizeof(coolkey_v0_object_header_t);
  424|       |
  425|  43.4k|	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  229|  43.4k|#define COOLKEY_V1_OBJECT 1
  ------------------
              	if ((object_record_type != COOLKEY_V1_OBJECT) && (object_record_type != COOLKEY_V0_OBJECT)) {
  ------------------
  |  |  228|  2.72k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (425:6): [True: 2.72k, False: 40.6k]
  |  Branch (425:51): [True: 0, False: 2.72k]
  ------------------
  426|      0|		return NULL;
  427|      0|	}
  428|  43.4k|	if (offset > buf_len) {
  ------------------
  |  Branch (428:6): [True: 79, False: 43.3k]
  ------------------
  429|     79|		return NULL;
  430|     79|	}
  431|  43.3k|	return obj + offset;
  432|  43.4k|}
card-coolkey.c:coolkey_get_attribute_count:
  502|  42.0k|{
  503|  42.0k|	if (object_record_type == COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  42.0k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (503:6): [True: 1.42k, False: 40.6k]
  ------------------
  504|  1.42k|		return coolkey_v0_get_attribute_count(obj, buf_len);
  505|  1.42k|	}
  506|  40.6k|	if (object_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  40.6k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (506:6): [True: 0, False: 40.6k]
  ------------------
  507|      0|		return 0;
  508|      0|	}
  509|  40.6k|	return coolkey_v1_get_attribute_count(obj, buf_len);
  510|  40.6k|}
card-coolkey.c:coolkey_v0_get_attribute_count:
  440|  1.42k|{
  441|  1.42k|	coolkey_v0_object_header_t *object_head = (coolkey_v0_object_header_t *)obj;
  442|  1.42k|	const u8 *attr;
  443|  1.42k|	int count = 0;
  444|  1.42k|	size_t attribute_data_len;
  445|       |
  446|       |	/* make sure we have enough of the object to read the record_type */
  447|  1.42k|	if (buf_len <= sizeof(coolkey_v0_object_header_t)) {
  ------------------
  |  Branch (447:6): [True: 118, False: 1.30k]
  ------------------
  448|    118|		return 0;
  449|    118|	}
  450|       |	/*
  451|       |	 * now loop through all the attributes in the list. first find the start of the list
  452|       |	 */
  453|  1.30k|	attr = coolkey_attribute_start(obj, COOLKEY_V0_OBJECT, buf_len);
  ------------------
  |  |  228|  1.30k|#define COOLKEY_V0_OBJECT 0
  ------------------
  454|  1.30k|	if (attr == NULL) {
  ------------------
  |  Branch (454:6): [True: 0, False: 1.30k]
  ------------------
  455|      0|		return 0;
  456|      0|	}
  457|       |
  458|  1.30k|	buf_len -= (attr-obj);
  459|  1.30k|	attribute_data_len = bebytes2ushort(object_head->attribute_data_len);
  460|  1.30k|	if (buf_len < attribute_data_len) {
  ------------------
  |  Branch (460:6): [True: 422, False: 880]
  ------------------
  461|    422|		return 0;
  462|    422|	}
  463|       |
  464|  2.01k|	while (attribute_data_len) {
  ------------------
  |  Branch (464:9): [True: 1.37k, False: 641]
  ------------------
  465|  1.37k|		size_t len = coolkey_v0_get_attribute_record_len(attr, buf_len);
  466|       |
  467|  1.37k|		if (len == 0) {
  ------------------
  |  Branch (467:7): [True: 0, False: 1.37k]
  ------------------
  468|      0|			break;
  469|      0|		}
  470|       |		/*  This is an error in the token data, don't parse the last attribute */
  471|  1.37k|		if (len > attribute_data_len) {
  ------------------
  |  Branch (471:7): [True: 239, False: 1.13k]
  ------------------
  472|    239|			break;
  473|    239|		}
  474|       |		/* we know that coolkey_v0_get_attribute_record_len never
  475|       |		 * 	returns more than buf_len, so we can safely assert that.
  476|       |		 * 	If the assert is true, you can easily see that the loop
  477|       |		 * 	will eventually break with len == 0, even if attribute_data_len
  478|       |		 * 	was invalid */
  479|  1.13k|		if (len > buf_len)
  ------------------
  |  Branch (479:7): [True: 0, False: 1.13k]
  ------------------
  480|      0|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  481|  1.13k|		count++;
  482|  1.13k|		attr += len;
  483|  1.13k|		buf_len -= len;
  484|  1.13k|		attribute_data_len -= len;
  485|  1.13k|	}
  486|    880|	return count;
  487|    880|}
card-coolkey.c:coolkey_v0_get_attribute_record_len:
  380|  2.34k|{
  381|  2.34k|	size_t attribute_len = sizeof(coolkey_v0_attribute_header_t);
  382|  2.34k|	size_t len;
  383|  2.34k|	int r;
  384|       |
  385|  2.34k|	r = coolkey_v0_get_attribute_len(attr, buf_len, &len);
  386|  2.34k|	if (r < 0) {
  ------------------
  |  Branch (386:6): [True: 84, False: 2.25k]
  ------------------
  387|     84|		return buf_len; /* skip to the end, ignore the rest of the record */
  388|     84|	}
  389|  2.25k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  2.25k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 460, False: 1.79k]
  |  |  ------------------
  ------------------
  390|  2.34k|}
card-coolkey.c:coolkey_v1_get_attribute_count:
  491|  40.6k|{
  492|  40.6k|	coolkey_object_header_t *object_head = (coolkey_object_header_t *)obj;
  493|       |
  494|  40.6k|	if (buf_len <= sizeof(coolkey_object_header_t)) {
  ------------------
  |  Branch (494:6): [True: 19.0k, False: 21.5k]
  ------------------
  495|  19.0k|		return 0;
  496|  19.0k|	}
  497|  21.5k|	return bebytes2ushort(object_head->attribute_count);
  498|  40.6k|}
card-coolkey.c:coolkey_get_attribute_record_len:
  394|  25.0k|{
  395|  25.0k|	if (obj_record_type ==  COOLKEY_V0_OBJECT) {
  ------------------
  |  |  228|  25.0k|#define COOLKEY_V0_OBJECT 0
  ------------------
  |  Branch (395:6): [True: 967, False: 24.0k]
  ------------------
  396|    967|		return coolkey_v0_get_attribute_record_len(attr, buf_len);
  397|    967|	}
  398|  24.0k|	if (obj_record_type != COOLKEY_V1_OBJECT) {
  ------------------
  |  |  229|  24.0k|#define COOLKEY_V1_OBJECT 1
  ------------------
  |  Branch (398:6): [True: 0, False: 24.0k]
  ------------------
  399|      0|		return buf_len; /* skip to the end */
  400|      0|	}
  401|  24.0k|	return coolkey_v1_get_attribute_record_len(attr, buf_len);
  402|  24.0k|}
card-coolkey.c:coolkey_v1_get_attribute_record_len:
  364|   377k|{
  365|   377k|	size_t attribute_len = sizeof(coolkey_attribute_header_t);
  366|   377k|	size_t len = 0;
  367|   377k|	int r;
  368|       |
  369|   377k|	r = coolkey_v1_get_attribute_len(attr, buf_len, &len, 1);
  370|   377k|	if (r < 0) {
  ------------------
  |  Branch (370:6): [True: 359k, False: 17.5k]
  ------------------
  371|   359k|		return buf_len; /* skip to the end, ignore the rest of the record */
  372|   359k|	}
  373|       |
  374|  17.5k|	return MIN(buf_len,attribute_len+len);
  ------------------
  |  |   70|  17.5k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 783, False: 16.7k]
  |  |  ------------------
  ------------------
  375|   377k|}
card-coolkey.c:coolkey_get_attribute_data_fixed:
  674|  37.2k|																sc_cardctl_coolkey_attribute_t *attr_out) {
  675|  37.2k|	unsigned long cka_id = fixed_attributes & 0xf;
  676|  37.2k|	unsigned long cka_class = ((fixed_attributes) >> 4) & 0x7;
  677|  37.2k|	unsigned long mask, bit;
  678|       |
  679|  37.2k|	if (attr_type == CKA_ID) {
  ------------------
  |  |  161|  37.2k|#define CKA_ID 0x00000102UL
  ------------------
  |  Branch (679:6): [True: 4.98k, False: 32.3k]
  ------------------
  680|  4.98k|		attr_out->attribute_length = 1;
  681|  4.98k|		attr_out->attribute_value= &coolkey_static_cka_id[cka_id];
  682|  4.98k|		return SC_SUCCESS;
  ------------------
  |  |   28|  4.98k|#define SC_SUCCESS				0
  ------------------
  683|  4.98k|	}
  684|  32.3k|	if (attr_type == CKA_CLASS) {
  ------------------
  |  |  137|  32.3k|#define CKA_CLASS 0x00000000UL
  ------------------
  |  Branch (684:6): [True: 8.31k, False: 23.9k]
  ------------------
  685|  8.31k|		attr_out->attribute_data_type = SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG;
  ------------------
  |  | 1049|  8.31k|#define SC_CARDCTL_COOLKEY_ATTR_TYPE_ULONG 1
  ------------------
  686|  8.31k|		attr_out->attribute_length = 4;
  687|  8.31k|		attr_out->attribute_value = coolkey_static_cka_class[cka_class].class_value;
  688|  8.31k|		return SC_SUCCESS;
  ------------------
  |  |   28|  8.31k|#define SC_SUCCESS				0
  ------------------
  689|  8.31k|	}
  690|       |	/* If it matched, it must be one of the booleans */
  691|  23.9k|	mask = coolkey_static_cka_class[cka_class].boolean_mask;
  692|  23.9k|	bit = coolkey_get_fixed_boolean_bit(attr_type);
  693|       |	/* attribute isn't in the list */
  694|  23.9k|	if ((bit & mask) == 0) {
  ------------------
  |  Branch (694:6): [True: 9.34k, False: 14.6k]
  ------------------
  695|  9.34k|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|  9.34k|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  696|  9.34k|	}
  697|  14.6k|	attr_out->attribute_length = 1;
  698|  14.6k|	attr_out->attribute_value = bit & fixed_attributes ? &coolkey_static_true : &coolkey_static_false;
  ------------------
  |  Branch (698:30): [True: 5.93k, False: 8.71k]
  ------------------
  699|  14.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  14.6k|#define SC_SUCCESS				0
  ------------------
  700|  23.9k|}
card-coolkey.c:coolkey_get_fixed_boolean_bit:
  620|  23.9k|{
  621|  23.9k|	switch(type) {
  622|      0|	case CKA_TOKEN:               return 0x00000080;
  ------------------
  |  |  138|      0|#define CKA_TOKEN 0x00000001UL
  ------------------
  |  Branch (622:2): [True: 0, False: 23.9k]
  ------------------
  623|  1.99k|	case CKA_PRIVATE:             return 0x00000100;
  ------------------
  |  |  139|  1.99k|#define CKA_PRIVATE 0x00000002UL
  ------------------
  |  Branch (623:2): [True: 1.99k, False: 22.0k]
  ------------------
  624|  2.38k|	case CKA_MODIFIABLE:          return 0x00000200;
  ------------------
  |  |  197|  2.38k|#define CKA_MODIFIABLE 0x00000170UL
  ------------------
  |  Branch (624:2): [True: 2.38k, False: 21.6k]
  ------------------
  625|  1.12k|	case CKA_DERIVE:              return 0x00000400;
  ------------------
  |  |  171|  1.12k|#define CKA_DERIVE 0x0000010CUL
  ------------------
  |  Branch (625:2): [True: 1.12k, False: 22.8k]
  ------------------
  626|  1.12k|	case CKA_LOCAL:               return 0x00000800;
  ------------------
  |  |  193|  1.12k|#define CKA_LOCAL 0x00000163UL
  ------------------
  |  Branch (626:2): [True: 1.12k, False: 22.8k]
  ------------------
  627|  1.12k|	case CKA_ENCRYPT:             return 0x00001000;
  ------------------
  |  |  163|  1.12k|#define CKA_ENCRYPT 0x00000104UL
  ------------------
  |  Branch (627:2): [True: 1.12k, False: 22.8k]
  ------------------
  628|  1.12k|	case CKA_DECRYPT:             return 0x00002000;
  ------------------
  |  |  164|  1.12k|#define CKA_DECRYPT 0x00000105UL
  ------------------
  |  Branch (628:2): [True: 1.12k, False: 22.8k]
  ------------------
  629|  1.12k|	case CKA_WRAP:                return 0x00004000;
  ------------------
  |  |  165|  1.12k|#define CKA_WRAP 0x00000106UL
  ------------------
  |  Branch (629:2): [True: 1.12k, False: 22.8k]
  ------------------
  630|  1.12k|	case CKA_UNWRAP:              return 0x00008000;
  ------------------
  |  |  166|  1.12k|#define CKA_UNWRAP 0x00000107UL
  ------------------
  |  Branch (630:2): [True: 1.12k, False: 22.8k]
  ------------------
  631|  1.12k|	case CKA_SIGN:                return 0x00010000;
  ------------------
  |  |  167|  1.12k|#define CKA_SIGN 0x00000108UL
  ------------------
  |  Branch (631:2): [True: 1.12k, False: 22.8k]
  ------------------
  632|  1.12k|	case CKA_SIGN_RECOVER:        return 0x00020000;
  ------------------
  |  |  168|  1.12k|#define CKA_SIGN_RECOVER 0x00000109UL
  ------------------
  |  Branch (632:2): [True: 1.12k, False: 22.8k]
  ------------------
  633|  1.12k|	case CKA_VERIFY:              return 0x00040000;
  ------------------
  |  |  169|  1.12k|#define CKA_VERIFY 0x0000010AUL
  ------------------
  |  Branch (633:2): [True: 1.12k, False: 22.8k]
  ------------------
  634|  1.12k|	case CKA_VERIFY_RECOVER:      return 0x00080000;
  ------------------
  |  |  170|  1.12k|#define CKA_VERIFY_RECOVER 0x0000010BUL
  ------------------
  |  Branch (634:2): [True: 1.12k, False: 22.8k]
  ------------------
  635|  1.12k|	case CKA_SENSITIVE:           return 0x00100000;
  ------------------
  |  |  162|  1.12k|#define CKA_SENSITIVE 0x00000103UL
  ------------------
  |  Branch (635:2): [True: 1.12k, False: 22.8k]
  ------------------
  636|  1.12k|	case CKA_ALWAYS_SENSITIVE:    return 0x00200000;
  ------------------
  |  |  195|  1.12k|#define CKA_ALWAYS_SENSITIVE 0x00000165UL
  ------------------
  |  Branch (636:2): [True: 1.12k, False: 22.8k]
  ------------------
  637|  1.12k|	case CKA_EXTRACTABLE:         return 0x00400000;
  ------------------
  |  |  192|  1.12k|#define CKA_EXTRACTABLE 0x00000162UL
  ------------------
  |  Branch (637:2): [True: 1.12k, False: 22.8k]
  ------------------
  638|  1.12k|	case CKA_NEVER_EXTRACTABLE:   return 0x00800000;
  ------------------
  |  |  194|  1.12k|#define CKA_NEVER_EXTRACTABLE 0x00000164UL
  ------------------
  |  Branch (638:2): [True: 1.12k, False: 22.8k]
  ------------------
  639|  3.87k|	default: break;
  ------------------
  |  Branch (639:2): [True: 3.87k, False: 20.1k]
  ------------------
  640|  23.9k|	}
  641|  3.87k|	return 0; /* return no bits */
  642|  23.9k|}
card-coolkey.c:sc_get_driver:
 2452|  15.3k|{
 2453|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2454|       |
 2455|  15.3k|	coolkey_ops = *iso_drv->ops;
 2456|  15.3k|	coolkey_ops.match_card = coolkey_match_card;
 2457|  15.3k|	coolkey_ops.init = coolkey_init;
 2458|  15.3k|	coolkey_ops.finish = coolkey_finish;
 2459|       |
 2460|  15.3k|	coolkey_ops.select_file =  coolkey_select_file; /* need to record object type */
 2461|  15.3k|	coolkey_ops.get_challenge = coolkey_get_challenge;
 2462|  15.3k|	coolkey_ops.read_binary = coolkey_read_binary;
 2463|  15.3k|	coolkey_ops.write_binary = coolkey_write_binary;
 2464|  15.3k|	coolkey_ops.set_security_env = coolkey_set_security_env;
 2465|  15.3k|	coolkey_ops.restore_security_env = coolkey_restore_security_env;
 2466|  15.3k|	coolkey_ops.compute_signature = coolkey_compute_crypt;
 2467|  15.3k|	coolkey_ops.decipher =  coolkey_compute_crypt;
 2468|  15.3k|	coolkey_ops.card_ctl = coolkey_card_ctl;
 2469|  15.3k|	coolkey_ops.check_sw = coolkey_check_sw;
 2470|  15.3k|	coolkey_ops.pin_cmd = coolkey_pin_cmd;
 2471|  15.3k|	coolkey_ops.logout = coolkey_logout;
 2472|  15.3k|	coolkey_ops.card_reader_lock_obtained = coolkey_card_reader_lock_obtained;
 2473|       |
 2474|  15.3k|	return &coolkey_drv;
 2475|  15.3k|}
card-coolkey.c:coolkey_match_card:
 2288|  6.66k|{
 2289|  6.66k|	int r;
 2290|       |
 2291|  6.66k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  6.66k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  6.66k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  6.66k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 6.66k]
  |  |  ------------------
  ------------------
 2292|       |
 2293|  6.66k|	r = coolkey_select_applet(card);
 2294|  6.66k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  6.66k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2294:6): [True: 1.19k, False: 5.46k]
  ------------------
 2295|  1.19k|		sc_apdu_t apdu;
 2296|       |
 2297|       |		/* The GET STATUS INS with P1 = 1 returns invalid instruction (0x6D00)
 2298|       |		 * on Coolkey applet (reserved for GetMemory function),
 2299|       |		 * while incorrect P1 (0x9C10) on Muscle applets
 2300|       |		 */
 2301|  1.19k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |  291|  1.19k|#define SC_APDU_CASE_1			0x01
  ------------------
              		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, COOLKEY_INS_GET_STATUS, 0x01, 0x00);
  ------------------
  |  |   79|  1.19k|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 2302|  1.19k|		apdu.cla = COOLKEY_CLASS;
  ------------------
  |  |   72|  1.19k|#define COOLKEY_CLASS           0xb0
  ------------------
 2303|  1.19k|		apdu.le = 0x00;
 2304|  1.19k|		apdu.resplen = 0;
 2305|  1.19k|		apdu.resp = NULL;
 2306|  1.19k|		r = sc_transmit_apdu(card, &apdu);
 2307|  1.19k|		if (r == SC_SUCCESS && apdu.sw1 == 0x6d && apdu.sw2 == 0x00) {
  ------------------
  |  |   28|  2.39k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2307:7): [True: 1.19k, False: 2]
  |  Branch (2307:26): [True: 1.02k, False: 174]
  |  Branch (2307:46): [True: 1.01k, False: 6]
  ------------------
 2308|  1.01k|			return 1;
 2309|  1.01k|		}
 2310|    182|		return 0;
 2311|  1.19k|	}
 2312|  5.46k|	return 0;
 2313|  6.66k|}
card-coolkey.c:coolkey_select_applet:
 1074|  10.1k|{
 1075|  10.1k|	u8 aid[] = { 0x62, 0x76, 0x01, 0xff, 0x00, 0x00, 0x00 };
 1076|  10.1k|	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   71|  10.1k|#define ISO7816_CLASS           0x00
  ------------------
              	return coolkey_apdu_io(card, ISO7816_CLASS, ISO7816_INS_SELECT_FILE, 4, 0,
  ------------------
  |  |   75|  10.1k|#define ISO7816_INS_SELECT_FILE 0xa4
  ------------------
 1077|  10.1k|			&aid[0], sizeof(aid), NULL, NULL,  NULL, 0);
 1078|  10.1k|}
card-coolkey.c:coolkey_init:
 2317|  1.01k|{
 2318|  1.01k|	int r;
 2319|  1.01k|	unsigned long flags;
 2320|  1.01k|	unsigned long ext_flags;
 2321|  1.01k|	coolkey_private_data_t * priv;
 2322|       |
 2323|  1.01k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 2324|       |
 2325|  1.01k|	r = coolkey_initialize(card);
 2326|  1.01k|	if (r < 0) {
  ------------------
  |  Branch (2326:6): [True: 360, False: 654]
  ------------------
 2327|    360|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|    360|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    360|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    360|	int _ret = r; \
  |  |  |  |  155|    360|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 360, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    360|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    360|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 360, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    360|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    360|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    360|	return _ret; \
  |  |  |  |  163|    360|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2328|    360|	}
 2329|       |
 2330|    654|	card->type = SC_CARD_TYPE_COOLKEY_GENERIC;
 2331|       |
 2332|       |	/* set Token Major/minor version */
 2333|    654|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|    654|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 2334|       |
 2335|    654|	_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 2336|    654|	_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 2337|    654|	_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 2338|       |
 2339|    654|	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  183|    654|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  182|    654|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              	flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    654|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    654|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 2340|    654|	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    654|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              	ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    654|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 2341|       |
 2342|    654|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 2343|    654|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 2344|    654|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 2345|       |
 2346|       |
 2347|    654|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    654|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2348|    654|	if (priv->pin_count != 0) {
  ------------------
  |  Branch (2348:6): [True: 357, False: 297]
  ------------------
 2349|    357|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    357|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 2350|    357|	}
 2351|       |
 2352|    654|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    654|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    654|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    654|	int _ret = r; \
  |  |  |  |  155|    654|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 654, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    654|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 654]
  |  |  |  |  ------------------
  |  |  |  |  157|    654|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    654|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    654|	return _ret; \
  |  |  |  |  163|    654|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2353|    654|}
card-coolkey.c:coolkey_initialize:
 2157|  1.01k|{
 2158|  1.01k|	int r;
 2159|  1.01k|	coolkey_private_data_t *priv = NULL;
 2160|  1.01k|	coolkey_life_cycle_t life_cycle;
 2161|  1.01k|	coolkey_object_info_t object_info;
 2162|  1.01k|	int combined_processed = 0;
 2163|       |
 2164|       |	/* already found? */
 2165|  1.01k|	if (card->drv_data) {
  ------------------
  |  Branch (2165:6): [True: 0, False: 1.01k]
  ------------------
 2166|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2167|      0|	}
 2168|  1.01k|	sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,"Coolkey Applet found");
  ------------------
  |  |   70|  1.01k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2169|       |
 2170|  1.01k|	priv = coolkey_new_private_data();
 2171|  1.01k|	if (priv == NULL) {
  ------------------
  |  Branch (2171:6): [True: 0, False: 1.01k]
  ------------------
 2172|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2173|      0|		goto cleanup;
 2174|      0|	}
 2175|  1.01k|	r = coolkey_get_life_cycle(card, &life_cycle);
 2176|  1.01k|	if (r < 0) {
  ------------------
  |  Branch (2176:6): [True: 72, False: 942]
  ------------------
 2177|     72|		goto cleanup;
 2178|     72|	}
 2179|       |
 2180|       |	/* Select a coolkey read the coolkey objects out */
 2181|    942|	r = coolkey_select_applet(card);
 2182|    942|	if (r < 0) {
  ------------------
  |  Branch (2182:6): [True: 1, False: 941]
  ------------------
 2183|      1|		goto cleanup;
 2184|      1|	}
 2185|       |
 2186|    941|	priv->protocol_version_major = life_cycle.protocol_version_major;
 2187|    941|	priv->protocol_version_minor = life_cycle.protocol_version_minor;
 2188|    941|	priv->pin_count = life_cycle.pin_count;
 2189|    941|	priv->life_cycle = life_cycle.life_cycle;
 2190|       |
 2191|       |	/* walk down the list of objects and read them off the token */
 2192|    941|	r = coolkey_list_object(card, COOLKEY_LIST_RESET, &object_info);
  ------------------
  |  |  104|    941|#define COOLKEY_LIST_RESET 0x00
  ------------------
 2193|  12.6k|	while (r >= 0) {
  ------------------
  |  Branch (2193:9): [True: 11.8k, False: 807]
  ------------------
 2194|  11.8k|		unsigned long object_id;
 2195|  11.8k|		unsigned long object_len;
 2196|       |
 2197|       |		/* The card did not return what we expected: Lets try other objects */
 2198|  11.8k|		if ((size_t)r < (sizeof(object_info)))
  ------------------
  |  Branch (2198:7): [True: 18, False: 11.8k]
  ------------------
 2199|     18|			break;
 2200|       |
 2201|       |		/* TODO also look at the ACL... */
 2202|       |
 2203|  11.8k|		object_id = bebytes2ulong(object_info.object_id);
 2204|  11.8k|		object_len = bebytes2ulong(object_info.object_length);
 2205|       |		/* Avoid insanely large data */
 2206|  11.8k|		if (object_len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  11.8k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2206:7): [True: 18, False: 11.7k]
  ------------------
 2207|     18|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     18|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2208|     18|			goto cleanup;
 2209|     18|		}
 2210|       |
 2211|       |		/* the combined object is a single object that can store the other objects.
 2212|       |		 * most coolkeys provisioned by TPS has a single combined object that is
 2213|       |		 * compressed greatly increasing the effectiveness of compress (since lots
 2214|       |		 * of certs on the token share the same Subject and Issuer DN's). We now
 2215|       |		 * process it separately so that we can have both combined objects managed
 2216|       |		 * by TPS and user managed certs on the same token */
 2217|  11.7k|		if (object_id == COOLKEY_COMBINED_OBJECT_ID) {
  ------------------
  |  |  109|  11.7k|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
  |  Branch (2217:7): [True: 222, False: 11.5k]
  ------------------
 2218|    222|			u8 *object = malloc(object_len);
 2219|    222|			if (object == NULL) {
  ------------------
  |  Branch (2219:8): [True: 0, False: 222]
  ------------------
 2220|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2221|      0|				break;
 2222|      0|			}
 2223|    222|			r = coolkey_read_object(card, COOLKEY_COMBINED_OBJECT_ID, 0, object, object_len,
  ------------------
  |  |  109|    222|#define COOLKEY_COMBINED_OBJECT_ID 0x7a300000 /* 'z0\0\0' */
  ------------------
 2224|    222|				priv->nonce, sizeof(priv->nonce));
 2225|    222|			if (r < 0) {
  ------------------
  |  Branch (2225:8): [True: 35, False: 187]
  ------------------
 2226|     35|				free(object);
 2227|     35|				break;
 2228|     35|			}
 2229|    187|			r = coolkey_process_combined_object(card, priv, object, r);
 2230|    187|			free(object);
 2231|    187|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    187|#define SC_SUCCESS				0
  ------------------
  |  Branch (2231:8): [True: 63, False: 124]
  ------------------
 2232|     63|				break;
 2233|     63|			}
 2234|    124|			combined_processed = 1;
 2235|  11.5k|		} else {
 2236|  11.5k|			sc_log(card->ctx, "Add new object id=%ld, len=%lu", object_id, object_len);
  ------------------
  |  |   71|  11.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__
  |  |  ------------------
  ------------------
 2237|  11.5k|			r = coolkey_add_object(priv, object_id, NULL, object_len, 0);
 2238|  11.5k|			if (r != SC_SUCCESS)
  ------------------
  |  |   28|  11.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2238:8): [True: 3.95k, False: 7.60k]
  ------------------
 2239|  3.95k|				sc_log(card->ctx, "coolkey_add_object() returned %d", r);
  ------------------
  |  |   71|  3.95k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2240|  11.5k|		}
 2241|       |
 2242|       |		/* Read next object: error is handled on the cycle condition and below after cycle */
 2243|  11.6k|		r = coolkey_list_object(card, COOLKEY_LIST_NEXT, &object_info);
  ------------------
  |  |  105|  11.6k|#define COOLKEY_LIST_NEXT  0x01
  ------------------
 2244|  11.6k|	}
 2245|    923|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    923|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (2245:6): [True: 251, False: 672]
  ------------------
 2246|       |		/* This means the card does not cooperate at all: bail out */
 2247|    251|		if (r >= 0) {
  ------------------
  |  Branch (2247:7): [True: 18, False: 233]
  ------------------
 2248|     18|			r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     18|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 2249|     18|		}
 2250|    251|		goto cleanup;
 2251|    251|	}
 2252|       |	/* if we didn't pull the cuid from the combined object, then grab it now */
 2253|    672|	if (!combined_processed) {
  ------------------
  |  Branch (2253:6): [True: 551, False: 121]
  ------------------
 2254|    551|		global_platform_cplc_data_t cplc_data;
 2255|       |		/* select the card manager, because a card with applet only will have
 2256|       |		   already selected the coolkey applet */
 2257|       |
 2258|    551|		r = gp_select_card_manager(card);
 2259|    551|		if (r < 0) {
  ------------------
  |  Branch (2259:7): [True: 3, False: 548]
  ------------------
 2260|      3|			goto cleanup;
 2261|      3|		}
 2262|       |
 2263|    548|		r = gp_get_cplc_data(card, &cplc_data);
 2264|    548|		if (r < 0) {
  ------------------
  |  Branch (2264:7): [True: 15, False: 533]
  ------------------
 2265|     15|			goto cleanup;
 2266|     15|		}
 2267|    533|		coolkey_make_cuid_from_cplc(&priv->cuid, &cplc_data);
 2268|    533|		priv->token_name = (u8 *)strdup("COOLKEY");
 2269|    533|		if (priv->token_name == NULL) {
  ------------------
  |  Branch (2269:7): [True: 0, False: 533]
  ------------------
 2270|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2271|      0|			goto cleanup;
 2272|      0|		}
 2273|    533|		priv->token_name_length = sizeof("COOLKEY")-1;
 2274|    533|	}
 2275|    654|	card->drv_data = priv;
 2276|    654|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    654|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    654|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    654|	int _ret = r; \
  |  |  |  |  155|    654|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 654, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    654|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 654]
  |  |  |  |  ------------------
  |  |  |  |  157|    654|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    654|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    654|	return _ret; \
  |  |  |  |  163|    654|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2277|       |
 2278|    360|cleanup:
 2279|    360|	if (priv) {
  ------------------
  |  Branch (2279:6): [True: 360, False: 0]
  ------------------
 2280|    360|		coolkey_free_private_data(priv);
 2281|    360|	}
 2282|    360|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    360|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    360|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    360|	int _ret = r; \
  |  |  |  |  155|    360|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 360, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    360|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    360|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 360, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    360|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    360|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    360|	return _ret; \
  |  |  |  |  163|    360|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2283|    360|}
card-coolkey.c:coolkey_new_private_data:
  772|  1.01k|{
  773|  1.01k|	coolkey_private_data_t *priv;
  774|       |
  775|       |	/* allocate priv and zero all the fields */
  776|  1.01k|	priv = calloc(1, sizeof(coolkey_private_data_t));
  777|  1.01k|	if (!priv)
  ------------------
  |  Branch (777:6): [True: 0, False: 1.01k]
  ------------------
  778|      0|		return NULL;
  779|       |
  780|       |	/* set other fields as appropriate */
  781|  1.01k|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|  1.01k|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
  782|  1.01k|	if (list_init(&priv->objects_list) != 0 ||
  ------------------
  |  Branch (782:6): [True: 0, False: 1.01k]
  ------------------
  783|  1.01k|	    list_attributes_comparator(&priv->objects_list, coolkey_compare_id) != 0 ||
  ------------------
  |  Branch (783:6): [True: 0, False: 1.01k]
  ------------------
  784|  1.01k|	    list_attributes_copy(&priv->objects_list, coolkey_list_meter, 1) != 0) {
  ------------------
  |  Branch (784:6): [True: 0, False: 1.01k]
  ------------------
  785|      0|		coolkey_free_private_data(priv);
  786|      0|		return NULL;
  787|      0|	}
  788|       |
  789|  1.01k|	return priv;
  790|  1.01k|}
card-coolkey.c:coolkey_get_life_cycle:
 1032|  1.01k|{
 1033|  1.01k|	coolkey_status_t status;
 1034|  1.01k|	u8 *receive_buf;
 1035|  1.01k|	size_t receive_len;
 1036|  1.01k|	int len;
 1037|       |
 1038|  1.01k|	receive_len = sizeof(*life_cycle);
 1039|  1.01k|	receive_buf = (u8 *)life_cycle;
 1040|  1.01k|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|  1.01k|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|  1.01k|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1041|  1.01k|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1042|  1.01k|	if (len == sizeof(*life_cycle)) {
  ------------------
  |  Branch (1042:6): [True: 941, False: 73]
  ------------------
 1043|    941|		return SC_SUCCESS;
  ------------------
  |  |   28|    941|#define SC_SUCCESS				0
  ------------------
 1044|    941|	}
 1045|       |
 1046|     73|	receive_len = 1;
 1047|     73|	receive_buf = &life_cycle->life_cycle;
 1048|     73|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   72|     73|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_LIFE_CYCLE, 0, 0,
  ------------------
  |  |   78|     73|#define COOLKEY_INS_GET_LIFE_CYCLE             0xf2
  ------------------
 1049|     73|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1050|     73|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1050:6): [True: 64, False: 9]
  ------------------
 1051|     64|		return len;
 1052|     64|	}
 1053|      9|	if (len != 1) { /* The returned data is invalid */
  ------------------
  |  Branch (1053:6): [True: 2, False: 7]
  ------------------
 1054|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1055|      2|	}
 1056|      7|	receive_len = sizeof(status);
 1057|      7|	receive_buf = (u8 *)&status;
 1058|      7|	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   72|      7|#define COOLKEY_CLASS           0xb0
  ------------------
              	len = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_GET_STATUS, 0, 0,
  ------------------
  |  |   79|      7|#define COOLKEY_INS_GET_STATUS                 0x3c
  ------------------
 1059|      7|			NULL, 0, &receive_buf, &receive_len, NULL, 0);
 1060|      7|	if (len < 0) { /* Error from the trasmittion */
  ------------------
  |  Branch (1060:6): [True: 3, False: 4]
  ------------------
 1061|      3|		return len;
 1062|      3|	}
 1063|      4|	if (len != sizeof(status)) { /* The returned data is invalid */
  ------------------
  |  Branch (1063:6): [True: 3, False: 1]
  ------------------
 1064|      3|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      3|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1065|      3|	}
 1066|      1|	life_cycle->protocol_version_major = status.protocol_version_major;
 1067|      1|	life_cycle->protocol_version_minor = status.protocol_version_minor;
 1068|      1|	life_cycle->pin_count = status.pin_count;
 1069|      1|	return SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 1070|      4|}
card-coolkey.c:coolkey_list_object:
 2144|  12.6k|{
 2145|  12.6k|	u8 *rbuf = (u8 *) object_info;
 2146|  12.6k|	size_t rbuflen = sizeof(*object_info);
 2147|       |
 2148|  12.6k|	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   72|  12.6k|#define COOLKEY_CLASS           0xb0
  ------------------
              	return coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_LIST_OBJECTS, seq, 0,
  ------------------
  |  |   81|  12.6k|#define COOLKEY_INS_LIST_OBJECTS               0x58
  ------------------
 2149|  12.6k|			NULL, 0, &rbuf, &rbuflen, NULL, 0);
 2150|       |
 2151|  12.6k|}
card-coolkey.c:coolkey_process_combined_object:
 2013|    187|{
 2014|    187|	coolkey_combined_header_t *header = (coolkey_combined_header_t *)object;
 2015|    187|	unsigned short compressed_offset;
 2016|    187|	unsigned short compressed_length;
 2017|    187|	unsigned short compressed_type;
 2018|    187|	unsigned short object_offset;
 2019|    187|	unsigned short object_count;
 2020|    187|	coolkey_decompressed_header_t *decompressed_header;
 2021|    187|	u8 *decompressed_object = NULL;
 2022|    187|	size_t decompressed_object_len = 0;
 2023|    187|	int free_decompressed = 0;
 2024|    187|	int i, r;
 2025|       |
 2026|    187|	if (object_length < sizeof(coolkey_combined_header_t)) {
  ------------------
  |  Branch (2026:6): [True: 1, False: 186]
  ------------------
 2027|      1|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2028|      1|	}
 2029|    186|	compressed_offset = bebytes2ushort(header->compression_offset);
 2030|    186|	compressed_length = bebytes2ushort(header->compression_length);
 2031|    186|	compressed_type   = bebytes2ushort(header->compression_type);
 2032|       |
 2033|    186|	if ((((size_t)compressed_offset) + (size_t)compressed_length) >  object_length) {
  ------------------
  |  Branch (2033:6): [True: 11, False: 175]
  ------------------
 2034|     11|		return SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     11|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2035|     11|	}
 2036|       |
 2037|       |	/* store the CUID */
 2038|    175|	memcpy(&priv->cuid, &header->cuid, sizeof(priv->cuid));
 2039|       |
 2040|    175|	if (compressed_type == COOLKEY_COMPRESSION_ZLIB) {
  ------------------
  |  |  180|    175|#define COOLKEY_COMPRESSION_ZLIB 1
  ------------------
  |  Branch (2040:6): [True: 142, False: 33]
  ------------------
 2041|    142|#ifdef ENABLE_ZLIB
 2042|    142|		r = sc_decompress_alloc(&decompressed_object, &decompressed_object_len, &object[compressed_offset], compressed_length, COMPRESSION_AUTO);
  ------------------
  |  |   26|    142|#define COMPRESSION_AUTO	0
  ------------------
 2043|    142|		if (r)
  ------------------
  |  Branch (2043:7): [True: 18, False: 124]
  ------------------
 2044|     18|			goto done;
 2045|    124|		free_decompressed = 1;
 2046|       |#else
 2047|       |		sc_log(card->ctx, "Coolkey compression not supported, no zlib");
 2048|       |		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2049|       |#endif
 2050|    124|	}  else {
 2051|     33|		decompressed_object =&object[compressed_offset];
 2052|     33|		decompressed_object_len = (size_t) compressed_length;
 2053|     33|	}
 2054|       |
 2055|    157|	decompressed_header = (coolkey_decompressed_header_t *)decompressed_object;
 2056|       |
 2057|    157|	if (decompressed_object_len < sizeof(coolkey_decompressed_header_t)) {
  ------------------
  |  Branch (2057:6): [True: 2, False: 155]
  ------------------
 2058|      2|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      2|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2059|      2|		goto done;
 2060|      2|	}
 2061|    155|	object_offset = bebytes2ushort(decompressed_header->object_offset);
 2062|    155|	object_count = bebytes2ushort(decompressed_header->object_count);
 2063|       |
 2064|       |
 2065|       |	/*
 2066|       |	 * using 2 different tests here so we can log different errors if logging is
 2067|       |	 * turned on.
 2068|       |	 */
 2069|       |	/* make sure token_name doesn't overrun the buffer */
 2070|    155|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2070:6): [True: 0, False: 155]
  ------------------
 2071|    155|		offsetof(coolkey_decompressed_header_t, token_name) > decompressed_object_len) {
 2072|      0|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2073|      0|		goto done;
 2074|      0|	}
 2075|       |	/* make sure it doesn't overlap the object space */
 2076|    155|	if (decompressed_header->token_name_length +
  ------------------
  |  Branch (2076:6): [True: 1, False: 154]
  ------------------
 2077|    155|		offsetof(coolkey_decompressed_header_t, token_name) > object_offset) {
 2078|      1|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      1|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2079|      1|		goto done;
 2080|      1|	}
 2081|       |
 2082|       |	/* store the token name in the priv structure so the emulator can set it */
 2083|    154|	free(priv->token_name);
 2084|    154|	priv->token_name = malloc(decompressed_header->token_name_length+1);
 2085|    154|	if (priv->token_name == NULL) {
  ------------------
  |  Branch (2085:6): [True: 0, False: 154]
  ------------------
 2086|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2087|      0|		goto done;
 2088|      0|	}
 2089|    154|	memcpy(priv->token_name, &decompressed_header->token_name[0],
 2090|    154|							decompressed_header->token_name_length);
 2091|    154|	priv->token_name[decompressed_header->token_name_length] = '\0';
 2092|    154|	priv->token_name_length = decompressed_header->token_name_length;
 2093|       |
 2094|       |
 2095|    934|	for (i=0; i < object_count; i++) {
  ------------------
  |  Branch (2095:12): [True: 810, False: 124]
  ------------------
 2096|    810|		u8 *current_object = NULL;
 2097|    810|		coolkey_combined_object_header_t *object_header = NULL;
 2098|    810|		unsigned long object_id;
 2099|    810|		int current_object_len;
 2100|       |
 2101|       |		/* Can we read the object header at all? */
 2102|    810|		if ((object_offset + sizeof(coolkey_combined_object_header_t)) > decompressed_object_len) {
  ------------------
  |  Branch (2102:7): [True: 27, False: 783]
  ------------------
 2103|     27|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|     27|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2104|     27|			goto done;
 2105|     27|		}
 2106|       |
 2107|    783|		current_object = &decompressed_object[object_offset];
 2108|    783|		object_header = (coolkey_combined_object_header_t *)current_object;
 2109|       |
 2110|       |		/* Parse object ID */
 2111|    783|		object_id = bebytes2ulong(object_header->object_id);
 2112|       |
 2113|       |		/* figure out how big it is */
 2114|    783|		r = coolkey_v1_get_object_length(current_object, decompressed_object_len-object_offset);
 2115|    783|		if (r < 0) {
  ------------------
  |  Branch (2115:7): [True: 0, False: 783]
  ------------------
 2116|      0|			goto done;
 2117|      0|		}
 2118|    783|		if ((size_t)r + object_offset > decompressed_object_len) {
  ------------------
  |  Branch (2118:7): [True: 0, False: 783]
  ------------------
 2119|      0|			r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|      0|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 2120|      0|			goto done;
 2121|      0|		}
 2122|    783|		current_object_len = r;
 2123|    783|		object_offset += current_object_len;
 2124|       |
 2125|       |		/* record this object */
 2126|    783|		sc_log(card->ctx, "Add new object id=%ld", object_id);
  ------------------
  |  |   71|    783|#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|    783|		r = coolkey_add_object(priv, object_id, current_object, current_object_len, 1);
 2128|    783|		if (r) {
  ------------------
  |  Branch (2128:7): [True: 3, False: 780]
  ------------------
 2129|      3|			goto done;
 2130|      3|		}
 2131|       |
 2132|    783|	}
 2133|    124|	r = SC_SUCCESS;
  ------------------
  |  |   28|    124|#define SC_SUCCESS				0
  ------------------
 2134|       |
 2135|    175|done:
 2136|    175|	if (free_decompressed) {
  ------------------
  |  Branch (2136:6): [True: 124, False: 51]
  ------------------
 2137|    124|		free(decompressed_object);
 2138|    124|	}
 2139|    175|	return r;
 2140|    124|}
card-coolkey.c:coolkey_v1_get_object_length:
  706|    783|{
  707|    783|	coolkey_combined_object_header_t *object_head = (coolkey_combined_object_header_t *) obj;
  708|    783|	int attribute_count;
  709|    783|	u8 *current_attribute;
  710|    783|	int j;
  711|    783|	size_t len;
  712|       |
  713|    783|	len = sizeof(coolkey_combined_object_header_t);
  714|    783|	if (buf_len <= len) {
  ------------------
  |  Branch (714:6): [True: 1, False: 782]
  ------------------
  715|      1|		return (int)buf_len;
  716|      1|	}
  717|    782|	attribute_count = bebytes2ushort(object_head->attribute_count);
  718|    782|	buf_len -= len;
  719|       |
  720|   354k|	for (current_attribute = obj + len, j = 0; j < attribute_count; j++) {
  ------------------
  |  Branch (720:45): [True: 353k, False: 782]
  ------------------
  721|   353k|		size_t attribute_len = coolkey_v1_get_attribute_record_len(current_attribute, buf_len);
  722|       |
  723|   353k|		len += attribute_len;
  724|   353k|		current_attribute += attribute_len;
  725|   353k|		buf_len -= attribute_len;
  726|   353k|	}
  727|    782|	return (int)len;
  728|    783|}
card-coolkey.c:coolkey_add_object:
 1972|  12.3k|{
 1973|  12.3k|	sc_cardctl_coolkey_object_t new_object;
 1974|  12.3k|	int r;
 1975|       |
 1976|  12.3k|	memset(&new_object, 0, sizeof(new_object));
 1977|  12.3k|	new_object.path = coolkey_template_path;
 1978|  12.3k|	new_object.path.len = 4;
 1979|  12.3k|	ulong2bebytes(new_object.path.value, object_id);
 1980|  12.3k|	new_object.id = object_id;
 1981|  12.3k|	new_object.length = object_length;
 1982|       |
 1983|       |	/* The object ID needs to be unique */
 1984|  12.3k|	if (coolkey_find_object_by_id(&priv->objects_list, object_id) != NULL) {
  ------------------
  |  Branch (1984:6): [True: 3.95k, False: 8.38k]
  ------------------
 1985|  3.95k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  3.95k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1986|  3.95k|	}
 1987|       |
 1988|  8.38k|	if (object_data) {
  ------------------
  |  Branch (1988:6): [True: 780, False: 7.60k]
  ------------------
 1989|    780|		new_object.data = malloc(object_length + add_v1_record);
 1990|    780|		if (new_object.data == NULL) {
  ------------------
  |  Branch (1990:7): [True: 0, False: 780]
  ------------------
 1991|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1992|      0|		}
 1993|    780|		if (add_v1_record) {
  ------------------
  |  Branch (1993:7): [True: 780, False: 0]
  ------------------
 1994|    780|			new_object.data[0] = COOLKEY_V1_OBJECT;
  ------------------
  |  |  229|    780|#define COOLKEY_V1_OBJECT 1
  ------------------
 1995|    780|			new_object.length++;
 1996|    780|		}
 1997|    780|		memcpy(&new_object.data[add_v1_record], object_data, object_length);
 1998|    780|	}
 1999|       |
 2000|  8.38k|	r = coolkey_add_object_to_list(&priv->objects_list, &new_object);
 2001|  8.38k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  8.38k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2001:6): [True: 0, False: 8.38k]
  ------------------
 2002|       |		/* if we didn't successfully put the object on the list,
 2003|       |		 * the data space didn't get adopted. free it before we return */
 2004|      0|		free(new_object.data);
 2005|       |		new_object.data = NULL;
 2006|      0|	}
 2007|  8.38k|	return r;
 2008|  8.38k|}
card-coolkey.c:coolkey_add_object_to_list:
  816|  8.38k|{
  817|  8.38k|	if (list_append(list, object) < 0)
  ------------------
  |  Branch (817:6): [True: 0, False: 8.38k]
  ------------------
  818|      0|		return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|      0|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  819|  8.38k|	return SC_SUCCESS;
  ------------------
  |  |   28|  8.38k|#define SC_SUCCESS				0
  ------------------
  820|  8.38k|}
card-coolkey.c:coolkey_make_cuid_from_cplc:
 1082|    533|{
 1083|    533|	cuid->ic_fabricator[0]    = cplc_data->ic_fabricator[0];
 1084|    533|	cuid->ic_fabricator[1]    = cplc_data->ic_fabricator[1];
 1085|    533|	cuid->ic_type[0]          = cplc_data->ic_type[0];
 1086|    533|	cuid->ic_type[1]          = cplc_data->ic_type[1];
 1087|    533|	cuid->ic_batch[0]         = cplc_data->ic_batch[0];
 1088|    533|	cuid->ic_batch[1]         = cplc_data->ic_batch[1];
 1089|    533|	cuid->ic_serial_number[0] = cplc_data->ic_serial_number[0];
 1090|    533|	cuid->ic_serial_number[1] = cplc_data->ic_serial_number[1];
 1091|    533|	cuid->ic_serial_number[2] = cplc_data->ic_serial_number[2];
 1092|    533|	cuid->ic_serial_number[3] = cplc_data->ic_serial_number[3];
 1093|    533|}
card-coolkey.c:coolkey_free_private_data:
  793|  1.01k|{
  794|  1.01k|	list_t *l = &priv->objects_list;
  795|  1.01k|	sc_cardctl_coolkey_object_t *o;
  796|       |
  797|       |	/* Clean up the allocated memory in the items */
  798|  1.01k|	list_iterator_start(l);
  799|  9.40k|	while (list_iterator_hasnext(l)) {
  ------------------
  |  Branch (799:9): [True: 8.38k, False: 1.01k]
  ------------------
  800|  8.38k|		o = (sc_cardctl_coolkey_object_t *)list_iterator_next(l);
  801|  8.38k|		free(o->data);
  802|  8.38k|		o->data = NULL;
  803|  8.38k|	}
  804|  1.01k|	list_iterator_stop(l);
  805|       |
  806|  1.01k|	list_destroy(&priv->objects_list);
  807|  1.01k|	free(priv->token_name);
  808|  1.01k|	free(priv);
  809|  1.01k|	return;
  810|  1.01k|}
card-coolkey.c:coolkey_finish:
 1960|    654|{
 1961|    654|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    654|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1962|       |
 1963|    654|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    654|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    654|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    654|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 654]
  |  |  ------------------
  ------------------
 1964|    654|	if (priv) {
  ------------------
  |  Branch (1964:6): [True: 654, False: 0]
  ------------------
 1965|    654|		coolkey_free_private_data(priv);
 1966|    654|	}
 1967|    654|	return SC_SUCCESS;
  ------------------
  |  |   28|    654|#define SC_SUCCESS				0
  ------------------
 1968|    654|}
card-coolkey.c:coolkey_select_file:
 1913|  2.58k|{
 1914|  2.58k|	int r;
 1915|  2.58k|	struct sc_file *file = NULL;
 1916|  2.58k|	coolkey_private_data_t *priv;
 1917|  2.58k|	unsigned long object_id;
 1918|       |
 1919|  2.58k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (1919:6): [True: 0, False: 2.58k]
  |  Branch (1919:22): [True: 0, False: 2.58k]
  ------------------
 1920|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1921|       |
 1922|  2.58k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.58k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.58k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.58k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.58k]
  |  |  ------------------
  ------------------
 1923|       |
 1924|  2.58k|	priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  2.58k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1925|       |
 1926|  2.58k|	if (in_path->len != 4) {
  ------------------
  |  Branch (1926:6): [True: 1, False: 2.58k]
  ------------------
 1927|      1|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      1|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1928|      1|	}
 1929|  2.58k|	r = coolkey_select_applet(card);
 1930|  2.58k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.58k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1930:6): [True: 1.73k, False: 851]
  ------------------
 1931|  1.73k|		return r;
 1932|  1.73k|	}
 1933|    851|	object_id = bebytes2ulong(in_path->value);
 1934|    851|	priv->obj = coolkey_find_object_by_id(&priv->objects_list, object_id);
 1935|    851|	if (priv->obj == NULL) {
  ------------------
  |  Branch (1935:6): [True: 533, False: 318]
  ------------------
 1936|    533|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    533|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1937|    533|	}
 1938|       |
 1939|    318|	priv->key_id = COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|    318|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1940|    318|	if (coolkey_class(object_id) == COOLKEY_KEY_CLASS) {
  ------------------
  |  |  111|    318|#define COOLKEY_KEY_CLASS			'k'
  ------------------
  |  Branch (1940:6): [True: 294, False: 24]
  ------------------
 1941|    294|		priv->key_id = coolkey_get_key_id(object_id);
 1942|    294|	}
 1943|    318|	if (file_out) {
  ------------------
  |  Branch (1943:6): [True: 15, False: 303]
  ------------------
 1944|     15|		file = sc_file_new();
 1945|     15|		if (file == NULL)
  ------------------
  |  Branch (1945:7): [True: 0, False: 15]
  ------------------
 1946|     15|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1947|     15|		file->path = *in_path;
 1948|       |		/* this could be like the FCI */
 1949|     15|		file->type =  SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     15|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1950|     15|		file->shareable = 0;
 1951|     15|		file->ef_structure = 0;
 1952|     15|		file->size = priv->obj->length;
 1953|     15|		*file_out = file;
 1954|     15|	}
 1955|       |
 1956|    318|	return SC_SUCCESS;
  ------------------
  |  |   28|    318|#define SC_SUCCESS				0
  ------------------
 1957|    318|}
card-coolkey.c:coolkey_class:
 1886|    318|static u8 coolkey_class(unsigned long object_id) {
 1887|    318|	return (object_id >> 24) & 0xff;
 1888|    318|}
card-coolkey.c:coolkey_get_key_id:
 1890|    294|static unsigned short coolkey_get_key_id(unsigned long object_id) {
 1891|    294|	char char_index = (object_id >> 16) & 0xff;
 1892|    294|	if (char_index >= '0' && char_index <= '9') {
  ------------------
  |  Branch (1892:6): [True: 288, False: 6]
  |  Branch (1892:27): [True: 229, False: 59]
  ------------------
 1893|    229|		return (u8)(char_index - '0');
 1894|    229|	}
 1895|     65|	if (char_index >= 'A' && char_index <= 'Z') {
  ------------------
  |  Branch (1895:6): [True: 59, False: 6]
  |  Branch (1895:27): [True: 47, False: 12]
  ------------------
 1896|     47|		return (u8)(char_index - 'A' + 10);
 1897|     47|	}
 1898|     18|	if (char_index >= 'a' && char_index <= 'z') {
  ------------------
  |  Branch (1898:6): [True: 12, False: 6]
  |  Branch (1898:27): [True: 6, False: 6]
  ------------------
 1899|      6|		return (u8)(char_index - 'a' + 26 + 10);
 1900|      6|	}
 1901|     12|	return COOLKEY_INVALID_KEY;
  ------------------
  |  |  110|     12|#define COOLKEY_INVALID_KEY        0xff00
  ------------------
 1902|     18|}
card-coolkey.c:coolkey_read_binary:
 1184|     74|{
 1185|     74|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|     74|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1186|     74|	int r = 0;
 1187|     74|	size_t len;
 1188|     74|	u8 *data = NULL;
 1189|       |
 1190|     74|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|     74|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|     74|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|     74|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 74]
  |  |  ------------------
  ------------------
 1191|     74|	if (idx > priv->obj->length) {
  ------------------
  |  Branch (1191:6): [True: 0, False: 74]
  ------------------
 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|     74|	if (priv->obj->data) {
  ------------------
  |  Branch (1196:6): [True: 59, False: 15]
  ------------------
 1197|     59|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1198|     59|			 "returning cached value idx=%u count=%"SC_FORMAT_LEN_SIZE_T"u",
 1199|     59|			 idx, count);
 1200|     59|		len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     59|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 51, False: 8]
  |  |  ------------------
  ------------------
 1201|     59|		memcpy(buf, &priv->obj->data[idx], len);
 1202|     59|		LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|     59|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     59|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     59|	int _ret = r; \
  |  |  |  |  155|     59|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 59]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     59|	} else { \
  |  |  |  |  159|     59|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     59|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     59|	} \
  |  |  |  |  162|     59|	return _ret; \
  |  |  |  |  163|     59|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1203|     59|	}
 1204|       |
 1205|     15|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1206|     15|		 "clearing cache idx=%u count=%"SC_FORMAT_LEN_SIZE_T"u",
 1207|     15|		 idx, count);
 1208|       |
 1209|     15|	data = malloc(priv->obj->length);
 1210|     15|	if (data == NULL) {
  ------------------
  |  Branch (1210:6): [True: 0, False: 15]
  ------------------
 1211|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1212|      0|		goto done;
 1213|      0|	}
 1214|       |
 1215|       |
 1216|     15|	r = coolkey_read_object(card, priv->obj->id, 0, data, priv->obj->length,
 1217|     15|		priv->nonce, sizeof(priv->nonce));
 1218|     15|	if (r < 0)
  ------------------
  |  Branch (1218:6): [True: 3, False: 12]
  ------------------
 1219|      3|		goto done;
 1220|       |
 1221|     12|	if ((size_t) r != priv->obj->length) {
  ------------------
  |  Branch (1221:6): [True: 0, False: 12]
  ------------------
 1222|      0|		priv->obj->length = r;
 1223|      0|	}
 1224|       |
 1225|       |
 1226|       |	/* OK we've read the data, now copy the required portion out to the callers buffer */
 1227|     12|	len = MIN(count, priv->obj->length-idx);
  ------------------
  |  |   70|     12|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 8, False: 4]
  |  |  ------------------
  ------------------
 1228|     12|	memcpy(buf, &data[idx], len);
 1229|     12|	r = (int)len;
 1230|       |	/* cache the data in the object */
 1231|     12|	priv->obj->data=data;
 1232|     12|	data = NULL;
 1233|       |
 1234|     15|done:
 1235|     15|	if (data)
  ------------------
  |  Branch (1235:6): [True: 3, False: 12]
  ------------------
 1236|      3|		free(data);
 1237|     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: 3, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     15|	return _ret; \
  |  |  |  |  163|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1238|     15|}
card-coolkey.c:coolkey_set_security_env:
 1634|    302|{
 1635|    302|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    302|#define SC_SUCCESS				0
  ------------------
 1636|    302|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    302|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1637|       |
 1638|    302|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    302|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    302|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    302|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 302]
  |  |  ------------------
  ------------------
 1639|       |
 1640|    302|	sc_log(card->ctx,
  ------------------
  |  |   71|    302|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1641|    302|		 "flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%"SC_FORMAT_LEN_SIZE_T"u\n",
 1642|    302|		 env->flags, env->operation, env->algorithm,
 1643|    302|		 env->algorithm_flags, env->algorithm_ref, env->key_ref[0],
 1644|    302|		 env->key_ref_len);
 1645|       |
 1646|    302|	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   78|    302|#define SC_ALGORITHM_RSA		0
  ------------------
              	if ((env->algorithm != SC_ALGORITHM_RSA) && (env->algorithm != SC_ALGORITHM_EC)) {
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1646:6): [True: 0, False: 302]
  |  Branch (1646:46): [True: 0, False: 0]
  ------------------
 1647|      0|		 r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1648|      0|	}
 1649|    302|	priv->algorithm = env->algorithm;
 1650|    302|	priv->operation = env->operation;
 1651|       |
 1652|    302|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    302|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    302|	int _ret = r; \
  |  |  155|    302|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 302, False: 0]
  |  |  ------------------
  |  |  156|    302|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 302]
  |  |  ------------------
  |  |  157|    302|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    302|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    302|	return _ret; \
  |  |  163|    302|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1653|    302|}
card-coolkey.c:coolkey_compute_crypt:
 1865|    302|{
 1866|    302|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    302|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1867|    302|	int r;
 1868|    302|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    302|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    302|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    302|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 302]
  |  |  ------------------
  ------------------
 1869|       |
 1870|    302|	switch (priv->algorithm) {
 1871|    302|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    302|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1871:2): [True: 302, False: 0]
  ------------------
 1872|    302|		r = coolkey_rsa_op(card, data, datalen, out, outlen);
 1873|    302|		break;
 1874|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1874:2): [True: 0, False: 302]
  ------------------
 1875|      0|		r = coolkey_ecc_op(card, data, datalen, out, outlen);
 1876|      0|		break;
 1877|      0|	default:
  ------------------
  |  Branch (1877:2): [True: 0, False: 302]
  ------------------
 1878|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 1879|      0|		break;
 1880|    302|	}
 1881|       |
 1882|    302|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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: 278, False: 24]
  |  |  ------------------
  |  |  156|    278|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    274|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 274, False: 4]
  |  |  ------------------
  |  |  157|    278|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    278|	} else { \
  |  |  159|     24|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|     24|			"returning with: %d\n", _ret); \
  |  |  161|     24|	} \
  |  |  162|    302|	return _ret; \
  |  |  163|    302|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 1883|    302|}
card-coolkey.c:coolkey_rsa_op:
 1684|    302|{
 1685|    302|	int r;
 1686|    302|	u8 **crypt_out_p = NULL;
 1687|    302|	size_t crypt_out_len_p = 0;
 1688|    302|	coolkey_private_data_t *priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    302|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1689|    302|	coolkey_compute_crypt_params_t params;
 1690|    302|	u8 key_number;
 1691|    302|	size_t params_len;
 1692|    302|	u8 buf[MAX_COMPUTE_BUF + 2];
 1693|    302|	size_t buf_len;
 1694|    302|	u8 *buf_out;
 1695|       |
 1696|    302|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    302|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    302|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    302|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 302]
  |  |  ------------------
  ------------------
 1697|    302|	sc_log(card->ctx, "datalen=%"SC_FORMAT_LEN_SIZE_T"u outlen=%"SC_FORMAT_LEN_SIZE_T"u\n",
  ------------------
  |  |   71|    302|#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|    302|		datalen, max_out_len);
 1699|       |
 1700|    302|	if (datalen > 0xFFFF) {
  ------------------
  |  Branch (1700:6): [True: 0, False: 302]
  ------------------
 1701|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1702|      0|		goto done;
 1703|      0|	}
 1704|       |
 1705|    302|	if (priv->key_id > 0xff) {
  ------------------
  |  Branch (1705:6): [True: 20, False: 282]
  ------------------
 1706|     20|		r = SC_ERROR_NO_DEFAULT_KEY;
  ------------------
  |  |  106|     20|#define SC_ERROR_NO_DEFAULT_KEY			-1504
  ------------------
 1707|     20|		goto done;
 1708|     20|	}
 1709|    282|	key_number = priv->key_id;
 1710|       |
 1711|    282|	memset(&params, 0, sizeof(params));
 1712|    282|	params.init.mode = COOLKEY_CRYPT_MODE_RSA_NO_PAD;
  ------------------
  |  |   98|    282|#define COOLKEY_CRYPT_MODE_RSA_NO_PAD    0x00
  ------------------
 1713|    282|	params.init.direction = COOLKEY_CRYPT_DIRECTION_ENCRYPT; /* for no pad, direction is irrelevant */
  ------------------
  |  |  101|    282|#define COOLKEY_CRYPT_DIRECTION_ENCRYPT  0x03
  ------------------
 1714|       |
 1715|       |	/* send the data to the card if necessary */
 1716|    282|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1663|    282|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1716:6): [True: 131, False: 151]
  ------------------
 1717|       |		/* We need to write data to special object on the card as it does not safely fit APDU */
 1718|    131|		u8 len_buf[2];
 1719|       |
 1720|    131|		params.init.location = COOLKEY_CRYPT_LOCATION_DL_OBJECT;
  ------------------
  |  |  100|    131|#define COOLKEY_CRYPT_LOCATION_DL_OBJECT 0x02
  ------------------
 1721|       |
 1722|    131|		params_len = sizeof(params.init);
 1723|       |
 1724|    131|		ushort2bebytes(len_buf, datalen);
 1725|       |
 1726|    131|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  108|    131|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1727|    131|					priv->nonce, sizeof(priv->nonce));
 1728|    131|		if (r < 0) {
  ------------------
  |  Branch (1728:7): [True: 29, False: 102]
  ------------------
 1729|     29|			goto done;
 1730|     29|		}
 1731|       |
 1732|    102|		r = coolkey_write_object(card, COOLKEY_DL_OBJECT_ID, 2, data, datalen, priv->nonce, sizeof(priv->nonce));
  ------------------
  |  |  108|    102|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1733|    102|		if (r < 0) {
  ------------------
  |  Branch (1733:7): [True: 33, False: 69]
  ------------------
 1734|     33|			goto done;
 1735|     33|		}
 1736|     69|		ushort2bebytes(params.init.buf_len, 0);
 1737|    151|	} else {
 1738|       |		/* The data fits in APDU. Copy it to the params object */
 1739|    151|		params.init.location = COOLKEY_CRYPT_LOCATION_APDU;
  ------------------
  |  |   99|    151|#define COOLKEY_CRYPT_LOCATION_APDU      0x01
  ------------------
 1740|       |
 1741|    151|		params_len = sizeof(params.init) + datalen;
 1742|       |
 1743|    151|		buf_out = &buf[0];
 1744|    151|		crypt_out_p = &buf_out;
 1745|    151|		buf_len = sizeof(buf);
 1746|    151|		crypt_out_len_p = buf_len;
 1747|       |
 1748|    151|		ushort2bebytes(params.init.buf_len, datalen);
 1749|    151|		memcpy(params.buf, data, datalen);
 1750|    151|	}
 1751|       |
 1752|    220|	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   72|    220|#define COOLKEY_CLASS           0xb0
  ------------------
              	r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_COMPUTE_CRYPT,
  ------------------
  |  |   84|    220|#define COOLKEY_INS_COMPUTE_CRYPT              0x36
  ------------------
 1753|    220|			key_number, COOLKEY_CRYPT_ONE_STEP, (u8 *)&params, params_len,
  ------------------
  |  |   96|    220|#define COOLKEY_CRYPT_ONE_STEP 4
  ------------------
 1754|    220|			crypt_out_p, &crypt_out_len_p, priv->nonce, sizeof(priv->nonce));
 1755|    220|	if (r < 0) {
  ------------------
  |  Branch (1755:6): [True: 31, False: 189]
  ------------------
 1756|     31|		goto done;
 1757|     31|	}
 1758|    189|	buf_len = crypt_out_len_p;
 1759|       |
 1760|    189|	if (datalen > MAX_COMPUTE_BUF) {
  ------------------
  |  | 1663|    189|#define MAX_COMPUTE_BUF 200
  ------------------
  |  Branch (1760:6): [True: 62, False: 127]
  ------------------
 1761|     62|		u8 len_buf[2];
 1762|     62|		size_t out_length;
 1763|       |
 1764|     62|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, 0, len_buf, sizeof(len_buf),
  ------------------
  |  |  108|     62|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1765|     62|					priv->nonce, sizeof(priv->nonce));
 1766|     62|		if (r < 0) {
  ------------------
  |  Branch (1766:7): [True: 30, False: 32]
  ------------------
 1767|     30|			goto done;
 1768|     30|		}
 1769|       |
 1770|     32|		out_length = bebytes2ushort(len_buf);
 1771|     32|		out_length = MIN(out_length,max_out_len);
  ------------------
  |  |   70|     32|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 31, False: 1]
  |  |  ------------------
  ------------------
 1772|       |
 1773|     32|		r = coolkey_read_object(card, COOLKEY_DL_OBJECT_ID, sizeof(len_buf), out, out_length,
  ------------------
  |  |  108|     32|#define COOLKEY_DL_OBJECT_ID       0xffffffff
  ------------------
 1774|     32|					priv->nonce, sizeof(priv->nonce));
 1775|       |
 1776|    127|	} else {
 1777|    127|		size_t out_length;
 1778|    127|		if (buf_len < 2) {
  ------------------
  |  Branch (1778:7): [True: 51, False: 76]
  ------------------
 1779|     51|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     51|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1780|     51|			goto done;
 1781|     51|		}
 1782|     76|		out_length = bebytes2ushort(buf);
 1783|     76|		if (out_length > buf_len) {
  ------------------
  |  Branch (1783:7): [True: 60, False: 16]
  ------------------
 1784|     60|			r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     60|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1785|     60|			goto done;
 1786|     60|		}
 1787|     16|		out_length = MIN(out_length, max_out_len);
  ------------------
  |  |   70|     16|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 16, False: 0]
  |  |  ------------------
  ------------------
 1788|     16|		memcpy(out, buf + 2, out_length);
 1789|     16|		r = (int)out_length;
 1790|     16|	}
 1791|       |
 1792|    302|done:
 1793|    302|	return r;
 1794|    189|}
card-coolkey.c:coolkey_write_object:
 1143|    233|{
 1144|    233|	coolkey_write_object_param_t params;
 1145|    233|	size_t operation_len;
 1146|    233|	size_t left = buf_len;
 1147|    233|	int r;
 1148|    233|	size_t max_operation_len;
 1149|       |
 1150|       |	/* set limit for the card's maximum send size and short write */
 1151|    233|	max_operation_len = MIN(COOLKEY_MAX_CHUNK_SIZE, (card->max_send_size - sizeof(coolkey_read_object_param_t) - nonce_size));
  ------------------
  |  |   70|    233|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 233]
  |  |  ------------------
  ------------------
 1152|       |
 1153|    233|	ulong2bebytes(&params.head.object_id[0], object_id);
 1154|       |
 1155|  1.78k|	do {
 1156|  1.78k|		ulong2bebytes(&params.head.offset[0], offset);
 1157|  1.78k|		operation_len = MIN(left, max_operation_len);
  ------------------
  |  |   70|  1.78k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 207, False: 1.58k]
  |  |  ------------------
  ------------------
 1158|  1.78k|		params.head.length = operation_len;
 1159|  1.78k|		memcpy(params.buf, buf, operation_len);
 1160|  1.78k|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   72|  1.78k|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_WRITE_OBJECT, 0, 0,
  ------------------
  |  |   89|  1.78k|#define COOLKEY_INS_WRITE_OBJECT               0x54
  ------------------
 1161|  1.78k|			(u8 *)&params, sizeof(params.head)+operation_len, NULL, 0, nonce, nonce_size);
 1162|  1.78k|		if (r < 0) {
  ------------------
  |  Branch (1162:7): [True: 62, False: 1.72k]
  ------------------
 1163|     62|			goto fail;
 1164|     62|		}
 1165|  1.72k|		buf += operation_len;
 1166|  1.72k|		offset += operation_len;
 1167|  1.72k|		left -= operation_len;
 1168|  1.72k|	} while (left != 0);
  ------------------
  |  Branch (1168:11): [True: 1.55k, False: 171]
  ------------------
 1169|       |
 1170|    171|	return (int)(buf_len - left);
 1171|       |
 1172|     62|fail:
 1173|     62|	return r;
 1174|    233|}
card-coolkey.c:coolkey_card_ctl:
 1589|  63.9k|{
 1590|  63.9k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  63.9k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1591|       |
 1592|  63.9k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  63.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  63.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  63.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  63.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 63.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1593|  63.9k|	sc_log(card->ctx, "cmd=%ld ptr=%p", cmd, ptr);
  ------------------
  |  |   71|  63.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__
  |  |  ------------------
  ------------------
 1594|       |
 1595|  63.9k|	if (priv == NULL) {
  ------------------
  |  Branch (1595:6): [True: 0, False: 63.9k]
  ------------------
 1596|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1597|      0|	}
 1598|  63.9k|	switch(cmd) {
  ------------------
  |  Branch (1598:9): [True: 63.9k, False: 0]
  ------------------
 1599|      0|		case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1599:3): [True: 0, False: 63.9k]
  ------------------
 1600|      0|			return coolkey_get_serial_nr_from_CUID(card, (sc_serial_number_t *) ptr);
 1601|    654|		case SC_CARDCTL_COOLKEY_GET_TOKEN_INFO:
  ------------------
  |  Branch (1601:3): [True: 654, False: 63.3k]
  ------------------
 1602|    654|			return coolkey_get_token_info(card, (sc_pkcs15_tokeninfo_t *) ptr);
 1603|  1.79k|		case SC_CARDCTL_COOLKEY_FIND_OBJECT:
  ------------------
  |  Branch (1603:3): [True: 1.79k, False: 62.1k]
  ------------------
 1604|  1.79k|			return coolkey_find_object(card, (sc_cardctl_coolkey_find_object_t *)ptr);
 1605|    654|		case SC_CARDCTL_COOLKEY_INIT_GET_OBJECTS:
  ------------------
  |  Branch (1605:3): [True: 654, False: 63.3k]
  ------------------
 1606|    654|			return coolkey_get_init_and_get_count(&priv->objects_list, (int *)ptr);
 1607|  7.27k|		case SC_CARDCTL_COOLKEY_GET_NEXT_OBJECT:
  ------------------
  |  Branch (1607:3): [True: 7.27k, False: 56.7k]
  ------------------
 1608|  7.27k|			return coolkey_fetch_object(&priv->objects_list, (sc_cardctl_coolkey_object_t *)ptr);
 1609|    654|		case SC_CARDCTL_COOLKEY_FINAL_GET_OBJECTS:
  ------------------
  |  Branch (1609:3): [True: 654, False: 63.3k]
  ------------------
 1610|    654|			return coolkey_final_iterator(&priv->objects_list);
 1611|  52.9k|		case SC_CARDCTL_COOLKEY_GET_ATTRIBUTE:
  ------------------
  |  Branch (1611:3): [True: 52.9k, False: 11.0k]
  ------------------
 1612|  52.9k|			return coolkey_find_attribute(card,(sc_cardctl_coolkey_attribute_t *)ptr);
 1613|  63.9k|	}
 1614|       |
 1615|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1616|      0|}
card-coolkey.c:coolkey_get_token_info:
 1334|    654|{
 1335|    654|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    654|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1336|    654|	char *label = NULL;
 1337|    654|	char *manufacturer_id = NULL;
 1338|    654|	char *serial_number = NULL;
 1339|       |
 1340|    654|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    654|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    654|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    654|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    654|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 654]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1341|    654|	label = strdup((char *)priv->token_name);
 1342|    654|	manufacturer_id = coolkey_get_manufacturer(&priv->cuid);
 1343|    654|	serial_number = coolkey_cuid_to_string(&priv->cuid);
 1344|       |
 1345|    654|	if (label && manufacturer_id && serial_number) {
  ------------------
  |  Branch (1345:6): [True: 654, False: 0]
  |  Branch (1345:15): [True: 654, False: 0]
  |  Branch (1345:34): [True: 654, False: 0]
  ------------------
 1346|    654|		free(token_info->label);
 1347|    654|		token_info->label = label;
 1348|    654|		free(token_info->manufacturer_id);
 1349|    654|		token_info->manufacturer_id = manufacturer_id;
 1350|    654|		free(token_info->serial_number);
 1351|    654|		token_info->serial_number = serial_number;
 1352|    654|		return SC_SUCCESS;
  ------------------
  |  |   28|    654|#define SC_SUCCESS				0
  ------------------
 1353|    654|	}
 1354|      0|	free(label);
 1355|      0|	free(manufacturer_id);
 1356|      0|	free(serial_number);
 1357|      0|	return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1358|    654|}
card-coolkey.c:coolkey_get_manufacturer:
 1305|    654|{
 1306|    654|	unsigned short fabricator = bebytes2ushort(cuid->ic_fabricator);
 1307|    654|	int i;
 1308|    654|	char *buf;
 1309|    654|	const char *manufacturer_string = "%04x Unknown";
 1310|    654|	size_t len;
 1311|    654|	int r;
 1312|       |
 1313|  3.89k|	for (i=0; i < manufacturer_list_count; i++) {
  ------------------
  |  Branch (1313:12): [True: 3.26k, False: 624]
  ------------------
 1314|  3.26k|		if (manufacturer_list[i].id == fabricator) {
  ------------------
  |  Branch (1314:7): [True: 30, False: 3.23k]
  ------------------
 1315|     30|			manufacturer_string = manufacturer_list[i].string;
 1316|     30|			break;
 1317|     30|		}
 1318|  3.26k|	}
 1319|    654|	len = strlen(manufacturer_string)+1;
 1320|    654|	buf= malloc(len);
 1321|    654|	if (buf == NULL) {
  ------------------
  |  Branch (1321:6): [True: 0, False: 654]
  ------------------
 1322|      0|		return NULL;
 1323|      0|	}
 1324|    654|	r = snprintf(buf, len, manufacturer_string, fabricator);
 1325|    654|	if (r < 0) {
  ------------------
  |  Branch (1325:6): [True: 0, False: 654]
  ------------------
 1326|      0|		free(buf);
 1327|      0|		return NULL;
 1328|      0|	}
 1329|    654|	return buf;
 1330|    654|}
card-coolkey.c:coolkey_cuid_to_string:
 1280|    654|{
 1281|    654|	char *buf;
 1282|    654|	size_t len = sizeof(coolkey_cuid_t)*2 + 1;
 1283|    654|	buf = malloc(len);
 1284|    654|	if (buf == NULL) {
  ------------------
  |  Branch (1284:6): [True: 0, False: 654]
  ------------------
 1285|      0|		return NULL;
 1286|      0|	}
 1287|    654|	sc_bin_to_hex((u8 *)cuid, sizeof(*cuid), buf, len, 0);
 1288|    654|	return buf;
 1289|    654|}
card-coolkey.c:coolkey_find_object:
 1560|  1.79k|{
 1561|  1.79k|	sc_cardctl_coolkey_object_t *obj = NULL;
 1562|  1.79k|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|  1.79k|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 1563|  1.79k|	int r;
 1564|       |
 1565|  1.79k|	switch (fobj->type) {
 1566|    356|	case SC_CARDCTL_COOLKEY_FIND_BY_ID:
  ------------------
  |  | 1059|    356|#define SC_CARDCTL_COOLKEY_FIND_BY_ID       0
  ------------------
  |  Branch (1566:2): [True: 356, False: 1.43k]
  ------------------
 1567|    356|		obj = coolkey_find_object_by_id(&priv->objects_list, fobj->find_id);
 1568|    356|		break;
 1569|  1.43k|	case SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE:
  ------------------
  |  | 1060|  1.43k|#define SC_CARDCTL_COOLKEY_FIND_BY_TEMPLATE 1
  ------------------
  |  Branch (1569:2): [True: 1.43k, False: 356]
  ------------------
 1570|  1.43k|		obj = coolkey_find_object_by_template(card, fobj->coolkey_template, fobj->template_count);
 1571|  1.43k|		break;
 1572|      0|	default:
  ------------------
  |  Branch (1572:2): [True: 0, False: 1.79k]
  ------------------
 1573|      0|		break;
 1574|  1.79k|	}
 1575|  1.79k|	if (obj == NULL) {
  ------------------
  |  Branch (1575:6): [True: 682, False: 1.10k]
  ------------------
 1576|    682|		return SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|    682|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 1577|    682|	}
 1578|  1.10k|	if (obj->data == NULL) {
  ------------------
  |  Branch (1578:6): [True: 80, False: 1.02k]
  ------------------
 1579|     80|		r = coolkey_fill_object(card, obj);
 1580|     80|		if (r < 0) {
  ------------------
  |  Branch (1580:7): [True: 71, False: 9]
  ------------------
 1581|     71|			return r;
 1582|     71|		}
 1583|     80|	}
 1584|  1.03k|	fobj->obj = obj;
 1585|  1.03k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.03k|#define SC_SUCCESS				0
  ------------------
 1586|  1.10k|}
card-coolkey.c:coolkey_get_init_and_get_count:
 1253|    654|{
 1254|    654|	*countp = list_size(list);
 1255|    654|	list_iterator_start(list);
 1256|    654|	return SC_SUCCESS;
  ------------------
  |  |   28|    654|#define SC_SUCCESS				0
  ------------------
 1257|    654|}
card-coolkey.c:coolkey_fetch_object:
 1261|  7.27k|{
 1262|  7.27k|	sc_cardctl_coolkey_object_t *ptr;
 1263|  7.27k|	if (!list_iterator_hasnext(list)) {
  ------------------
  |  Branch (1263:6): [True: 0, False: 7.27k]
  ------------------
 1264|      0|		return SC_ERROR_FILE_END_REACHED;
  ------------------
  |  |   69|      0|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
 1265|      0|	}
 1266|       |
 1267|  7.27k|	ptr = list_iterator_next(list);
 1268|  7.27k|	*coolkey_obj = *ptr;
 1269|  7.27k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.27k|#define SC_SUCCESS				0
  ------------------
 1270|  7.27k|}
card-coolkey.c:coolkey_final_iterator:
 1274|    654|{
 1275|    654|	list_iterator_stop(list);
 1276|    654|	return SC_SUCCESS;
  ------------------
  |  |   28|    654|#define SC_SUCCESS				0
  ------------------
 1277|    654|}
card-coolkey.c:coolkey_check_sw:
  876|  72.4k|{
  877|  72.4k|	sc_log(card->ctx,
  ------------------
  |  |   71|  72.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__
  |  |  ------------------
  ------------------
  878|  72.4k|		"sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
  879|       |
  880|  72.4k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (880:6): [True: 36.9k, False: 35.5k]
  |  Branch (880:21): [True: 34.5k, False: 2.32k]
  ------------------
  881|  34.5k|		return SC_SUCCESS;
  ------------------
  |  |   28|  34.5k|#define SC_SUCCESS				0
  ------------------
  882|       |
  883|  37.8k|	if (sw1 == 0x9c) {
  ------------------
  |  Branch (883:6): [True: 961, False: 36.8k]
  ------------------
  884|    961|		if (sw2 == 0xff) {
  ------------------
  |  Branch (884:7): [True: 14, False: 947]
  ------------------
  885|       |			/* shouldn't happen on a production applet, 0x9cff is a debugging error code */
  886|     14|			return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     14|#define SC_ERROR_INTERNAL			-1400
  ------------------
  887|     14|		}
  888|    947|		if (sw2 >= coolkey_number_of_error_codes) {
  ------------------
  |  Branch (888:7): [True: 43, False: 904]
  ------------------
  889|     43|			return SC_ERROR_UNKNOWN;
  ------------------
  |  |  130|     43|#define SC_ERROR_UNKNOWN			-1900
  ------------------
  890|     43|		}
  891|    904|		return coolkey_error_codes[sw2].sc_error;
  892|    947|	}
  893|       |
  894|       |	/* iso error */
  895|  36.8k|        return sc_get_iso7816_driver()->ops->check_sw(card, sw1, sw2);
  896|  37.8k|}
card-coolkey.c:coolkey_pin_cmd:
 2358|    699|{
 2359|    699|	int r;
 2360|    699|	coolkey_private_data_t * priv = COOLKEY_DATA(card);
  ------------------
  |  |  753|    699|#define COOLKEY_DATA(card) ((coolkey_private_data_t*)card->drv_data)
  ------------------
 2361|    699|	size_t rbuflen;
 2362|    699|	u8 *rbuf;
 2363|       |
 2364|       |	/* COOLKEY uses a separate pin from the card pin, managed by the applet.
 2365|       |	 * if we successfully log into coolkey, we will get a nonce, which we append
 2366|       |	 * to our APDUs to authenticate the apdu to the card. This allows coolkey to
 2367|       |	 * maintain separate per application login states without the application
 2368|       |	 * having to cache the pin */
 2369|    699|	switch (data->cmd) {
 2370|    654|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|    654|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2370:2): [True: 654, False: 45]
  ------------------
 2371|    654|		if (priv->nonce_valid) {
  ------------------
  |  Branch (2371:7): [True: 11, False: 643]
  ------------------
 2372|     11|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|     11|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 2373|    643|		} else {
 2374|    643|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|    643|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 2375|       |			/* coolkey retries is 100. It's unlikely the pin is block.
 2376|       |			 * instead, coolkey slows down the login command exponentially
 2377|       |			 */
 2378|    643|			data->pin1.tries_left = 0xf;
 2379|    643|		}
 2380|    654|		if (tries_left) {
  ------------------
  |  Branch (2380:7): [True: 0, False: 654]
  ------------------
 2381|      0|			*tries_left = data->pin1.tries_left;
 2382|      0|		}
 2383|    654|		r = SC_SUCCESS;
  ------------------
  |  |   28|    654|#define SC_SUCCESS				0
  ------------------
 2384|    654|		break;
 2385|       |
 2386|     12|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|     12|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2386:2): [True: 12, False: 687]
  ------------------
 2387|     24|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|     24|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2387:2): [True: 12, False: 687]
  ------------------
 2388|       |		/* these 2 commands are currently reserved for TPS */
 2389|     24|	default:
  ------------------
  |  Branch (2389:2): [True: 0, False: 699]
  ------------------
 2390|     24|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|     24|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2391|     24|		break;
 2392|     21|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|     21|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2392:2): [True: 21, False: 678]
  ------------------
 2393|       |		/* coolkey applet supports multiple pins, but TPS currently only uses one.
 2394|       |		 * just support the one pin for now (we need an array of nonces to handle
 2395|       |		 * multiple pins) */
 2396|       |		/* coolkey only supports unpadded ascii pins, so no need to format the pin */
 2397|     21|		rbuflen = sizeof(priv->nonce);
 2398|     21|		rbuf = &priv->nonce[0];
 2399|     21|		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   72|     21|#define COOLKEY_CLASS           0xb0
  ------------------
              		r = coolkey_apdu_io(card, COOLKEY_CLASS, COOLKEY_INS_VERIFY_PIN,
  ------------------
  |  |   80|     21|#define COOLKEY_INS_VERIFY_PIN                 0x42
  ------------------
 2400|     21|			data->pin_reference, 0, data->pin1.data, data->pin1.len,
 2401|     21|			&rbuf, &rbuflen, NULL, 0);
 2402|     21|		if (r < 0) {
  ------------------
  |  Branch (2402:7): [True: 10, False: 11]
  ------------------
 2403|     10|			break;
 2404|     10|		}
 2405|     11|		priv->nonce_valid = 1;
 2406|     11|		r = SC_SUCCESS;
  ------------------
  |  |   28|     11|#define SC_SUCCESS				0
  ------------------
 2407|    699|	}
 2408|    699|	return r;
 2409|    699|}
card-coolkey.c:coolkey_card_reader_lock_obtained:
 2430|  26.4k|{
 2431|  26.4k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  26.4k|#define SC_SUCCESS				0
  ------------------
 2432|       |
 2433|  26.4k|	SC_FUNC_CALLED(card->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]
  |  |  ------------------
  ------------------
 2434|       |
 2435|  26.4k|	if (was_reset > 0) {
  ------------------
  |  Branch (2435:6): [True: 0, False: 26.4k]
  ------------------
 2436|      0|		r = coolkey_select_applet(card);
 2437|      0|	}
 2438|       |
 2439|  26.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  26.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  26.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  26.4k|	int _ret = r; \
  |  |  |  |  155|  26.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  26.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: 26.4k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  26.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|  26.4k|	return _ret; \
  |  |  |  |  163|  26.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2440|  26.4k|}

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

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

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

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

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

sc_get_eoi_driver:
  566|  15.3k|{
  567|  15.3k|	eoi_ops = *sc_get_iso7816_driver()->ops;
  568|       |
  569|  15.3k|	eoi_ops.match_card = eoi_match_card;
  570|  15.3k|	eoi_ops.init = eoi_init;
  571|  15.3k|	eoi_ops.finish = eoi_finish;
  572|  15.3k|	eoi_ops.select_file = eoi_select_file;
  573|  15.3k|	eoi_ops.logout = eoi_logout;
  574|  15.3k|	eoi_ops.pin_cmd = eoi_pin_cmd;
  575|  15.3k|	eoi_ops.card_ctl = eoi_card_ctl;
  576|  15.3k|	eoi_ops.set_security_env = eoi_set_security_env;
  577|  15.3k|	eoi_ops.compute_signature = eoi_compute_signature;
  578|       |
  579|  15.3k|	return &eoi_drv;
  580|  15.3k|}
card-eoi.c:eoi_match_card:
  236|  2.10k|static int eoi_match_card(sc_card_t* card) {
  237|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  238|  2.10k|	if (_sc_match_atr(card, eoi_atrs, &card->type) >= 0) {
  ------------------
  |  Branch (238:6): [True: 44, False: 2.06k]
  ------------------
  239|     44|		sc_log(card->ctx, "ATR recognized as Slovenian eID card");
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  240|     44|		LOG_FUNC_RETURN(card->ctx, ATR_MATCH);
  ------------------
  |  |  164|     44|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     44|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     44|	int _ret = r; \
  |  |  |  |  155|     44|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     44|	} else { \
  |  |  |  |  159|     44|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     44|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     44|	} \
  |  |  |  |  162|     44|	return _ret; \
  |  |  |  |  163|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  241|     44|	}
  242|  2.06k|	LOG_FUNC_RETURN(card->ctx, !ATR_MATCH);
  ------------------
  |  |  164|  2.06k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.06k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.06k|	int _ret = r; \
  |  |  |  |  155|  2.06k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.06k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.06k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.06k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.06k|	return _ret; \
  |  |  |  |  163|  2.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|  2.06k|}
card-eoi.c:eoi_init:
  245|     44|static int eoi_init(sc_card_t* card) {
  246|     44|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
  247|     44|	u8 version[6];
  248|     44|	size_t i, j;
  249|     44|	scconf_block **found_blocks, *block;
  250|     44|	int r;
  251|     44|	char *can;
  252|       |
  253|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|       |
  255|     44|	if (eoi_get_data(card, 0x16, version, sizeof(version)) != SC_SUCCESS)
  ------------------
  |  |   28|     44|#define SC_SUCCESS				0
  ------------------
  |  Branch (255:6): [True: 34, False: 10]
  ------------------
  256|     44|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|       |
  258|     10|	if (privdata)
  ------------------
  |  Branch (258:6): [True: 0, False: 10]
  ------------------
  259|     10|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|     10|	privdata = sc_mem_secure_alloc(sizeof(struct eoi_privdata));
  261|     10|	if (!privdata)
  ------------------
  |  Branch (261:6): [True: 0, False: 10]
  ------------------
  262|     10|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  263|       |	/* sc_mem_secure_alloc()-ed memory may not be zeroized */
  264|     10|	memset(privdata, 0, sizeof(struct eoi_privdata));
  265|     10|	card->drv_data = privdata;
  266|       |
  267|     10|	sprintf(privdata->version, "%X%02X.%02X%02X", version[0], version[1], version[2], version[3]);
  268|     10|	sc_log(card->ctx, "App version: %s", privdata->version);
  ------------------
  |  |   71|     10|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  269|       |
  270|     10|	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
  271|     10|	card->sm_ctx.ops.open = eoi_sm_open;
  272|       |
  273|     10|	card->max_send_size = SC_MAX_APDU_DATA_SIZE;
  ------------------
  |  |   35|     10|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  274|     10|	card->max_recv_size = SC_MAX_APDU_RESP_SIZE;
  ------------------
  |  |   36|     10|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  275|       |
  276|     20|	for (i = 0; i < sizeof eoi_curves / sizeof * eoi_curves; ++i) {
  ------------------
  |  Branch (276:14): [True: 10, False: 10]
  ------------------
  277|     10|		r = _sc_card_add_ec_alg(card, eoi_curves[i].len, SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE, 0, &eoi_curves[i].oid);
  ------------------
  |  |  183|     10|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		r = _sc_card_add_ec_alg(card, eoi_curves[i].len, SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDSA_HASH_NONE, 0, &eoi_curves[i].oid);
  ------------------
  |  |  184|     10|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|     10|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  278|     10|		LOG_TEST_GOTO_ERR(card->ctx, r, "Add EC alg failed");
  ------------------
  |  |  184|     10|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     10|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     10|	int _ret = (r); \
  |  |  |  |  178|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|     10|	}
  280|       |
  281|     10|	can = getenv("EOI_CAN");
  282|     10|	if (can)
  ------------------
  |  Branch (282:6): [True: 0, False: 10]
  ------------------
  283|      0|		strlcpy(privdata->can, can, sizeof(privdata->can));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  284|     20|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (284:14): [True: 10, False: 10]
  ------------------
  285|     10|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
  286|     10|					"card_driver", "eoi");
  287|     10|		if (!found_blocks)
  ------------------
  |  Branch (287:7): [True: 0, False: 10]
  ------------------
  288|      0|			continue;
  289|       |
  290|     10|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (290:40): [True: 0, False: 10]
  ------------------
  291|      0|			if (!privdata->can[0]) {
  ------------------
  |  Branch (291:8): [True: 0, False: 0]
  ------------------
  292|      0|				const char *can = scconf_get_str(block, "can", NULL);
  293|      0|				if (can)
  ------------------
  |  Branch (293:9): [True: 0, False: 0]
  ------------------
  294|      0|					strlcpy(privdata->can, can, sizeof(privdata->can));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
  295|      0|			}
  296|      0|		}
  297|     10|		free(found_blocks);
  298|     10|	}
  299|       |
  300|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|       |
  302|      0|err:
  303|      0|	if (privdata) {
  ------------------
  |  Branch (303:6): [True: 0, False: 0]
  ------------------
  304|      0|		sc_mem_clear(privdata, sizeof(struct eoi_privdata));
  305|      0|		sc_mem_secure_free(privdata, sizeof(struct eoi_privdata));
  306|      0|	}
  307|      0|	card->drv_data = NULL;
  308|       |
  309|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  310|      0|}
card-eoi.c:eoi_get_data:
  219|     44|{
  220|     44|	int r;
  221|     44|	sc_apdu_t apdu;
  222|       |
  223|     44|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x01, data_id);
  ------------------
  |  |  292|     44|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  224|     44|	apdu.resp = buf;
  225|     44|	apdu.resplen = len;
  226|     44|	apdu.le = len;
  227|       |
  228|     44|	r = sc_transmit_apdu(card, &apdu);
  229|     44|	LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 2, False: 42]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 42]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  230|     42|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  231|     42|	return r;
  232|     44|}
card-eoi.c:eoi_finish:
  313|     10|{
  314|     10|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
  315|       |
  316|     10|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     10|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     10|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     10|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     10|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|       |
  318|     10|	if (privdata) {
  ------------------
  |  Branch (318:6): [True: 10, False: 0]
  ------------------
  319|     10|		sc_mem_clear(privdata, sizeof(struct eoi_privdata));
  320|     10|		sc_mem_secure_free(privdata, sizeof(struct eoi_privdata));
  321|     10|	}
  322|       |
  323|     10|	card->drv_data = NULL;
  324|       |
  325|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  326|     10|}
card-eoi.c:eoi_select_file:
  329|     61|{
  330|     61|	struct eoi_privdata *privdata = (struct eoi_privdata *)card->drv_data;
  331|     61|	int i;
  332|       |
  333|     61|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     61|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     61|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     61|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     61|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 61]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  334|       |
  335|     61|	if (!privdata)
  ------------------
  |  Branch (335:6): [True: 0, False: 61]
  ------------------
  336|     61|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|       |
  338|     61|	for (i = 0; i < MAX_OBJECTS && privdata->pin_paths[i]; i++) {
  ------------------
  |  |   24|    122|#define MAX_OBJECTS 8
  ------------------
  |  Branch (338:14): [True: 61, False: 0]
  |  Branch (338:33): [True: 0, False: 61]
  ------------------
  339|      0|		if (privdata->pin_paths[i] && sc_compare_path(privdata->pin_paths[i], in_path)) {
  ------------------
  |  Branch (339:7): [True: 0, False: 0]
  |  Branch (339:33): [True: 0, False: 0]
  ------------------
  340|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  341|      0|		}
  342|      0|	}
  343|       |
  344|     61|	LOG_FUNC_RETURN(card->ctx, sc_get_iso7816_driver()->ops->select_file(card, in_path, file_out));
  ------------------
  |  |  164|     61|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     61|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     61|	int _ret = r; \
  |  |  |  |  155|     61|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 61, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     47|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 47, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|     61|}
card-eoi.c:eoi_pin_cmd:
  381|      1|{
  382|      1|	int r;
  383|       |
  384|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  385|       |
  386|      1|	if (data->cmd == SC_PIN_CMD_VERIFY && card->sm_ctx.sm_mode == SM_MODE_NONE) {
  ------------------
  |  |  422|      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 (386:6): [True: 0, False: 1]
  |  Branch (386:40): [True: 0, False: 0]
  ------------------
  387|       |		/* Establish SM before any PIN VERIFY command */
  388|      0|		r = eoi_sm_open(card);
  389|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (389:7): [True: 0, False: 0]
  ------------------
  390|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  391|      0|	}
  392|       |
  393|      1|	if (data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  424|      1|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (393:6): [True: 0, False: 1]
  ------------------
  394|      0|		int pin_reference = data->pin_reference;
  395|      0|		size_t pin2_len = data->pin2.len;
  396|       |		/* Verify PUK, establish SM if necessary */
  397|      0|		data->cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  398|      0|		data->pin_reference = data->puk_reference;
  399|      0|		r = eoi_pin_cmd(card, data, tries_left);
  400|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (400:7): [True: 0, False: 0]
  ------------------
  401|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|       |		/* RESET RETRY COUNTER */
  403|      0|		data->cmd = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  404|      0|		data->pin_reference = 0x80|pin_reference;
  405|      0|		data->pin1.len = 0;
  406|      0|		data->pin2.len = 0;
  407|      0|		r = sc_get_iso7816_driver()->ops->pin_cmd(card, data, tries_left);
  408|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (408:7): [True: 0, False: 0]
  ------------------
  409|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  410|       |		/* Continue as CHANGE PIN */
  411|      0|		data->cmd = SC_PIN_CMD_CHANGE;
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  412|      0|		data->pin2.len = pin2_len;
  413|      0|	}
  414|       |
  415|       |	/* CHANGE PIN command does not send the old PIN as it should already be verified */
  416|      1|	if (data->cmd == SC_PIN_CMD_CHANGE)
  ------------------
  |  |  423|      1|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (416:6): [True: 0, False: 1]
  ------------------
  417|      0|		data->pin1.len = 0;
  418|       |
  419|      1|	LOG_FUNC_RETURN(card->ctx, sc_get_iso7816_driver()->ops->pin_cmd(card, data, tries_left));
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  420|      1|}
card-eoi.c:eoi_card_ctl:
  424|      1|{
  425|      1|	struct sc_card_driver *iso_driver = NULL;
  426|      1|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      1|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  427|       |
  428|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  429|      1|	switch (cmd) {
  430|      0|	case SC_CARDCTL_GET_MODEL:
  ------------------
  |  Branch (430:2): [True: 0, False: 1]
  ------------------
  431|      0|		if (!ptr) {
  ------------------
  |  Branch (431:7): [True: 0, False: 0]
  ------------------
  432|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  433|      0|		} else {
  434|      0|			*(char **)ptr = eoi_model;
  435|      0|			r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  436|      0|		}
  437|      0|		break;
  438|      1|	default:
  ------------------
  |  Branch (438:2): [True: 1, False: 0]
  ------------------
  439|      1|		iso_driver = sc_get_iso7816_driver();
  440|      1|		if (iso_driver->ops->card_ctl != NULL) {
  ------------------
  |  Branch (440:7): [True: 0, False: 1]
  ------------------
  441|      0|			r = sc_get_iso7816_driver()->ops->card_ctl(card, cmd, ptr);
  442|      0|		}
  443|      1|	}
  444|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  445|      1|}

epass2003_refresh:
  926|    674|{
  927|    674|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    674|#define SC_SUCCESS				0
  ------------------
  928|    674|	epass2003_exdata *exdata = NULL;
  929|       |
  930|    674|	if (!card->drv_data)
  ------------------
  |  Branch (930:6): [True: 0, False: 674]
  ------------------
  931|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  932|       |
  933|    674|	exdata = (epass2003_exdata *)card->drv_data;
  934|       |
  935|    674|	if (exdata->sm) {
  ------------------
  |  Branch (935:6): [True: 556, False: 118]
  ------------------
  936|    556|		card->sm_ctx.sm_mode = 0;
  937|    556|		r = mutual_auth(card, g_init_key_enc, g_init_key_mac);
  938|    556|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|    556|#define SM_MODE_TRANSMIT	0x200
  ------------------
  939|    556|		LOG_TEST_RET(card->ctx, r, "mutual_auth failed");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 556, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    556|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    556|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    556|		return _ret; \
  |  |  |  |  172|    556|	} \
  |  |  |  |  173|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  940|    556|	}
  941|       |
  942|    118|	return r;
  943|    674|}
sec_attr_to_entry:
 2226|  2.18k|{
 2227|  2.18k|	int i;
 2228|  2.18k|	int found = 0;
 2229|       |
 2230|  2.18k|	unsigned int method;
 2231|  2.18k|	unsigned long  keyref;
 2232|       |
 2233|  2.18k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.18k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.18k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.18k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.18k]
  |  |  ------------------
  ------------------
 2234|       |
 2235|  2.18k|	switch (file->sec_attr[index]) {
 2236|    281|	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_EVERYONE):
  ------------------
  |  |  737|    281|#define EPASS2003_AC_MAC_NOLESS		0x90
  ------------------
              	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_EVERYONE):
  ------------------
  |  |  732|    281|#define EPASS2003_AC_EVERYONE		0x00
  ------------------
  |  Branch (2236:2): [True: 281, False: 1.90k]
  ------------------
 2237|    281|		method = SC_AC_NONE;
  ------------------
  |  |  150|    281|#define SC_AC_NONE			0x00000000
  ------------------
 2238|    281|		keyref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    281|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2239|    281|		break;
 2240|    215|	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER):
  ------------------
  |  |  737|    215|#define EPASS2003_AC_MAC_NOLESS		0x90
  ------------------
              	case (EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER):
  ------------------
  |  |  733|    215|#define EPASS2003_AC_USER		0x06
  ------------------
  |  Branch (2240:2): [True: 215, False: 1.97k]
  ------------------
 2241|    215|		method = SC_AC_CHV;
  ------------------
  |  |  151|    215|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 2242|    215|		keyref = 1;
 2243|    215|		break;
 2244|  1.68k|	default:
  ------------------
  |  Branch (2244:2): [True: 1.68k, False: 496]
  ------------------
 2245|  1.68k|		sc_log(card->ctx, "Unknown value 0x%2.2x in file->sec_attr[%d]", file->sec_attr[index], index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2246|  1.68k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  1.68k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 2247|  1.68k|		keyref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  1.68k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 2248|  1.68k|		break;
 2249|  2.18k|	}
 2250|       |
 2251|  74.2k|	for (i = 0; i < (int)(sizeof(sec_attr_to_acl_entry) / sizeof(sec_attr_to_acl_entries_t)); i++) {
  ------------------
  |  Branch (2251:14): [True: 72.1k, False: 2.18k]
  ------------------
 2252|  72.1k|		const sec_attr_to_acl_entries_t *e = &sec_attr_to_acl_entry[i];
 2253|       |
 2254|  72.1k|		if (index == e->index && file->type == e->file_type
  ------------------
  |  Branch (2254:7): [True: 4.06k, False: 68.0k]
  |  Branch (2254:28): [True: 1.03k, False: 3.03k]
  ------------------
 2255|  1.03k|				&& file->ef_structure == e->file_ef_structure) {
  ------------------
  |  Branch (2255:8): [True: 171, False: 859]
  ------------------
 2256|       |				/* may add multiple entries */
 2257|    171|			sc_file_add_acl_entry(file, e->op, method, keyref);
 2258|    171|			found++;
 2259|    171|		}
 2260|  72.1k|	}
 2261|  2.18k|	if (found != 1) {
  ------------------
  |  Branch (2261:6): [True: 2.08k, False: 103]
  ------------------
 2262|  2.08k|		sc_log(card->ctx,"found %d entries ", found);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2263|  2.08k|	}
 2264|       |
 2265|  2.18k|	return 0;
 2266|  2.18k|}
sc_get_epass2003_driver:
 3295|  15.3k|{
 3296|  15.3k|	return sc_get_driver();
 3297|  15.3k|}
card-epass2003.c:mutual_auth:
  896|    556|{
  897|    556|	struct sc_context *ctx = card->ctx;
  898|    556|	int r;
  899|    556|	unsigned char result[256] = {0};
  900|    556|	unsigned char ran_key[8] = {0};
  901|    556|	epass2003_exdata *exdata = NULL;
  902|       |
  903|    556|	if (!card->drv_data)
  ------------------
  |  Branch (903:6): [True: 0, False: 556]
  ------------------
  904|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  905|    556|	exdata = (epass2003_exdata *)card->drv_data;
  906|       |
  907|    556|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    556|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    556|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    556|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    556|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 556]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  908|       |
  909|    556|	r = gen_init_key(card, key_enc, key_mac, result, exdata->smtype);
  910|    556|	LOG_TEST_RET(ctx, r, "gen_init_key failed");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 556, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    556|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    556|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    556|		return _ret; \
  |  |  |  |  172|    556|	} \
  |  |  |  |  173|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  911|      0|	if (exdata->bFipsCertification) {
  ------------------
  |  Branch (911:6): [True: 0, False: 0]
  ------------------
  912|      0|		memcpy(ran_key, &result[12+1], 8);
  913|      0|	} else {
  914|      0|		memcpy(ran_key, &result[12], 8);
  915|      0|	}
  916|       |
  917|      0|	r = verify_init_key(card, ran_key, exdata->smtype);
  918|      0|	LOG_TEST_RET(ctx, r, "verify_init_key failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  919|       |
  920|      0|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  921|      0|}
card-epass2003.c:gen_init_key:
  679|    556|{
  680|    556|	int r;
  681|    556|	struct sc_apdu apdu;
  682|    556|	unsigned char data[256] = {0};
  683|    556|	unsigned char tmp_sm;
  684|    556|	unsigned char isFips;
  685|    556|	unsigned long blocksize = 0;
  686|    556|	unsigned char cryptogram[256] = {0}; /* host cryptogram */
  687|    556|	unsigned char iv[16] = {0};
  688|    556|	epass2003_exdata *exdata = NULL;
  689|       |
  690|    556|	if (!card->drv_data)
  ------------------
  |  Branch (690:6): [True: 0, False: 556]
  ------------------
  691|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  692|       |
  693|    556|	exdata = (epass2003_exdata *)card->drv_data;
  694|    556|	isFips = exdata->bFipsCertification;
  695|       |
  696|    556|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    556|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    556|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    556|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    556|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 556]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  697|       |
  698|    556|	if (1 != RAND_bytes(g_random, sizeof(g_random)))
  ------------------
  |  Branch (698:6): [True: 0, False: 556]
  ------------------
  699|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  700|       |
  701|    556|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x50, 0x00, 0x00);
  ------------------
  |  |  294|    556|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  702|    556|	apdu.cla = 0x80;
  703|    556|	apdu.lc = apdu.datalen = sizeof(g_random);
  704|    556|	apdu.data = g_random;	/* host random */
  705|    556|	if (isFips)
  ------------------
  |  Branch (705:6): [True: 22, False: 534]
  ------------------
  706|     22|		apdu.le = apdu.resplen = 29;
  707|    534|	else
  708|    534|		apdu.le = apdu.resplen = 28;
  709|       |
  710|    556|	apdu.resp = result;	/* card random is result[12~19] */
  711|       |
  712|    556|	tmp_sm = exdata->sm;
  713|    556|	exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|    556|#define SM_PLAIN				0x00
  ------------------
  714|    556|	r = epass2003_transmit_apdu(card, &apdu);
  715|    556|	exdata->sm = tmp_sm;
  716|    556|	LOG_TEST_RET(card->ctx, r, "APDU gen_init_key failed");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 538]
  |  |  |  |  ------------------
  |  |  |  |  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|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 538]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  717|       |
  718|    538|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  719|    538|	LOG_TEST_RET(card->ctx, r, "gen_init_key failed");
  ------------------
  |  |  174|    538|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    538|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    538|	int _ret = (r); \
  |  |  |  |  168|    538|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 492, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  169|    492|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    492|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    492|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    492|		return _ret; \
  |  |  |  |  172|    492|	} \
  |  |  |  |  173|    538|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 46]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  720|       |
  721|       |	/* Step 1 - Generate Derivation data */
  722|     46|	if (isFips) {
  ------------------
  |  Branch (722:6): [True: 14, False: 32]
  ------------------
  723|     14|		memset(data, 0x00, 15);
  724|     14|		data[11] = 0x04;
  725|     14|		data[14] = 0x80;
  726|     14|		data[15] = 0x01;
  727|     14|		memcpy(&data[16], g_random, 8);
  728|     14|		memcpy(&data[24], &result[12 + 1], 8);
  729|     32|	} else {
  730|     32|		memcpy(data, &result[16], 4);
  731|     32|		memcpy(&data[4], g_random, 4);
  732|     32|		memcpy(&data[8], &result[12], 4);
  733|     32|		memcpy(&data[12], &g_random[4], 4);
  734|     32|	}
  735|       |
  736|       |	/* Step 2,3 - Create S-ENC/S-MAC Session Key */
  737|     46|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|     46|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (737:6): [True: 31, False: 15]
  ------------------
  738|     31|		if (isFips) {
  ------------------
  |  Branch (738:7): [True: 14, False: 17]
  ------------------
  739|     14|			r = aes128_encrypt_cmac(card, key_enc, 128, data, 32, exdata->sk_enc);
  740|     14|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac enc failed");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  741|     14|			memset(&data[11], 0x06, 1);
  742|     14|			r = aes128_encrypt_cmac(card, key_mac, 128, data, 32, exdata->sk_mac);
  743|     14|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac mac  failed");
  ------------------
  |  |  174|     14|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     14|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     14|	int _ret = (r); \
  |  |  |  |  168|     14|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 14]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     14|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 14]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  744|     17|		} else {
  745|     17|			r = aes128_encrypt_ecb(card, key_enc, 16, data, 16, exdata->sk_enc);
  746|     17|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_ecb enc  failed");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  747|     17|			r = aes128_encrypt_ecb(card, key_mac, 16, data, 16, exdata->sk_mac);
  748|     17|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_ecb mac  failed");
  ------------------
  |  |  174|     17|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     17|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     17|	int _ret = (r); \
  |  |  |  |  168|     17|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     17|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  749|     17|		}
  750|     31|	} else {
  751|     15|		r = des3_encrypt_ecb(card, key_enc, 16, data, 16, exdata->sk_enc);
  752|     15|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_ecb 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  753|     15|		r = des3_encrypt_ecb(card, key_mac, 16, data, 16, exdata->sk_mac);
  754|     15|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_ecb 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  755|     15|	}
  756|       |
  757|     46|	if (isFips) {
  ------------------
  |  Branch (757:6): [True: 14, False: 32]
  ------------------
  758|     14|		data[11] = 0x00;
  759|     14|		data[14] = 0x40;
  760|     32|	} else {
  761|     32|		memcpy(data, g_random, 8);
  762|     32|		memcpy(&data[8], &result[12], 8);
  763|     32|		data[16] = 0x80;
  764|     32|		blocksize = (key_type == KEY_TYPE_AES ? 16 : 8);
  ------------------
  |  |   80|     32|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (764:16): [True: 17, False: 15]
  ------------------
  765|     32|		memset(&data[17], 0x00, blocksize - 1);
  766|     32|	}
  767|       |
  768|       |	/* calculate host cryptogram */
  769|     46|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|     46|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (769:6): [True: 31, False: 15]
  ------------------
  770|     31|		if (isFips) {
  ------------------
  |  Branch (770:7): [True: 14, False: 17]
  ------------------
  771|     14|			r = aes128_encrypt_cmac(card, exdata->sk_enc, 128, data, 32, cryptogram);
  772|     17|		} else {
  773|     17|			r = aes128_encrypt_cbc(card, exdata->sk_enc, 16, iv, data, 16 + blocksize, cryptogram);
  774|     17|		}
  775|     31|	} else {
  776|     15|		r = des3_encrypt_cbc(card, exdata->sk_enc, 16, iv, data, 16 + blocksize, cryptogram);
  777|     15|	}
  778|       |
  779|     46|	LOG_TEST_RET(card->ctx, r, "calculate host cryptogram 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: 0, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     46|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 46]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|       |
  781|       |	/* verify card cryptogram */
  782|     46|	if (isFips) {
  ------------------
  |  Branch (782:6): [True: 14, False: 32]
  ------------------
  783|     14|		if (0 != memcmp(&cryptogram[0], &result[20+1], 8))
  ------------------
  |  Branch (783:7): [True: 14, False: 0]
  ------------------
  784|     14|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  785|     32|	} else {
  786|     32|		if (0 != memcmp(&cryptogram[16], &result[20], 8))
  ------------------
  |  Branch (786:7): [True: 32, False: 0]
  ------------------
  787|     32|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  164|     32|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     32|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     32|	int _ret = r; \
  |  |  |  |  155|     32|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     32|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     32|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 32, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     32|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     32|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  788|     32|	}
  789|      0|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  790|      0|}
card-epass2003.c:epass2003_transmit_apdu:
 1616|    556|{
 1617|    556|	int r;
 1618|       |
 1619|    556|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    556|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    556|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    556|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    556|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 556]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1620|       |
 1621|    556|	r = sc_transmit_apdu_t(card, apdu);
 1622|    556|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    556|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    556|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    556|	int _ret = (r); \
  |  |  |  |  168|    556|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 538]
  |  |  |  |  ------------------
  |  |  |  |  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|    556|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 538]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1623|       |
 1624|    538|	return r;
 1625|    556|}
card-epass2003.c:sc_transmit_apdu_t:
  268|  2.73k|{
  269|  2.73k|	size_t resplen = apdu->resplen;
  270|  2.73k|	int r = sc_transmit_apdu(card, apdu);
  271|  2.73k|	if ((0x69 == apdu->sw1 && 0x85 == apdu->sw2) || (0x69 == apdu->sw1 && 0x88 == apdu->sw2)) {
  ------------------
  |  Branch (271:7): [True: 162, False: 2.57k]
  |  Branch (271:28): [True: 70, False: 92]
  |  Branch (271:51): [True: 92, False: 2.57k]
  |  Branch (271:72): [True: 53, False: 39]
  ------------------
  272|    123|		epass2003_refresh(card);
  273|       |		/* renew old resplen */
  274|    123|		apdu->resplen = resplen;
  275|    123|		r = sc_transmit_apdu(card, apdu);
  276|    123|	}
  277|  2.73k|	return r;
  278|  2.73k|}
card-epass2003.c:aes128_encrypt_cmac:
  415|     64|{
  416|     64|	size_t mactlen = 0;
  417|     64|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     64|#define SC_ERROR_INTERNAL			-1400
  ------------------
  418|     64|#if OPENSSL_VERSION_NUMBER < 0x30000000L
  419|     64|	CMAC_CTX *ctx = CMAC_CTX_new();
  420|     64|	if (ctx == NULL) {
  ------------------
  |  Branch (420:6): [True: 0, False: 64]
  ------------------
  421|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  422|      0|	}
  423|       |
  424|     64|	if (!CMAC_Init(ctx, key, keysize / 8, EVP_aes_128_cbc(), NULL)) {
  ------------------
  |  Branch (424:6): [True: 0, False: 64]
  ------------------
  425|      0|		goto err;
  426|      0|	}
  427|     64|	if (!CMAC_Update(ctx, input, length)) {
  ------------------
  |  Branch (427:6): [True: 0, False: 64]
  ------------------
  428|      0|		goto err;
  429|      0|	}
  430|     64|	if (!CMAC_Final(ctx, output, &mactlen)) {
  ------------------
  |  Branch (430:6): [True: 0, False: 64]
  ------------------
  431|      0|		goto err;
  432|      0|	}
  433|     64|	r = SC_SUCCESS;
  ------------------
  |  |   28|     64|#define SC_SUCCESS				0
  ------------------
  434|     64|err:
  435|     64|	CMAC_CTX_free(ctx);
  436|       |#else
  437|       |	EVP_MAC *mac = EVP_MAC_fetch(card->ctx->ossl3ctx->libctx, "cmac", NULL);
  438|       |	if (mac == NULL) {
  439|       |		return r;
  440|       |	}
  441|       |
  442|       |	OSSL_PARAM params[2] = {0};
  443|       |	params[0] = OSSL_PARAM_construct_utf8_string("cipher","aes-128-cbc", 0);
  444|       |	params[1] = OSSL_PARAM_construct_end();
  445|       |
  446|       |	EVP_MAC_CTX *ctx = EVP_MAC_CTX_new(mac);
  447|       |	if (ctx == NULL) {
  448|       |		EVP_MAC_CTX_free(ctx);
  449|       |		sc_log_openssl(card->ctx);
  450|       |		return r;
  451|       |	}
  452|       |	if (!EVP_MAC_init(ctx, (const unsigned char *)key, keysize / 8, params)) {
  453|       |		sc_log_openssl(card->ctx);
  454|       |		goto err;
  455|       |	}
  456|       |	if (!EVP_MAC_update(ctx, input, length)) {
  457|       |		sc_log_openssl(card->ctx);
  458|       |		goto err;
  459|       |	}
  460|       |	if (!EVP_MAC_final(ctx, output, &mactlen, 16)) {
  461|       |		sc_log_openssl(card->ctx);
  462|       |		goto err;
  463|       |	}
  464|       |	r = SC_SUCCESS;
  465|       |err:
  466|       |	EVP_MAC_CTX_free(ctx);
  467|       |	EVP_MAC_free(mac);
  468|       |#endif
  469|     64|	return r;
  470|     64|}
card-epass2003.c:aes128_encrypt_ecb:
  475|     34|{
  476|     34|	unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
  477|     34|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-ECB");
  478|     34|	int r;
  479|     34|	r = openssl_enc(alg, key, iv, input, length, output);
  480|     34|	sc_evp_cipher_free(alg);
  481|     34|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     34|#define SC_SUCCESS				0
  ------------------
  |  Branch (481:6): [True: 0, False: 34]
  ------------------
  482|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  483|     34|	return r;
  484|     34|}
card-epass2003.c:openssl_enc:
  283|  1.68k|{
  284|  1.68k|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.68k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  285|  1.68k|	EVP_CIPHER_CTX * ctx = NULL;
  286|  1.68k|	int outl = 0;
  287|  1.68k|	int outl_tmp = 0;
  288|  1.68k|	unsigned char iv_tmp[EVP_MAX_IV_LENGTH] = {0};
  289|       |
  290|  1.68k|	memcpy(iv_tmp, iv, EVP_MAX_IV_LENGTH);
  291|  1.68k|	ctx = EVP_CIPHER_CTX_new();
  292|  1.68k|	if (ctx == NULL)
  ------------------
  |  Branch (292:6): [True: 0, False: 1.68k]
  ------------------
  293|      0|		goto out;
  294|       |
  295|  1.68k|	if (!EVP_EncryptInit_ex(ctx, cipher, NULL, key, iv_tmp) || !EVP_CIPHER_CTX_set_padding(ctx, 0))
  ------------------
  |  Branch (295:6): [True: 0, False: 1.68k]
  |  Branch (295:61): [True: 0, False: 1.68k]
  ------------------
  296|      0|		goto out;
  297|       |
  298|  1.68k|	if (!EVP_EncryptUpdate(ctx, output, &outl, input, (int)length))
  ------------------
  |  Branch (298:6): [True: 0, False: 1.68k]
  ------------------
  299|      0|		goto out;
  300|       |
  301|  1.68k|	if (!EVP_EncryptFinal_ex(ctx, output + outl, &outl_tmp))
  ------------------
  |  Branch (301:6): [True: 0, False: 1.68k]
  ------------------
  302|      0|		goto out;
  303|       |
  304|  1.68k|	r = SC_SUCCESS;
  ------------------
  |  |   28|  1.68k|#define SC_SUCCESS				0
  ------------------
  305|  1.68k|out:
  306|  1.68k|	EVP_CIPHER_CTX_free(ctx);
  307|  1.68k|	return r;
  308|  1.68k|}
card-epass2003.c:des3_encrypt_ecb:
  518|     30|{
  519|     30|	unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
  520|     30|	unsigned char bKey[24] = {0};
  521|     30|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-EDE3");
  522|     30|	int r;
  523|       |
  524|     30|	if (keysize == 16) {
  ------------------
  |  Branch (524:6): [True: 30, False: 0]
  ------------------
  525|     30|		memcpy(&bKey[0], key, 16);
  526|     30|		memcpy(&bKey[16], key, 8);
  527|     30|	} else {
  528|      0|		memcpy(&bKey[0], key, 24);
  529|      0|	}
  530|       |
  531|     30|	r = openssl_enc(alg, bKey, iv, input, length, output);
  532|     30|	sc_evp_cipher_free(alg);
  533|     30|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  |  Branch (533:6): [True: 0, False: 30]
  ------------------
  534|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  535|     30|	return r;
  536|     30|}
card-epass2003.c:aes128_encrypt_cbc:
  490|    138|{
  491|    138|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "AES-128-CBC");
  492|    138|	int r;
  493|    138|	r = openssl_enc(alg, key, iv, input, length, output);
  494|    138|	sc_evp_cipher_free(alg);
  495|    138|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    138|#define SC_SUCCESS				0
  ------------------
  |  Branch (495:6): [True: 0, False: 138]
  ------------------
  496|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  497|    138|	return r;
  498|    138|}
card-epass2003.c:des3_encrypt_cbc:
  542|    498|{
  543|    498|	unsigned char bKey[24] = {0};
  544|    498|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-EDE3-CBC");
  545|    498|	int r;
  546|       |
  547|    498|	if (keysize == 16) {
  ------------------
  |  Branch (547:6): [True: 498, False: 0]
  ------------------
  548|    498|		memcpy(&bKey[0], key, 16);
  549|    498|		memcpy(&bKey[16], key, 8);
  550|    498|	} else {
  551|      0|		memcpy(&bKey[0], key, 24);
  552|      0|	}
  553|       |
  554|    498|	r = openssl_enc(EVP_des_ede3_cbc(), bKey, iv, input, length, output);
  555|    498|	sc_evp_cipher_free(alg);
  556|    498|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    498|#define SC_SUCCESS				0
  ------------------
  |  Branch (556:6): [True: 0, False: 498]
  ------------------
  557|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  558|    498|	return r;
  559|    498|}
card-epass2003.c:sc_get_driver:
 3262|  15.3k|{
 3263|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3264|       |
 3265|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (3265:6): [True: 1, False: 15.3k]
  ------------------
 3266|      1|		iso_ops = iso_drv->ops;
 3267|       |
 3268|  15.3k|	epass2003_ops = *iso_ops;
 3269|       |
 3270|  15.3k|	epass2003_ops.match_card = epass2003_match_card;
 3271|  15.3k|	epass2003_ops.init = epass2003_init;
 3272|  15.3k|	epass2003_ops.finish = epass2003_finish;
 3273|  15.3k|	epass2003_ops.write_binary = NULL;
 3274|  15.3k|	epass2003_ops.write_record = NULL;
 3275|  15.3k|	epass2003_ops.select_file = epass2003_select_file;
 3276|       |	epass2003_ops.get_response = NULL;
 3277|  15.3k|	epass2003_ops.restore_security_env = epass2003_restore_security_env;
 3278|  15.3k|	epass2003_ops.set_security_env = epass2003_set_security_env;
 3279|  15.3k|	epass2003_ops.decipher = epass2003_decipher;
 3280|  15.3k|	epass2003_ops.compute_signature = epass2003_decipher;
 3281|  15.3k|	epass2003_ops.create_file = epass2003_create_file;
 3282|  15.3k|	epass2003_ops.delete_file = epass2003_delete_file;
 3283|  15.3k|	epass2003_ops.list_files = epass2003_list_files;
 3284|  15.3k|	epass2003_ops.card_ctl = epass2003_card_ctl;
 3285|  15.3k|	epass2003_ops.process_fci = epass2003_process_fci;
 3286|  15.3k|	epass2003_ops.construct_fci = epass2003_construct_fci;
 3287|  15.3k|	epass2003_ops.pin_cmd = epass2003_pin_cmd;
 3288|  15.3k|	epass2003_ops.check_sw = epass2003_check_sw;
 3289|  15.3k|	epass2003_ops.get_challenge = epass2003_get_challenge;
 3290|  15.3k|	epass2003_ops.logout = epass2003_logout;
 3291|  15.3k|	return &epass2003_drv;
 3292|  15.3k|}
card-epass2003.c:epass2003_match_card:
 1668|  8.91k|{
 1669|  8.91k|	int r;
 1670|       |
 1671|  8.91k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  8.91k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1672|  8.91k|	r = _sc_match_atr(card, epass2003_atrs, &card->type);
 1673|  8.91k|	if (r < 0)
  ------------------
  |  Branch (1673:6): [True: 8.33k, False: 572]
  ------------------
 1674|  8.33k|		return 0;
 1675|       |
 1676|    572|	return 1;
 1677|  8.91k|}
card-epass2003.c:epass2003_init:
 1682|    572|{
 1683|    572|	unsigned int flags;
 1684|    572|	unsigned int ext_flags;
 1685|    572|	unsigned char data[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1686|    572|	size_t datalen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    572|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1687|    572|	epass2003_exdata *exdata = NULL;
 1688|    572|	void *old_drv_data = card->drv_data;
 1689|       |
 1690|    572|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    572|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    572|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    572|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    572|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 572]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1691|       |
 1692|    572|	card->name = "epass2003";
 1693|    572|	card->cla = 0x00;
 1694|    572|	exdata = (epass2003_exdata *)calloc(1, sizeof(epass2003_exdata));
 1695|    572|	if (!exdata)
  ------------------
  |  Branch (1695:6): [True: 0, False: 572]
  ------------------
 1696|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1697|       |
 1698|    572|	card->drv_data = exdata;
 1699|       |
 1700|    572|	exdata->sm = SM_SCP01;
  ------------------
  |  |   92|    572|#define SM_SCP01				0x01
  ------------------
 1701|       |
 1702|       |	/* decide FIPS/Non-FIPS mode */
 1703|    572|	if (SC_SUCCESS != get_data(card, 0x86, data, datalen)) {
  ------------------
  |  |   28|    572|#define SC_SUCCESS				0
  ------------------
  |  Branch (1703:6): [True: 21, False: 551]
  ------------------
 1704|     21|		free(exdata);
 1705|     21|		card->drv_data = old_drv_data;
 1706|     21|		return SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     21|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 1707|     21|	}
 1708|       |
 1709|    551|	if (memcmp(&data[32], "\x87\x01\x01", 3) == 0 && memcmp(&data[0], "\x80\x01\x01", 3) == 0) {
  ------------------
  |  Branch (1709:6): [True: 38, False: 513]
  |  Branch (1709:51): [True: 12, False: 26]
  ------------------
 1710|     12|		exdata->bFipsCertification = 0x01;
 1711|    539|	} else {
 1712|    539|		exdata->bFipsCertification = 0x00;
 1713|    539|	}
 1714|       |
 1715|    551|	if (0x01 == data[2])
  ------------------
  |  Branch (1715:6): [True: 58, False: 493]
  ------------------
 1716|     58|		exdata->smtype = KEY_TYPE_AES;
  ------------------
  |  |   80|     58|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
 1717|    493|	else
 1718|    493|		exdata->smtype = KEY_TYPE_DES;
  ------------------
  |  |   81|    493|#define KEY_TYPE_DES	0x02	/* Non-FIPS mode */
  ------------------
 1719|       |
 1720|    551|	if (0x84 == data[14]) {
  ------------------
  |  Branch (1720:6): [True: 98, False: 453]
  ------------------
 1721|     98|		if (0x00 == data[16]) {
  ------------------
  |  Branch (1721:7): [True: 95, False: 3]
  ------------------
 1722|     95|			exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|     95|#define SM_PLAIN				0x00
  ------------------
 1723|     95|		}
 1724|     98|	}
 1725|       |
 1726|       |	/* mutual authentication */
 1727|    551|	card->max_recv_size = 0xD8;
 1728|    551|	card->max_send_size = 0xE8;
 1729|       |
 1730|    551|	card->sm_ctx.ops.open = epass2003_refresh;
 1731|    551|	card->sm_ctx.ops.get_sm_apdu = epass2003_sm_get_wrapped_apdu;
 1732|    551|	card->sm_ctx.ops.free_sm_apdu = epass2003_sm_free_wrapped_apdu;
 1733|       |
 1734|       |	/* FIXME (VT): rather then set/unset 'g_sm', better to implement filter for APDUs to be wrapped */
 1735|    551|	epass2003_refresh(card);
 1736|       |
 1737|    551|	card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|    551|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1738|       |
 1739|    551|	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  102|    551|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  111|    551|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_ONBOARD_KEY_GEN | SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|    551|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
 1740|       |
 1741|    551|	_sc_card_add_rsa_alg(card, 512, flags, 0);
 1742|    551|	_sc_card_add_rsa_alg(card, 768, flags, 0);
 1743|    551|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1744|    551|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1745|       |
 1746|       |	//set EC Alg Flags
 1747|    551|	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;
  ------------------
  |  |  102|    551|#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;
  ------------------
  |  |  185|    551|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  143|    551|#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;
  ------------------
  |  |  187|    551|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  147|    551|#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;
  ------------------
  |  |  184|    551|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    551|#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;
  ------------------
  |  |  183|    551|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1748|    551|	ext_flags = 0;
 1749|    551|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1750|       |
 1751|    551|	card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  557|    551|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps = SC_CARD_CAP_RNG | SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|    551|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
 1752|       |
 1753|    551|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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: 551, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    551|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 551]
  |  |  |  |  ------------------
  |  |  |  |  157|    551|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    551|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    551|	return _ret; \
  |  |  |  |  163|    551|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1754|    551|}
card-epass2003.c:get_data:
 1630|    579|{
 1631|    579|	int r;
 1632|    579|	struct sc_apdu apdu;
 1633|    579|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1634|    579|	size_t resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|    579|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1635|    579|	epass2003_exdata *exdata = NULL;
 1636|       |
 1637|    579|	if (!card->drv_data)
  ------------------
  |  Branch (1637:6): [True: 0, False: 579]
  ------------------
 1638|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1639|       |
 1640|    579|	exdata = (epass2003_exdata *)card->drv_data;
 1641|       |
 1642|    579|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    579|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    579|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    579|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    579|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 579]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1643|       |
 1644|    579|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, type);
  ------------------
  |  |  292|    579|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1645|    579|	apdu.resp = resp;
 1646|    579|	apdu.le = 0;
 1647|    579|	apdu.resplen = resplen;
 1648|    579|	if (0x86 == type) {
  ------------------
  |  Branch (1648:6): [True: 572, False: 7]
  ------------------
 1649|       |		/* No SM temporarily */
 1650|    572|		unsigned char tmp_sm = exdata->sm;
 1651|    572|		exdata->sm = SM_PLAIN;
  ------------------
  |  |   91|    572|#define SM_PLAIN				0x00
  ------------------
 1652|    572|		r = sc_transmit_apdu(card, &apdu);
 1653|    572|		exdata->sm = tmp_sm;
 1654|    572|	} else {
 1655|      7|		r = sc_transmit_apdu_t(card, &apdu);
 1656|      7|	}
 1657|    579|	LOG_TEST_RET(card->ctx, r, "APDU get_data failed");
  ------------------
  |  |  174|    579|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    579|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    579|	int _ret = (r); \
  |  |  |  |  168|    579|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 574]
  |  |  |  |  ------------------
  |  |  |  |  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|    579|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 574]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1658|    574|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1659|    574|	LOG_TEST_RET(card->ctx, r, "get_data failed");
  ------------------
  |  |  174|    574|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    574|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    574|	int _ret = (r); \
  |  |  |  |  168|    574|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 552]
  |  |  |  |  ------------------
  |  |  |  |  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|    574|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 552]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|       |
 1661|    552|	memcpy(data, resp, datalen);
 1662|    552|	return r;
 1663|    574|}
card-epass2003.c:epass2003_sm_get_wrapped_apdu:
 1565|  1.78k|{
 1566|  1.78k|	struct sc_context *ctx = card->ctx;
 1567|  1.78k|	struct sc_apdu *apdu = NULL;
 1568|  1.78k|	int rv;
 1569|       |
 1570|  1.78k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.78k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.78k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.78k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.78k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1571|  1.78k|	if (!plain || !sm_apdu)
  ------------------
  |  Branch (1571:6): [True: 0, False: 1.78k]
  |  Branch (1571:16): [True: 0, False: 1.78k]
  ------------------
 1572|  1.78k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1573|       |
 1574|  1.78k|	*sm_apdu = NULL;
 1575|       |	//construct new SM apdu from original apdu
 1576|  1.78k|	apdu = calloc(1, sizeof(struct sc_apdu));
 1577|  1.78k|	if (!apdu) {
  ------------------
  |  Branch (1577:6): [True: 0, False: 1.78k]
  ------------------
 1578|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1579|      0|		goto err;
 1580|      0|	}
 1581|  1.78k|	apdu->data = calloc (1, SC_MAX_EXT_APDU_BUFFER_SIZE);
  ------------------
  |  |   37|  1.78k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1582|  1.78k|	if (!apdu->data) {
  ------------------
  |  Branch (1582:6): [True: 0, False: 1.78k]
  ------------------
 1583|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1584|      0|		goto err;
 1585|      0|	}
 1586|  1.78k|	apdu->resp = calloc (1, SC_MAX_EXT_APDU_BUFFER_SIZE);
  ------------------
  |  |   37|  1.78k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1587|  1.78k|	if (!apdu->resp) {
  ------------------
  |  Branch (1587:6): [True: 0, False: 1.78k]
  ------------------
 1588|      0|		rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1589|      0|		goto err;
 1590|      0|	}
 1591|  1.78k|	apdu->datalen = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|  1.78k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1592|  1.78k|	apdu->resplen = SC_MAX_EXT_APDU_BUFFER_SIZE;
  ------------------
  |  |   37|  1.78k|#define SC_MAX_EXT_APDU_BUFFER_SIZE	65538
  ------------------
 1593|       |
 1594|  1.78k|	rv = epass2003_sm_wrap_apdu(card, plain, apdu);
 1595|  1.78k|	if (rv) {
  ------------------
  |  Branch (1595:6): [True: 0, False: 1.78k]
  ------------------
 1596|      0|		rv = epass2003_sm_free_wrapped_apdu(card, NULL, &apdu);
 1597|      0|		if (rv < 0)
  ------------------
  |  Branch (1597:7): [True: 0, False: 0]
  ------------------
 1598|      0|			goto err;
 1599|      0|	}
 1600|       |
 1601|  1.78k|	*sm_apdu = apdu;
 1602|  1.78k|	apdu = NULL;
 1603|  1.78k|err:
 1604|  1.78k|	if (apdu) {
  ------------------
  |  Branch (1604:6): [True: 0, False: 1.78k]
  ------------------
 1605|      0|		free((unsigned char *) apdu->data);
 1606|      0|		free(apdu->resp);
 1607|      0|		free(apdu);
 1608|      0|		apdu = NULL;
 1609|      0|	}
 1610|  1.78k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.78k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1611|  1.78k|}
card-epass2003.c:epass2003_sm_wrap_apdu:
 1278|  1.78k|{
 1279|  1.78k|	unsigned char buf[4096] = {0}; /* APDU buffer */
 1280|  1.78k|	size_t buf_len = sizeof(buf);
 1281|  1.78k|	epass2003_exdata *exdata = NULL;
 1282|       |
 1283|  1.78k|	if (!card->drv_data)
  ------------------
  |  Branch (1283:6): [True: 0, False: 1.78k]
  ------------------
 1284|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1285|       |
 1286|  1.78k|	exdata = (epass2003_exdata *)card->drv_data;
 1287|       |
 1288|  1.78k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.78k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.78k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.78k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.78k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1289|       |
 1290|  1.78k|	if (exdata->sm)
  ------------------
  |  Branch (1290:6): [True: 557, False: 1.22k]
  ------------------
 1291|    557|		plain->cla |= 0x0C;
 1292|       |
 1293|  1.78k|	sm->cse = plain->cse;
 1294|  1.78k|	sm->cla = plain->cla;
 1295|  1.78k|	sm->ins = plain->ins;
 1296|  1.78k|	sm->p1 = plain->p1;
 1297|  1.78k|	sm->p2 = plain->p2;
 1298|  1.78k|	sm->lc = plain->lc;
 1299|  1.78k|	sm->le = plain->le;
 1300|  1.78k|	sm->control = plain->control;
 1301|  1.78k|	sm->flags = plain->flags;
 1302|       |
 1303|  1.78k|	switch (sm->cla & 0x0C) {
 1304|  1.22k|	case 0x00:
  ------------------
  |  Branch (1304:2): [True: 1.22k, False: 557]
  ------------------
 1305|  1.22k|	case 0x04:
  ------------------
  |  Branch (1305:2): [True: 0, False: 1.78k]
  ------------------
 1306|  1.22k|		sm->datalen = plain->datalen;
 1307|  1.22k|		memcpy((void *)sm->data, plain->data, plain->datalen);
 1308|  1.22k|		sm->resplen = plain->resplen;
 1309|  1.22k|		memcpy(sm->resp, plain->resp, plain->resplen);
 1310|  1.22k|		break;
 1311|    557|	case 0x0C:
  ------------------
  |  Branch (1311:2): [True: 557, False: 1.22k]
  ------------------
 1312|    557|		memset(buf, 0, sizeof(buf));
 1313|    557|		if (0 != encode_apdu(card, plain, sm, buf, &buf_len))
  ------------------
  |  Branch (1313:7): [True: 0, False: 557]
  ------------------
 1314|      0|			return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      0|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1315|    557|		break;
 1316|    557|	default:
  ------------------
  |  Branch (1316:2): [True: 0, False: 1.78k]
  ------------------
 1317|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
 1318|  1.78k|	}
 1319|       |
 1320|  1.78k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.78k|#define SC_SUCCESS				0
  ------------------
 1321|  1.78k|}
card-epass2003.c:encode_apdu:
 1189|    557|{
 1190|    557|	size_t block_size = 0;
 1191|    557|	unsigned char dataTLV[4096] = {0};
 1192|    557|	size_t data_tlv_len = 0;
 1193|    557|	unsigned char le_tlv[256] = {0};
 1194|    557|	size_t le_tlv_len = 0;
 1195|    557|	size_t mac_tlv_len = 10;
 1196|    557|	size_t tmp_lc = 0;
 1197|    557|	size_t tmp_le = 0;
 1198|    557|	unsigned char mac_tlv[256] = {0};
 1199|    557|	epass2003_exdata *exdata = NULL;
 1200|       |
 1201|    557|	mac_tlv[0] = 0x8E;
 1202|    557|	mac_tlv[1] = 8;
 1203|       |	/* size_t plain_le = 0; */
 1204|    557|	if (!card->drv_data)
  ------------------
  |  Branch (1204:6): [True: 0, False: 557]
  ------------------
 1205|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1206|    557|	exdata = (epass2003_exdata*)card->drv_data;
 1207|    557|	block_size = (KEY_TYPE_DES == exdata->smtype ? 16 : 8);
  ------------------
  |  |   81|    557|#define KEY_TYPE_DES	0x02	/* Non-FIPS mode */
  ------------------
  |  Branch (1207:16): [True: 484, False: 73]
  ------------------
 1208|       |
 1209|    557|	sm->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|    557|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1210|    557|	apdu_buf[0] = (unsigned char)plain->cla;
 1211|    557|	apdu_buf[1] = (unsigned char)plain->ins;
 1212|    557|	apdu_buf[2] = (unsigned char)plain->p1;
 1213|    557|	apdu_buf[3] = (unsigned char)plain->p2;
 1214|       |	/* plain_le = plain->le; */
 1215|       |	/* padding */
 1216|    557|	if (exdata->bFipsCertification && plain->lc == 0 && apdu_buf[1] == 0x82 && apdu_buf[2] == 0x01) {
  ------------------
  |  Branch (1216:6): [True: 22, False: 535]
  |  Branch (1216:36): [True: 1, False: 21]
  |  Branch (1216:54): [True: 0, False: 1]
  |  Branch (1216:77): [True: 0, False: 0]
  ------------------
 1217|      0|		apdu_buf[4] = 0x00;
 1218|    557|	} else {
 1219|    557|		apdu_buf[4] = 0x80;
 1220|    557|	}
 1221|    557|	memset(&apdu_buf[5], 0x00, block_size - 5);
 1222|       |
 1223|       |	/* Data -> Data' */
 1224|    557|	if (plain->lc != 0)
  ------------------
  |  Branch (1224:6): [True: 553, False: 4]
  ------------------
 1225|    553|		if (0 != construct_data_tlv(card, plain, apdu_buf, dataTLV, &data_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1225:7): [True: 0, False: 553]
  ------------------
 1226|      0|			return -1;
 1227|       |
 1228|    557|	if (plain->le != 0 || (plain->le == 0 && plain->resplen != 0))
  ------------------
  |  Branch (1228:6): [True: 19, False: 538]
  |  Branch (1228:25): [True: 538, False: 0]
  |  Branch (1228:43): [True: 538, False: 0]
  ------------------
 1229|    557|		if (0 != construct_le_tlv(plain, apdu_buf, data_tlv_len, le_tlv,
  ------------------
  |  Branch (1229:7): [True: 0, False: 557]
  ------------------
 1230|    557|				     &le_tlv_len, exdata->smtype))
 1231|      0|			return -1;
 1232|       |
 1233|    557|	if (exdata->bFipsCertification && plain->lc == 0 && apdu_buf[1] == 0x82 && apdu_buf[2] == 0x01) {
  ------------------
  |  Branch (1233:6): [True: 22, False: 535]
  |  Branch (1233:36): [True: 1, False: 21]
  |  Branch (1233:54): [True: 0, False: 1]
  |  Branch (1233:77): [True: 0, False: 0]
  ------------------
 1234|      0|		if (0 != construct_mac_tlv_case1(card, apdu_buf, data_tlv_len, le_tlv_len, mac_tlv, &mac_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1234:7): [True: 0, False: 0]
  ------------------
 1235|      0|			return -1;
 1236|    557|	} else {
 1237|    557|		if (0 != construct_mac_tlv(card, apdu_buf, data_tlv_len, le_tlv_len, mac_tlv, &mac_tlv_len, exdata->smtype))
  ------------------
  |  Branch (1237:7): [True: 0, False: 557]
  ------------------
 1238|      0|			return -1;
 1239|    557|	}
 1240|       |
 1241|    557|	memset(apdu_buf + 4, 0, *apdu_buf_len - 4);
 1242|    557|	sm->lc = sm->datalen = data_tlv_len + le_tlv_len + mac_tlv_len;
 1243|    557|	if (sm->lc > 0xFF) {
  ------------------
  |  Branch (1243:6): [True: 0, False: 557]
  ------------------
 1244|      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
  |  |  ------------------
  ------------------
 1245|      0|		apdu_buf[4] = (unsigned char)((sm->lc) / 0x10000);
 1246|      0|		apdu_buf[5] = (unsigned char)(((sm->lc) / 0x100) % 0x100);
 1247|      0|		apdu_buf[6] = (unsigned char)((sm->lc) % 0x100);
 1248|      0|		tmp_lc = 3;
 1249|    557|	} else {
 1250|    557|		apdu_buf[4] = (unsigned char)sm->lc;
 1251|    557|		tmp_lc = 1;
 1252|    557|	}
 1253|       |
 1254|    557|	memcpy(apdu_buf + 4 + tmp_lc, dataTLV, data_tlv_len);
 1255|    557|	memcpy(apdu_buf + 4 + tmp_lc + data_tlv_len, le_tlv, le_tlv_len);
 1256|    557|	memcpy(apdu_buf + 4 + tmp_lc + data_tlv_len + le_tlv_len, mac_tlv, mac_tlv_len);
 1257|    557|	memcpy((unsigned char *)sm->data, apdu_buf + 4 + tmp_lc, sm->datalen);
 1258|    557|	*apdu_buf_len = 0;
 1259|       |
 1260|    557|	if (4 == le_tlv_len) {
  ------------------
  |  Branch (1260:6): [True: 17, False: 540]
  ------------------
 1261|     17|		sm->cse = SC_APDU_CASE_4_EXT;
  ------------------
  |  |  299|     17|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|     17|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|     17|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1262|     17|		*(apdu_buf + 4 + tmp_lc + sm->lc) = (unsigned char)(plain->le / 0x100);
 1263|     17|		*(apdu_buf + 4 + tmp_lc + sm->lc + 1) = (unsigned char)(plain->le % 0x100);
 1264|     17|		tmp_le = 2;
 1265|    540|	} else if (3 == le_tlv_len) {
  ------------------
  |  Branch (1265:13): [True: 540, False: 0]
  ------------------
 1266|    540|		*(apdu_buf + 4 + tmp_lc + sm->lc) = (unsigned char)plain->le;
 1267|    540|		tmp_le = 1;
 1268|    540|	}
 1269|       |
 1270|    557|	*apdu_buf_len += 4 + tmp_lc + data_tlv_len + le_tlv_len + mac_tlv_len + tmp_le;
 1271|       |	/* sm->le = calc_le(plain_le); */
 1272|    557|	return 0;
 1273|    557|}
card-epass2003.c:construct_data_tlv:
  950|    553|{
  951|    553|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    553|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (951:23): [True: 70, False: 483]
  ------------------
  952|    553|	unsigned char pad[4096] = {0};
  953|    553|	size_t pad_len;
  954|    553|	size_t tlv_more;	/* increased tlv length */
  955|    553|	unsigned char iv[16] = {0};
  956|    553|	epass2003_exdata *exdata = NULL;
  957|    553|	int r = 0;
  958|       |
  959|    553|	if (!card->drv_data)
  ------------------
  |  Branch (959:6): [True: 0, False: 553]
  ------------------
  960|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  961|       |
  962|    553|	exdata = (epass2003_exdata *)card->drv_data;
  963|       |
  964|       |	/* padding */
  965|    553|	apdu_buf[block_size] = 0x87;
  966|    553|	memcpy(pad, apdu->data, apdu->lc);
  967|    553|	pad[apdu->lc] = 0x80;
  968|    553|	if ((apdu->lc + 1) % block_size)
  ------------------
  |  Branch (968:6): [True: 553, False: 0]
  ------------------
  969|    553|		pad_len = ((apdu->lc + 1) / block_size + 1) * block_size;
  970|      0|	else
  971|      0|		pad_len = apdu->lc + 1;
  972|       |
  973|       |	/* encode Lc' */
  974|    553|	if (pad_len > 0x7E) {
  ------------------
  |  Branch (974:6): [True: 0, False: 553]
  ------------------
  975|       |		/* Lc' > 0x7E, use extended APDU */
  976|      0|		apdu_buf[block_size + 1] = 0x82;
  977|      0|		apdu_buf[block_size + 2] = (unsigned char)((pad_len + 1) / 0x100);
  978|      0|		apdu_buf[block_size + 3] = (unsigned char)((pad_len + 1) % 0x100);
  979|      0|		apdu_buf[block_size + 4] = 0x01;
  980|      0|		tlv_more = 5;
  981|    553|	} else {
  982|    553|		apdu_buf[block_size + 1] = (unsigned char)pad_len + 1;
  983|    553|		apdu_buf[block_size + 2] = 0x01;
  984|    553|		tlv_more = 3;
  985|    553|	}
  986|    553|	memcpy(data_tlv, &apdu_buf[block_size], tlv_more);
  987|       |
  988|       |	/* encrypt Data */
  989|    553|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|    553|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (989:6): [True: 70, False: 483]
  ------------------
  990|     70|		r = aes128_encrypt_cbc(card, exdata->sk_enc, 16, iv, pad, pad_len, apdu_buf + block_size + tlv_more);
  991|     70|		LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cbc 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: 0, False: 70]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 70]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  992|    483|	} else {
  993|    483|		r = des3_encrypt_cbc(card, exdata->sk_enc, 16, iv, pad, pad_len, apdu_buf + block_size + tlv_more);
  994|    483|		LOG_TEST_RET(card->ctx, r, "des3_encrypt_cbc 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: 0, False: 483]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    483|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 483]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  995|    483|	}
  996|       |
  997|    553|	memcpy(data_tlv + tlv_more, apdu_buf + block_size + tlv_more, pad_len);
  998|    553|	*data_tlv_len = tlv_more + pad_len;
  999|    553|	return 0;
 1000|    553|}
card-epass2003.c:construct_le_tlv:
 1007|    557|{
 1008|    557|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    557|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1008:23): [True: 73, False: 484]
  ------------------
 1009|       |
 1010|    557|	*(apdu_buf + block_size + data_tlv_len) = 0x97;
 1011|    557|	if (apdu->le > 0x7F) {
  ------------------
  |  Branch (1011:6): [True: 17, False: 540]
  ------------------
 1012|       |		/* Le' > 0x7E, use extended APDU */
 1013|     17|		*(apdu_buf + block_size + data_tlv_len + 1) = 2;
 1014|     17|		*(apdu_buf + block_size + data_tlv_len + 2) = (unsigned char)(apdu->le / 0x100);
 1015|     17|		*(apdu_buf + block_size + data_tlv_len + 3) = (unsigned char)(apdu->le % 0x100);
 1016|     17|		memcpy(le_tlv, apdu_buf + block_size + data_tlv_len, 4);
 1017|     17|		*le_tlv_len = 4;
 1018|    540|	} else {
 1019|    540|		*(apdu_buf + block_size + data_tlv_len + 1) = 1;
 1020|    540|		*(apdu_buf + block_size + data_tlv_len + 2) = (unsigned char)apdu->le;
 1021|    540|		memcpy(le_tlv, apdu_buf + block_size + data_tlv_len, 3);
 1022|    540|		*le_tlv_len = 3;
 1023|    540|	}
 1024|    557|	return 0;
 1025|    557|}
card-epass2003.c:des_encrypt_cbc:
  588|    984|{
  589|    984|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-CBC");
  590|    984|	int r;
  591|       |
  592|    984|	r = openssl_enc(alg, key, iv, input, length, output);
  593|    984|	sc_evp_cipher_free(alg);
  594|    984|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    984|#define SC_SUCCESS				0
  ------------------
  |  Branch (594:6): [True: 0, False: 984]
  ------------------
  595|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  596|    984|	return r;
  597|    984|}
card-epass2003.c:des_decrypt_cbc:
  603|    492|{
  604|    492|	EVP_CIPHER *alg = sc_evp_cipher(card->ctx, "DES-CBC");
  605|    492|	int r;
  606|       |
  607|    492|	r = openssl_dec(alg, key, iv, input, length, output);
  608|    492|	sc_evp_cipher_free(alg);
  609|    492|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    492|#define SC_SUCCESS				0
  ------------------
  |  Branch (609:6): [True: 0, False: 492]
  ------------------
  610|      0|		sc_log_openssl(card->ctx);
  ------------------
  |  |   72|      0|#define sc_log_openssl(ctx)   sc_do_log_openssl(ctx, SC_LOG_DEBUG_DEPS, FILENAME, __LINE__, __FUNCTION__)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  611|    492|	return r;
  612|    492|}
card-epass2003.c:openssl_dec:
  313|    492|{
  314|    492|	int r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    492|#define SC_ERROR_INTERNAL			-1400
  ------------------
  315|    492|	EVP_CIPHER_CTX * ctx = NULL;
  316|    492|	int outl = 0;
  317|    492|	int outl_tmp = 0;
  318|    492|	unsigned char iv_tmp[EVP_MAX_IV_LENGTH] = {0};
  319|       |
  320|    492|	memcpy(iv_tmp, iv, EVP_MAX_IV_LENGTH);
  321|    492|	ctx = EVP_CIPHER_CTX_new();
  322|    492|	if (ctx == NULL)
  ------------------
  |  Branch (322:6): [True: 0, False: 492]
  ------------------
  323|      0|		goto out;
  324|       |
  325|    492|	if (!EVP_DecryptInit_ex(ctx, cipher, NULL, key, iv_tmp) ||
  ------------------
  |  Branch (325:6): [True: 0, False: 492]
  ------------------
  326|    492|			!EVP_CIPHER_CTX_set_padding(ctx, 0))
  ------------------
  |  Branch (326:4): [True: 0, False: 492]
  ------------------
  327|      0|		goto out;
  328|       |
  329|    492|	if (!EVP_DecryptUpdate(ctx, output, &outl, input, (int)length))
  ------------------
  |  Branch (329:6): [True: 0, False: 492]
  ------------------
  330|      0|		goto out;
  331|       |
  332|    492|	if (!EVP_DecryptFinal_ex(ctx, output + outl, &outl_tmp))
  ------------------
  |  Branch (332:6): [True: 0, False: 492]
  ------------------
  333|      0|		goto out;
  334|       |
  335|    492|	r = SC_SUCCESS;
  ------------------
  |  |   28|    492|#define SC_SUCCESS				0
  ------------------
  336|    492|out:
  337|    492|	EVP_CIPHER_CTX_free(ctx);
  338|    492|	return r;
  339|    492|}
card-epass2003.c:construct_mac_tlv:
 1032|    557|{
 1033|    557|	size_t block_size = (KEY_TYPE_AES == key_type ? 16 : 8);
  ------------------
  |  |   80|    557|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1033:23): [True: 73, False: 484]
  ------------------
 1034|    557|	unsigned char mac[4096] = {0};
 1035|    557|	size_t mac_len;
 1036|    557|	unsigned char icv[16] = {0};
 1037|    557|	int r ;
 1038|    557|	int i = (KEY_TYPE_AES == key_type ? 15 : 7);
  ------------------
  |  |   80|    557|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1038:11): [True: 73, False: 484]
  ------------------
 1039|    557|	epass2003_exdata *exdata = NULL;
 1040|       |
 1041|    557|	if (!card->drv_data)
  ------------------
  |  Branch (1041:6): [True: 0, False: 557]
  ------------------
 1042|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1043|       |
 1044|    557|	exdata = (epass2003_exdata *)card->drv_data;
 1045|       |
 1046|    557|	if (0 == data_tlv_len && 0 == le_tlv_len) {
  ------------------
  |  Branch (1046:6): [True: 4, False: 553]
  |  Branch (1046:27): [True: 0, False: 4]
  ------------------
 1047|      0|		mac_len = block_size;
 1048|    557|	} else {
 1049|       |		/* padding */
 1050|    557|		*(apdu_buf + block_size + data_tlv_len + le_tlv_len) = 0x80;
 1051|    557|		if ((data_tlv_len + le_tlv_len + 1) % block_size) {
  ------------------
  |  Branch (1051:7): [True: 548, False: 9]
  ------------------
 1052|    548|			mac_len = (((data_tlv_len + le_tlv_len + 1) / block_size) +
 1053|    548|					1) * block_size + block_size;
 1054|    548|		} else {
 1055|      9|			mac_len = data_tlv_len + le_tlv_len + 1 + block_size;
 1056|      9|		}
 1057|    557|		memset((apdu_buf + block_size + data_tlv_len + le_tlv_len + 1),
 1058|    557|		       0, (mac_len - (data_tlv_len + le_tlv_len + 1)));
 1059|    557|	}
 1060|       |
 1061|       |	/* increase icv */
 1062|    557|	for (; i >= 0; i--) {
  ------------------
  |  Branch (1062:9): [True: 557, False: 0]
  ------------------
 1063|    557|		if (exdata->icv_mac[i] == 0xff) {
  ------------------
  |  Branch (1063:7): [True: 0, False: 557]
  ------------------
 1064|      0|			exdata->icv_mac[i] = 0;
 1065|    557|		} else {
 1066|    557|			exdata->icv_mac[i]++;
 1067|    557|			break;
 1068|    557|		}
 1069|    557|	}
 1070|       |
 1071|       |	/* calculate MAC */
 1072|    557|	memset(icv, 0, sizeof(icv));
 1073|    557|	memcpy(icv, exdata->icv_mac, 16);
 1074|    557|	if (KEY_TYPE_AES == key_type) {
  ------------------
  |  |   80|    557|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1074:6): [True: 73, False: 484]
  ------------------
 1075|     73|		if (exdata->bFipsCertification) {
  ------------------
  |  Branch (1075:7): [True: 22, False: 51]
  ------------------
 1076|    374|			for (int i = 0; i < 16; i++) {
  ------------------
  |  Branch (1076:20): [True: 352, False: 22]
  ------------------
 1077|    352|				apdu_buf[i] = apdu_buf[i] ^ icv[i];
 1078|    352|			}
 1079|     22|			r = aes128_encrypt_cmac(card, exdata->sk_mac, 128, apdu_buf, data_tlv_len + le_tlv_len + block_size, mac);
 1080|     22|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cmac 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: 0, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     22|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1081|     22|			memcpy(mac_tlv + 2, &mac[0 /*ulmacLen-16*/], 8);
 1082|    110|			for (int j = 0; j < 4; j++) {
  ------------------
  |  Branch (1082:20): [True: 88, False: 22]
  ------------------
 1083|     88|				apdu_buf[j] = apdu_buf[j] ^ icv[j];
 1084|     88|			}
 1085|     51|		} else {
 1086|     51|			r = aes128_encrypt_cbc(card, exdata->sk_mac, 16, icv, apdu_buf, mac_len, mac);
 1087|     51|			LOG_TEST_RET(card->ctx, r, "aes128_encrypt_cbc failed");
  ------------------
  |  |  174|     51|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     51|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     51|	int _ret = (r); \
  |  |  |  |  168|     51|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 51]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     51|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 51]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1088|     51|			memcpy(mac_tlv + 2, &mac[mac_len - 16], 8);
 1089|     51|		}
 1090|    484|	} else {
 1091|    484|		unsigned char iv[EVP_MAX_IV_LENGTH] = {0};
 1092|    484|		unsigned char tmp[8] = {0};
 1093|    484|		r = des_encrypt_cbc(card, exdata->sk_mac, 8, icv, apdu_buf, mac_len, mac);
 1094|    484|		LOG_TEST_RET(card->ctx, r, "des_encrypt_cbc 1 failed");
  ------------------
  |  |  174|    484|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    484|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    484|	int _ret = (r); \
  |  |  |  |  168|    484|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 484]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    484|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 484]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1095|    484|		r = des_decrypt_cbc(card, &exdata->sk_mac[8], 8, iv, &mac[mac_len - 8], 8, tmp);
 1096|    484|		LOG_TEST_RET(card->ctx, r, "des_decrypt_cbc failed");
  ------------------
  |  |  174|    484|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    484|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    484|	int _ret = (r); \
  |  |  |  |  168|    484|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 484]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    484|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 484]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1097|    484|		memset(iv, 0x00, sizeof iv);
 1098|    484|		r = des_encrypt_cbc(card, exdata->sk_mac, 8, iv, tmp, 8, mac_tlv + 2);
 1099|    484|		LOG_TEST_RET(card->ctx, r, "des_encrypt_cbc 2 failed");
  ------------------
  |  |  174|    484|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    484|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    484|	int _ret = (r); \
  |  |  |  |  168|    484|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 484]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    484|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 484]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1100|    484|	}
 1101|       |
 1102|    557|	*mac_tlv_len = 2 + 8;
 1103|    557|	return 0;
 1104|    557|}
card-epass2003.c:epass2003_sm_free_wrapped_apdu:
 1533|  1.78k|{
 1534|  1.78k|	struct sc_context *ctx = card->ctx;
 1535|  1.78k|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|  1.78k|#define SC_SUCCESS				0
  ------------------
 1536|       |
 1537|  1.78k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.78k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.78k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.78k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.78k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1538|  1.78k|	if (!sm_apdu)
  ------------------
  |  Branch (1538:6): [True: 0, False: 1.78k]
  ------------------
 1539|  1.78k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1540|  1.78k|	if (!(*sm_apdu))
  ------------------
  |  Branch (1540:6): [True: 0, False: 1.78k]
  ------------------
 1541|  1.78k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1542|       |
 1543|       |
 1544|  1.78k|	if (plain)
  ------------------
  |  Branch (1544:6): [True: 1.78k, False: 0]
  ------------------
 1545|  1.78k|		rv = epass2003_sm_unwrap_apdu(card, *sm_apdu, plain);
 1546|       |
 1547|  1.78k|	if ((*sm_apdu)->data) {
  ------------------
  |  Branch (1547:6): [True: 1.78k, False: 0]
  ------------------
 1548|  1.78k|		unsigned char * p = (unsigned char *)((*sm_apdu)->data);
 1549|  1.78k|		free(p);
 1550|  1.78k|	}
 1551|  1.78k|	if ((*sm_apdu)->resp) {
  ------------------
  |  Branch (1551:6): [True: 1.78k, False: 0]
  ------------------
 1552|  1.78k|		free((*sm_apdu)->resp);
 1553|  1.78k|	}
 1554|       |
 1555|  1.78k|	free(*sm_apdu);
 1556|  1.78k|	*sm_apdu = NULL;
 1557|       |
 1558|  1.78k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  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|    556|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 556, False: 1.22k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1559|  1.78k|}
card-epass2003.c:epass2003_sm_unwrap_apdu:
 1488|  1.78k|{
 1489|  1.78k|	int r;
 1490|  1.78k|	size_t len = 0;
 1491|  1.78k|	epass2003_exdata *exdata = NULL;
 1492|       |
 1493|  1.78k|	if (!card->drv_data)
  ------------------
  |  Branch (1493:6): [True: 0, False: 1.78k]
  ------------------
 1494|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1495|       |
 1496|  1.78k|	exdata = (epass2003_exdata *)card->drv_data;
 1497|       |
 1498|  1.78k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.78k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.78k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.78k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.78k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.78k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1499|       |
 1500|       |	/* verify MAC, and check if SW1,2 match SW1,2 encapsulated in SM */
 1501|  1.78k|	if (exdata->sm) {
  ------------------
  |  Branch (1501:6): [True: 557, False: 1.22k]
  ------------------
 1502|    557|		if (epass2003_check_response_mac_and_sw(card, sm)) {
  ------------------
  |  Branch (1502:7): [True: 556, False: 1]
  ------------------
 1503|    556|			sc_log(card->ctx, "MAC or SW incorrect");
  ------------------
  |  |   71|    556|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1504|    556|			return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    556|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1505|    556|		}
 1506|    557|	}
 1507|  1.22k|	r = sc_check_sw(card, sm->sw1, sm->sw2);
 1508|  1.22k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  1.22k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1508:6): [True: 852, False: 372]
  ------------------
 1509|    852|		if (exdata->sm) {
  ------------------
  |  Branch (1509:7): [True: 0, False: 852]
  ------------------
 1510|      0|			len = plain->resplen;
 1511|      0|			if (0 != decrypt_response(card, sm->resp, sm->resplen, plain->resp, &len))
  ------------------
  |  Branch (1511:8): [True: 0, False: 0]
  ------------------
 1512|      0|				return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      0|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 1513|    852|		} else {
 1514|    852|			memcpy(plain->resp, sm->resp, sm->resplen);
 1515|    852|			len = sm->resplen;
 1516|    852|		}
 1517|    852|	}
 1518|       |
 1519|  1.22k|	plain->resplen = len;
 1520|  1.22k|	plain->sw1 = sm->sw1;
 1521|  1.22k|	plain->sw2 = sm->sw2;
 1522|       |
 1523|  1.22k|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1524|  1.22k|	       "unwrapped APDU: resplen %"SC_FORMAT_LEN_SIZE_T"u, SW %02X%02X",
 1525|  1.22k|	       plain->resplen, plain->sw1, plain->sw2);
 1526|  1.22k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.22k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.22k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.22k|	int _ret = r; \
  |  |  |  |  155|  1.22k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.22k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.22k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.22k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.22k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.22k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.22k|	return _ret; \
  |  |  |  |  163|  1.22k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1527|  1.22k|}
card-epass2003.c:epass2003_check_response_mac_and_sw:
 1325|    557|{
 1326|    557|	unsigned char iv[16];
 1327|    557|	unsigned char *data = NULL, *mac = NULL;
 1328|    557|	size_t blocksize, mac_len;
 1329|    557|	int ret = -1;
 1330|    557|	size_t taglen;
 1331|    557|	const u8 *tag;
 1332|    557|	epass2003_exdata *exdata;
 1333|    557|	unsigned char *in = sm->resp;
 1334|    557|	unsigned char *alt_in;
 1335|    557|	size_t inlen = sm->resplen;
 1336|    557|	size_t len_correction;
 1337|       |
 1338|       |	/* card/ctx/drv_data is already checked by caller */
 1339|    557|	exdata = (epass2003_exdata *)card->drv_data;
 1340|       |
 1341|       |	/* The SM must contain at least TLV encoded SW and MAC fields. */
 1342|    557|	if (inlen < 14 )
  ------------------
  |  Branch (1342:6): [True: 435, False: 122]
  ------------------
 1343|    435|		return ret;
 1344|       |
 1345|       |	/* compare BER-TLV encoded SW (TAG 0x99) and raw SW */
 1346|    122|	alt_in = in;
 1347|    122|	tag = sc_asn1_find_tag(card->ctx, alt_in, inlen, 0x99, &taglen);
 1348|    122|	if (tag == NULL || taglen != 2) {
  ------------------
  |  Branch (1348:6): [True: 55, False: 67]
  |  Branch (1348:21): [True: 29, False: 38]
  ------------------
 1349|       |		/*
 1350|       |		 * It seems that the EPASS2003 firmware has some problem with BER-TLV encoding.
 1351|       |		 * Instead of (correct) TLV 87 81 81 [01 .. ..] incorrect TLV 87 81 [01 .. ..]
 1352|       |		 * is returned. There seems to be some proprietary fix for the faulty encoding
 1353|       |		 * in the decrypt_response() function, similar fix here:
 1354|       |		 */
 1355|     84|		if (0x01 == in[2] && 0x82 != in[1]) {
  ------------------
  |  Branch (1355:7): [True: 68, False: 16]
  |  Branch (1355:24): [True: 67, False: 1]
  ------------------
 1356|     67|			sc_log(card->ctx, "Workaround, wrong BER-TLV ?");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1357|     67|			len_correction = in[1] + 2;
 1358|     67|			if (inlen < len_correction)
  ------------------
  |  Branch (1358:8): [True: 12, False: 55]
  ------------------
 1359|     12|				return ret;
 1360|     55|			inlen -= len_correction;
 1361|     55|			alt_in += len_correction;
 1362|     55|			tag = sc_asn1_find_tag(card->ctx, alt_in, inlen, 0x99, &taglen);
 1363|     55|			if (tag == NULL || taglen != 2)
  ------------------
  |  Branch (1363:8): [True: 37, False: 18]
  |  Branch (1363:23): [True: 7, False: 11]
  ------------------
 1364|     44|				return ret;
 1365|     55|		} else {
 1366|     17|			return ret;
 1367|     17|		}
 1368|     84|	}
 1369|     49|	if (sm->sw1 != tag[0] || sm->sw2 != tag[1])
  ------------------
  |  Branch (1369:6): [True: 21, False: 28]
  |  Branch (1369:27): [True: 12, False: 16]
  ------------------
 1370|     33|		return ret;
 1371|       |
 1372|       |	/* no documentation/real hardware to test, the response is accepted without MAC check */
 1373|     16|	if (exdata->bFipsCertification) {
  ------------------
  |  Branch (1373:6): [True: 0, False: 16]
  ------------------
 1374|      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__
  |  |  ------------------
  ------------------
 1375|      0|		return 0;
 1376|      0|	}
 1377|     16|	tag = sc_asn1_find_tag(card->ctx, alt_in, inlen, 0x8e, &taglen);
 1378|     16|	if (tag == NULL || taglen != 8)
  ------------------
  |  Branch (1378:6): [True: 6, False: 10]
  |  Branch (1378:21): [True: 2, False: 8]
  ------------------
 1379|      8|		return ret;
 1380|       |
 1381|      8|	if (KEY_TYPE_AES == exdata->smtype)
  ------------------
  |  |   80|      8|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1381:6): [True: 0, False: 8]
  ------------------
 1382|      0|		blocksize = 16;
 1383|      8|	else
 1384|      8|		blocksize = 8;
 1385|       |
 1386|      8|	mac_len = tag - in - 2;
 1387|      8|	if (NULL == (data = calloc(1, mac_len + blocksize)))
  ------------------
  |  Branch (1387:6): [True: 0, False: 8]
  ------------------
 1388|      0|		goto end;
 1389|      8|	if (NULL == (mac = malloc(mac_len + blocksize)))
  ------------------
  |  Branch (1389:6): [True: 0, False: 8]
  ------------------
 1390|      0|		goto end;
 1391|       |
 1392|       |	/* copy response to buffer and append padding */
 1393|      8|	memcpy(data, in, mac_len);
 1394|      8|	data[mac_len++] = 0x80;
 1395|       |
 1396|      8|	if (mac_len % blocksize)
  ------------------
  |  Branch (1396:6): [True: 7, False: 1]
  ------------------
 1397|      7|		mac_len += (blocksize - (mac_len % blocksize));
 1398|       |
 1399|       |	/* calculate MAC */
 1400|      8|	memcpy(iv, exdata->icv_mac, blocksize);
 1401|       |
 1402|      8|	if (KEY_TYPE_AES == exdata->smtype) {
  ------------------
  |  |   80|      8|#define KEY_TYPE_AES	0x01	/* FIPS mode */
  ------------------
  |  Branch (1402:6): [True: 0, False: 8]
  ------------------
 1403|      0|		if (aes128_encrypt_cbc(card, exdata->sk_mac, 16, iv, data, mac_len, mac))
  ------------------
  |  Branch (1403:7): [True: 0, False: 0]
  ------------------
 1404|      0|			goto end;
 1405|      8|	} else {
 1406|      8|		uint8_t tmp[8];
 1407|      8|		uint8_t iv0[EVP_MAX_IV_LENGTH];
 1408|      8|		if (des_encrypt_cbc(card, exdata->sk_mac, 8, iv, data, mac_len, mac))
  ------------------
  |  Branch (1408:7): [True: 0, False: 8]
  ------------------
 1409|      0|			goto end;
 1410|      8|		memset(iv0, 0, EVP_MAX_IV_LENGTH);
 1411|      8|		if (des_decrypt_cbc(card, &exdata->sk_mac[8], 8, iv0, &mac[mac_len - 8], 8, tmp))
  ------------------
  |  Branch (1411:7): [True: 0, False: 8]
  ------------------
 1412|      0|			goto end;
 1413|      8|		memset(iv0, 0, EVP_MAX_IV_LENGTH);
 1414|      8|		if (des_encrypt_cbc(card, exdata->sk_mac, 8, iv0, tmp, 8, &mac[mac_len - 8]))
  ------------------
  |  Branch (1414:7): [True: 0, False: 8]
  ------------------
 1415|      0|			goto end;
 1416|      8|	}
 1417|       |	/* compare MAC */
 1418|      8|	if (!memcmp(tag, mac + mac_len - blocksize, 8))
  ------------------
  |  Branch (1418:6): [True: 1, False: 7]
  ------------------
 1419|      1|		ret = 0;
 1420|      8|end:
 1421|      8|	if (data)
  ------------------
  |  Branch (1421:6): [True: 8, False: 0]
  ------------------
 1422|      8|		free(data);
 1423|      8|	if (mac)
  ------------------
  |  Branch (1423:6): [True: 8, False: 0]
  ------------------
 1424|      8|		free(mac);
 1425|      8|	return ret;
 1426|      8|}
card-epass2003.c:epass2003_finish:
 1758|    551|{
 1759|    551|	epass2003_exdata *exdata = (epass2003_exdata *)card->drv_data;
 1760|       |
 1761|    551|	if (exdata)
  ------------------
  |  Branch (1761:6): [True: 551, False: 0]
  ------------------
 1762|    551|		free(exdata);
 1763|    551|	return SC_SUCCESS;
  ------------------
  |  |   28|    551|#define SC_SUCCESS				0
  ------------------
 1764|    551|}
card-epass2003.c:epass2003_select_file:
 2004|  2.74k|{
 2005|  2.74k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.74k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.74k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.74k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.74k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.74k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2006|       |
 2007|  2.74k|	switch (in_path->type) {
 2008|      0|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (2008:2): [True: 0, False: 2.74k]
  ------------------
 2009|      0|		if (in_path->len != 2)
  ------------------
  |  Branch (2009:7): [True: 0, False: 0]
  ------------------
 2010|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2011|      0|		return epass2003_select_fid(card, in_path->value[0], in_path->value[1], file_out);
 2012|  1.07k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  1.07k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2012:2): [True: 1.07k, False: 1.67k]
  ------------------
 2013|  1.07k|		return epass2003_select_aid(card, in_path, file_out);
 2014|  1.67k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  1.67k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (2014:2): [True: 1.67k, False: 1.07k]
  ------------------
 2015|  1.67k|		return epass2003_select_path(card, in_path->value, in_path->len, file_out);
 2016|      0|	default:
  ------------------
  |  Branch (2016:2): [True: 0, False: 2.74k]
  ------------------
 2017|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2018|  2.74k|	}
 2019|  2.74k|}
card-epass2003.c:epass2003_select_fid:
 1917|  2.17k|{
 1918|  2.17k|	int r;
 1919|  2.17k|	sc_file_t *file = NULL;
 1920|  2.17k|	sc_path_t path;
 1921|       |
 1922|  2.17k|	memset(&path, 0, sizeof(path));
 1923|  2.17k|	path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  2.17k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1924|  2.17k|	path.value[0] = id_hi;
 1925|  2.17k|	path.value[1] = id_lo;
 1926|  2.17k|	path.len = 2;
 1927|       |
 1928|  2.17k|	r = epass2003_select_fid_(card, &path, &file);
 1929|  2.17k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.17k|	int _ret = (r); \
  |  |  |  |  168|  2.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.43k, False: 742]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.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|  1.43k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.43k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.43k|		return _ret; \
  |  |  |  |  172|  1.43k|	} \
  |  |  |  |  173|  2.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 742]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1930|       |
 1931|    742|	if (file_out) {
  ------------------
  |  Branch (1931:6): [True: 84, False: 658]
  ------------------
 1932|     84|		*file_out = file;
 1933|    658|	} else {
 1934|    658|		sc_file_free(file);
 1935|    658|	}
 1936|       |
 1937|    742|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    742|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    742|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    742|	int _ret = r; \
  |  |  |  |  155|    742|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 742, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    742|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 742]
  |  |  |  |  ------------------
  |  |  |  |  157|    742|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    742|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    742|	return _ret; \
  |  |  |  |  163|    742|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1938|    742|}
card-epass2003.c:epass2003_select_fid_:
 1822|  2.17k|{
 1823|  2.17k|	struct sc_apdu apdu;
 1824|  2.17k|	u8 buf[SC_MAX_APDU_BUFFER_SIZE] = {0};
 1825|  2.17k|	u8 pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
 1826|  2.17k|	int r;
 1827|  2.17k|	size_t pathlen;
 1828|  2.17k|	sc_file_t *file = NULL;
 1829|       |
 1830|  2.17k|	r = epass2003_hook_path(in_path, 1);
 1831|  2.17k|	LOG_TEST_RET(card->ctx, r, "Can not hook path");
  ------------------
  |  |  174|  2.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.17k|	int _ret = (r); \
  |  |  |  |  168|  2.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2.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|  2.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1832|       |
 1833|  2.17k|	memcpy(path, in_path->value, in_path->len);
 1834|  2.17k|	pathlen = in_path->len;
 1835|       |
 1836|  2.17k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  2.17k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1837|       |
 1838|  2.17k|	switch (in_path->type) {
 1839|  2.17k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  2.17k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1839:2): [True: 2.17k, False: 0]
  ------------------
 1840|  2.17k|		apdu.p1 = 0;
 1841|  2.17k|		if (pathlen != 2)
  ------------------
  |  Branch (1841:7): [True: 0, False: 2.17k]
  ------------------
 1842|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1843|  2.17k|		break;
 1844|  2.17k|	default:
  ------------------
  |  Branch (1844:2): [True: 0, False: 2.17k]
  ------------------
 1845|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1846|  2.17k|	}
 1847|  2.17k|	apdu.p2 = 0;		/* first record, return FCI */
 1848|  2.17k|	apdu.lc = pathlen;
 1849|  2.17k|	apdu.data = path;
 1850|  2.17k|	apdu.datalen = pathlen;
 1851|       |
 1852|  2.17k|	if (file_out != NULL) {
  ------------------
  |  Branch (1852:6): [True: 2.17k, False: 0]
  ------------------
 1853|  2.17k|		apdu.resp = buf;
 1854|  2.17k|		apdu.resplen = sizeof(buf);
 1855|  2.17k|		apdu.le = 0;
 1856|  2.17k|	} else {
 1857|      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 (1857:14): [True: 0, False: 0]
  ------------------
 1858|      0|	}
 1859|       |
 1860|  2.17k|	if (path[0] == 0x29) {	/* TODO:0x29 accords with FID prefix in profile  */
  ------------------
  |  Branch (1860:6): [True: 3, False: 2.17k]
  ------------------
 1861|       |		/* Not allowed to select private key file, so fake fci. */
 1862|       |		/* 62 16 82 02 11 00 83 02 29 00 85 02 08 00 86 08 FF 90 90 90 FF FF FF FF */
 1863|      3|		apdu.resplen = 0x18;
 1864|      3|		memcpy(apdu.resp,
 1865|      3|		       "\x6f\x16\x82\x02\x11\x00\x83\x02\x29\x00\x85\x02\x08\x00\x86\x08\xff\x90\x90\x90\xff\xff\xff\xff",
 1866|      3|		       apdu.resplen);
 1867|      3|		apdu.resp[9] = path[1];
 1868|      3|		apdu.sw1 = 0x90;
 1869|      3|		apdu.sw2 = 0x00;
 1870|      3|	}
 1871|  2.17k|	else {
 1872|  2.17k|		r = sc_transmit_apdu_t(card, &apdu);
 1873|  2.17k|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  2.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.17k|	int _ret = (r); \
  |  |  |  |  168|  2.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 556, False: 1.61k]
  |  |  |  |  ------------------
  |  |  |  |  169|    556|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    556|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    556|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    556|		return _ret; \
  |  |  |  |  172|    556|	} \
  |  |  |  |  173|  2.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.61k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1874|  2.17k|	}
 1875|       |
 1876|  1.62k|	if (file_out == NULL) {
  ------------------
  |  Branch (1876:6): [True: 0, False: 1.62k]
  ------------------
 1877|      0|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (1877:7): [True: 0, False: 0]
  ------------------
 1878|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1879|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1880|      0|	}
 1881|       |
 1882|  1.62k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1883|  1.62k|	if (r)
  ------------------
  |  Branch (1883:6): [True: 817, False: 805]
  ------------------
 1884|  1.62k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    817|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    817|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    817|	int _ret = r; \
  |  |  |  |  155|    817|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 817, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    817|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    817|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 817, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    817|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    817|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    817|	return _ret; \
  |  |  |  |  163|    817|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1885|    805|	if (apdu.resplen < 2)
  ------------------
  |  Branch (1885:6): [True: 36, False: 769]
  ------------------
 1886|    805|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     36|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     36|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     36|	int _ret = r; \
  |  |  |  |  155|     36|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     36|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     36|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 36, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     36|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     36|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     36|	return _ret; \
  |  |  |  |  163|     36|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1887|       |
 1888|    769|	switch (apdu.resp[0]) {
 1889|    742|	case 0x6F:
  ------------------
  |  Branch (1889:2): [True: 742, False: 27]
  ------------------
 1890|    742|		file = sc_file_new();
 1891|    742|		if (file == NULL)
  ------------------
  |  Branch (1891:7): [True: 0, False: 742]
  ------------------
 1892|    742|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1893|    742|		file->path = *in_path;
 1894|    742|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (1894:7): [True: 0, False: 742]
  ------------------
 1895|      0|			sc_file_free(file);
 1896|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1897|      0|		}
 1898|       |
 1899|    742|		if ((size_t) apdu.resp[1] + 2 <= apdu.resplen)
  ------------------
  |  Branch (1899:7): [True: 668, False: 74]
  ------------------
 1900|    668|			card->ops->process_fci(card, file, apdu.resp + 2, apdu.resp[1]);
 1901|    742|		epass2003_hook_file(file, 0);
 1902|    742|		*file_out = file;
 1903|    742|		break;
 1904|     11|	case 0x00:		/* proprietary coding */
  ------------------
  |  Branch (1904:2): [True: 11, False: 758]
  ------------------
 1905|     11|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     11|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     11|	int _ret = r; \
  |  |  |  |  155|     11|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     11|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     11|	return _ret; \
  |  |  |  |  163|     11|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1906|      0|		break;
 1907|     16|	default:
  ------------------
  |  Branch (1907:2): [True: 16, False: 753]
  ------------------
 1908|     16|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1909|    769|	}
 1910|    742|	return 0;
 1911|    769|}
card-epass2003.c:epass2003_hook_path:
 1770|  2.92k|{
 1771|  2.92k|	u8 fid_h = 0;
 1772|  2.92k|	u8 fid_l = 0;
 1773|       |
 1774|  2.92k|	if (!path || path->len < 2)
  ------------------
  |  Branch (1774:6): [True: 0, False: 2.92k]
  |  Branch (1774:15): [True: 0, False: 2.92k]
  ------------------
 1775|      0|		return -1;
 1776|  2.92k|	fid_h = path->value[path->len - 2];
 1777|  2.92k|	fid_l = path->value[path->len - 1];
 1778|       |
 1779|  2.92k|	switch (fid_h) {
 1780|      6|	case 0x29:
  ------------------
  |  Branch (1780:2): [True: 6, False: 2.91k]
  ------------------
 1781|     18|	case 0x30:
  ------------------
  |  Branch (1781:2): [True: 12, False: 2.90k]
  ------------------
 1782|     28|	case 0x31:
  ------------------
  |  Branch (1782:2): [True: 10, False: 2.91k]
  ------------------
 1783|     38|	case 0x32:
  ------------------
  |  Branch (1783:2): [True: 10, False: 2.91k]
  ------------------
 1784|     48|	case 0x33:
  ------------------
  |  Branch (1784:2): [True: 10, False: 2.91k]
  ------------------
 1785|     58|	case 0x34:
  ------------------
  |  Branch (1785:2): [True: 10, False: 2.91k]
  ------------------
 1786|     58|		if (inc)
  ------------------
  |  Branch (1786:7): [True: 34, False: 24]
  ------------------
 1787|     34|			fid_l = fid_l * FID_STEP;
  ------------------
  |  |  741|     34|#define FID_STEP 0x20
  ------------------
 1788|     24|		else
 1789|     24|			fid_l = fid_l / FID_STEP;
  ------------------
  |  |  741|     24|#define FID_STEP 0x20
  ------------------
 1790|     58|		path->value[path->len - 1] = fid_l;
 1791|     58|		return 1;
 1792|  2.86k|	default:
  ------------------
  |  Branch (1792:2): [True: 2.86k, False: 58]
  ------------------
 1793|  2.86k|		break;
 1794|  2.92k|	}
 1795|  2.86k|	return 0;
 1796|  2.92k|}
card-epass2003.c:epass2003_hook_file:
 1801|    742|{
 1802|    742|	int fidl = file->id & 0xff;
 1803|    742|	int fidh = file->id & 0xff00;
 1804|    742|	int rv = 0;
 1805|       |
 1806|    742|	rv = epass2003_hook_path(&file->path, inc);
 1807|       |
 1808|    742|	if (rv > 0) {
  ------------------
  |  Branch (1808:6): [True: 24, False: 718]
  ------------------
 1809|     24|		if (inc)
  ------------------
  |  Branch (1809:7): [True: 0, False: 24]
  ------------------
 1810|      0|			file->id = fidh + fidl * FID_STEP;
  ------------------
  |  |  741|      0|#define FID_STEP 0x20
  ------------------
 1811|     24|		else
 1812|     24|			file->id = fidh + fidl / FID_STEP;
  ------------------
  |  |  741|     24|#define FID_STEP 0x20
  ------------------
 1813|     24|	}
 1814|    742|	if (rv < 0)
  ------------------
  |  Branch (1814:6): [True: 0, False: 742]
  ------------------
 1815|      0|		return rv;
 1816|    742|	return SC_SUCCESS;
  ------------------
  |  |   28|    742|#define SC_SUCCESS				0
  ------------------
 1817|    742|}
card-epass2003.c:epass2003_select_aid:
 1943|  1.07k|{
 1944|  1.07k|	int r = 0;
 1945|       |
 1946|  1.07k|	r = iso_ops->select_file(card, in_path, file_out);
 1947|  1.07k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.07k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.07k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.07k|	int _ret = (r); \
  |  |  |  |  168|  1.07k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.01k, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.01k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.01k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.01k|		return _ret; \
  |  |  |  |  172|  1.01k|	} \
  |  |  |  |  173|  1.07k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 54]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1948|       |
 1949|     54|	if (file_out) {
  ------------------
  |  Branch (1949:6): [True: 0, False: 54]
  ------------------
 1950|      0|		sc_file_t *file = *file_out;
 1951|       |
 1952|      0|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
 1953|      0|		file->ef_structure = SC_FILE_EF_UNKNOWN;
  ------------------
  |  |  220|      0|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
 1954|      0|		file->path.len = 0;
 1955|      0|		file->size = 0;
 1956|       |		/* AID */
 1957|      0|		memcpy(file->name, in_path->value, in_path->len);
 1958|      0|		file->namelen = in_path->len;
 1959|      0|		file->id = 0x0000;
 1960|      0|	}
 1961|       |
 1962|     54|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1963|     54|}
card-epass2003.c:epass2003_select_path:
 1969|  1.67k|{
 1970|  1.67k|	u8 n_pathbuf[SC_MAX_PATH_SIZE];
 1971|  1.67k|	const u8 *path = pathbuf;
 1972|  1.67k|	size_t pathlen = len;
 1973|  1.67k|	unsigned int i;
 1974|  1.67k|	int r;
 1975|       |
 1976|  1.67k|	if (pathlen % 2 != 0 || pathlen > 6 || pathlen <= 0)
  ------------------
  |  Branch (1976:6): [True: 0, False: 1.67k]
  |  Branch (1976:26): [True: 1, False: 1.67k]
  |  Branch (1976:41): [True: 0, False: 1.67k]
  ------------------
 1977|  1.67k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1978|       |
 1979|       |	/* if pathlen == 6 then the first FID must be MF (== 3F00) */
 1980|  1.67k|	if (pathlen == 6 && (path[0] != 0x3f || path[1] != 0x00))
  ------------------
  |  Branch (1980:6): [True: 136, False: 1.53k]
  |  Branch (1980:23): [True: 1, False: 135]
  |  Branch (1980:42): [True: 2, False: 133]
  ------------------
 1981|  1.67k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      3|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      3|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      3|	int _ret = r; \
  |  |  |  |  155|      3|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      3|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      3|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      3|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      3|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      3|	return _ret; \
  |  |  |  |  163|      3|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1982|       |
 1983|       |	/* unify path (the first FID should be MF) */
 1984|  1.66k|	if (path[0] != 0x3f || path[1] != 0x00) {
  ------------------
  |  Branch (1984:6): [True: 81, False: 1.58k]
  |  Branch (1984:25): [True: 3, False: 1.58k]
  ------------------
 1985|     84|		n_pathbuf[0] = 0x3f;
 1986|     84|		n_pathbuf[1] = 0x00;
 1987|     84|		memcpy(n_pathbuf + 2, path, pathlen);
 1988|     84|		path = n_pathbuf;
 1989|     84|		pathlen += 2;
 1990|     84|	}
 1991|       |
 1992|  2.17k|	for (i = 0; i < pathlen - 2; i += 2) {
  ------------------
  |  Branch (1992:14): [True: 1.76k, False: 410]
  ------------------
 1993|  1.76k|		r = epass2003_select_fid(card, path[i], path[i + 1], NULL);
 1994|  1.76k|		LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
  ------------------
  |  |  174|  1.76k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.76k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.76k|	int _ret = (r); \
  |  |  |  |  168|  1.76k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.25k, False: 509]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.25k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.25k|		return _ret; \
  |  |  |  |  172|  1.25k|	} \
  |  |  |  |  173|  1.76k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 509]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1995|  1.76k|	}
 1996|       |
 1997|    410|	return epass2003_select_fid(card, path[pathlen - 2], path[pathlen - 1], file_out);
 1998|  1.66k|}
card-epass2003.c:epass2003_card_ctl:
 3009|      7|{
 3010|      7|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      7|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      7|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      7|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      7|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3011|       |
 3012|      7|	sc_log(card->ctx, "cmd is %0lx", cmd);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3013|      7|	switch (cmd) {
 3014|      0|	case SC_CARDCTL_ENTERSAFE_WRITE_KEY:
  ------------------
  |  Branch (3014:2): [True: 0, False: 7]
  ------------------
 3015|      0|		return epass2003_write_key(card, (sc_epass2003_wkey_data *) ptr);
 3016|      0|	case SC_CARDCTL_ENTERSAFE_GENERATE_KEY:
  ------------------
  |  Branch (3016:2): [True: 0, False: 7]
  ------------------
 3017|      0|		return epass2003_gen_key(card, (sc_epass2003_gen_key_data *) ptr);
 3018|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (3018:2): [True: 0, False: 7]
  ------------------
 3019|      0|		return epass2003_erase_card(card);
 3020|      7|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (3020:2): [True: 7, False: 0]
  ------------------
 3021|      7|		return epass2003_get_serialnr(card, (sc_serial_number_t *) ptr);
 3022|      0|	default:
  ------------------
  |  Branch (3022:2): [True: 0, False: 7]
  ------------------
 3023|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3024|      7|	}
 3025|      7|}
card-epass2003.c:epass2003_get_serialnr:
 2990|      7|{
 2991|      7|	u8 rbuf[8];
 2992|      7|	size_t rbuf_len = sizeof(rbuf);
 2993|       |
 2994|      7|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      7|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      7|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      7|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      7|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2995|       |
 2996|      7|	if (SC_SUCCESS != get_data(card, 0x80, rbuf, rbuf_len))
  ------------------
  |  |   28|      7|#define SC_SUCCESS				0
  ------------------
  |  Branch (2996:6): [True: 6, False: 1]
  ------------------
 2997|      6|		return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|      6|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
 2998|       |
 2999|      1|	card->serialnr.len = serial->len = 8;
 3000|      1|	memcpy(card->serialnr.value, rbuf, 8);
 3001|      1|	memcpy(serial->value, rbuf, 8);
 3002|       |
 3003|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3004|      1|}
card-epass2003.c:epass2003_process_fci:
 2270|    668|{
 2271|    668|	sc_context_t *ctx = card->ctx;
 2272|    668|	size_t taglen, len = buflen;
 2273|    668|	const u8 *tag = NULL, *p = buf;
 2274|       |
 2275|    668|	sc_log(ctx, "processing FCI bytes");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2276|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
 2277|    668|	if (tag != NULL && taglen == 2) {
  ------------------
  |  Branch (2277:6): [True: 95, False: 573]
  |  Branch (2277:21): [True: 84, False: 11]
  ------------------
 2278|     84|		file->id = (tag[0] << 8) | tag[1];
 2279|     84|		sc_log(ctx, "  file identifier: 0x%02X%02X", tag[0], tag[1]);
  ------------------
  |  |   71|     84|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2280|     84|	}
 2281|       |
 2282|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
 2283|    668|	if (tag != NULL && taglen > 0 && taglen < 3) {
  ------------------
  |  Branch (2283:6): [True: 58, False: 610]
  |  Branch (2283:21): [True: 42, False: 16]
  |  Branch (2283:35): [True: 25, False: 17]
  ------------------
 2284|     25|		file->size = tag[0];
 2285|     25|		if (taglen == 2)
  ------------------
  |  Branch (2285:7): [True: 14, False: 11]
  ------------------
 2286|     14|			file->size = (file->size << 8) + tag[1];
 2287|     25|		sc_log(ctx, "  bytes in file: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   71|     25|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2288|     25|			   file->size);
 2289|     25|	}
 2290|       |
 2291|    668|	if (tag == NULL) {
  ------------------
  |  Branch (2291:6): [True: 610, False: 58]
  ------------------
 2292|    610|		tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
 2293|    610|		if (tag != NULL && taglen >= 2) {
  ------------------
  |  Branch (2293:7): [True: 81, False: 529]
  |  Branch (2293:22): [True: 68, False: 13]
  ------------------
 2294|     68|			int bytes = (tag[0] << 8) + tag[1];
 2295|       |
 2296|     68|			sc_log(ctx, "  bytes in file: %d", bytes);
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2297|     68|			file->size = bytes;
 2298|     68|		}
 2299|    610|	}
 2300|       |
 2301|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x82, &taglen);
 2302|    668|	if (tag != NULL) {
  ------------------
  |  Branch (2302:6): [True: 284, False: 384]
  ------------------
 2303|    284|		if (taglen > 0) {
  ------------------
  |  Branch (2303:7): [True: 266, False: 18]
  ------------------
 2304|    266|			unsigned char byte = tag[0];
 2305|    266|			const char *type;
 2306|       |
 2307|    266|			if (byte == 0x38) {
  ------------------
  |  Branch (2307:8): [True: 31, False: 235]
  ------------------
 2308|     31|				type = "DF";
 2309|     31|				file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     31|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2310|    235|			} else if (0x01 <= byte && byte <= 0x07) {
  ------------------
  |  Branch (2310:15): [True: 221, False: 14]
  |  Branch (2310:31): [True: 103, False: 118]
  ------------------
 2311|    103|				type = "working EF";
 2312|    103|				file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    103|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 2313|    103|				switch (byte) {
 2314|     25|				case 0x01:
  ------------------
  |  Branch (2314:5): [True: 25, False: 78]
  ------------------
 2315|     25|					file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|     25|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 2316|     25|					break;
 2317|     31|				case 0x02:
  ------------------
  |  Branch (2317:5): [True: 31, False: 72]
  ------------------
 2318|     31|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     31|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
 2319|     31|					break;
 2320|     18|				case 0x04:
  ------------------
  |  Branch (2320:5): [True: 18, False: 85]
  ------------------
 2321|     18|					file->ef_structure = SC_FILE_EF_LINEAR_FIXED;
  ------------------
  |  |  222|     18|#define SC_FILE_EF_LINEAR_FIXED		0x02
  ------------------
 2322|     18|					break;
 2323|     29|				default:
  ------------------
  |  Branch (2323:5): [True: 29, False: 74]
  ------------------
 2324|     29|					break;
 2325|    103|				}
 2326|       |
 2327|    132|			} else if (0x10 == byte) {
  ------------------
  |  Branch (2327:15): [True: 12, False: 120]
  ------------------
 2328|     12|				type = "BSO";
 2329|     12|				file->type = SC_FILE_TYPE_BSO;
  ------------------
  |  |  217|     12|#define SC_FILE_TYPE_BSO		0x10
  ------------------
 2330|    120|			} else if (0x11 <= byte) {
  ------------------
  |  Branch (2330:15): [True: 102, False: 18]
  ------------------
 2331|    102|				type = "internal EF";
 2332|    102|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    102|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
 2333|    102|				switch (byte) {
 2334|     15|				case 0x11:
  ------------------
  |  Branch (2334:5): [True: 15, False: 87]
  ------------------
 2335|     15|					break;
 2336|     13|				case 0x12:
  ------------------
  |  Branch (2336:5): [True: 13, False: 89]
  ------------------
 2337|     13|					break;
 2338|     74|				default:
  ------------------
  |  Branch (2338:5): [True: 74, False: 28]
  ------------------
 2339|     74|					break;
 2340|    102|				}
 2341|    102|			} else {
 2342|     18|				type = "unknown";
 2343|     18|				file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     18|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
 2344|     18|			}
 2345|    266|			sc_log(ctx, "type %s, EF structure %d", type, byte);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2346|    266|		}
 2347|    284|	}
 2348|       |
 2349|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
 2350|    668|	if (tag != NULL && taglen > 0 && taglen <= 16) {
  ------------------
  |  Branch (2350:6): [True: 55, False: 613]
  |  Branch (2350:21): [True: 41, False: 14]
  |  Branch (2350:35): [True: 31, False: 10]
  ------------------
 2351|     31|		memcpy(file->name, tag, taglen);
 2352|     31|		file->namelen = taglen;
 2353|       |
 2354|     31|		sc_log_hex(ctx, "File name", file->name, file->namelen);
  ------------------
  |  |  129|     31|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     31|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2355|     31|		if (!file->type)
  ------------------
  |  Branch (2355:7): [True: 13, False: 18]
  ------------------
 2356|     13|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|     13|#define SC_FILE_TYPE_DF			0x04
  ------------------
 2357|     31|	}
 2358|       |
 2359|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
 2360|    668|	if (tag != NULL && taglen)
  ------------------
  |  Branch (2360:6): [True: 43, False: 625]
  |  Branch (2360:21): [True: 32, False: 11]
  ------------------
 2361|     32|		sc_file_set_prop_attr(file, tag, taglen);
 2362|    636|	else
 2363|    636|		file->prop_attr_len = 0;
 2364|       |
 2365|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0xA5, &taglen);
 2366|    668|	if (tag != NULL && taglen)
  ------------------
  |  Branch (2366:6): [True: 20, False: 648]
  |  Branch (2366:21): [True: 10, False: 10]
  ------------------
 2367|     10|		sc_file_set_prop_attr(file, tag, taglen);
 2368|       |
 2369|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x86, &taglen);
 2370|    668|	if (tag != NULL && taglen) {
  ------------------
  |  Branch (2370:6): [True: 175, False: 493]
  |  Branch (2370:21): [True: 161, False: 14]
  ------------------
 2371|    161|		unsigned int i;
 2372|    161|		sc_file_set_sec_attr(file, tag, taglen);
 2373|  2.74k|		for (i = 0; i< taglen; i++)
  ------------------
  |  Branch (2373:15): [True: 2.58k, False: 161]
  ------------------
 2374|  2.58k|			if (tag[i] != 0xff) /* skip unused entries */
  ------------------
  |  Branch (2374:8): [True: 2.18k, False: 401]
  ------------------
 2375|  2.18k|				sec_attr_to_entry(card, file, i);
 2376|    161|	}
 2377|       |
 2378|    668|	tag = sc_asn1_find_tag(ctx, p, len, 0x8A, &taglen);
 2379|    668|	if (tag != NULL && taglen == 1) {
  ------------------
  |  Branch (2379:6): [True: 89, False: 579]
  |  Branch (2379:21): [True: 66, False: 23]
  ------------------
 2380|     66|		if (tag[0] == 0x01)
  ------------------
  |  Branch (2380:7): [True: 6, False: 60]
  ------------------
 2381|      6|			file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|      6|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
 2382|     60|		else if (tag[0] == 0x07 || tag[0] == 0x05)
  ------------------
  |  Branch (2382:12): [True: 10, False: 50]
  |  Branch (2382:30): [True: 10, False: 40]
  ------------------
 2383|     20|			file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|     20|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
 2384|     40|		else if (tag[0] == 0x06 || tag[0] == 0x04)
  ------------------
  |  Branch (2384:12): [True: 13, False: 27]
  |  Branch (2384:30): [True: 15, False: 12]
  ------------------
 2385|     28|			file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|     28|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
 2386|     66|	}
 2387|    668|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    668|#define SC_FILE_MAGIC			0x14426950
  ------------------
 2388|       |
 2389|    668|	return 0;
 2390|    668|}
card-epass2003.c:epass2003_pin_cmd:
 3182|      7|{
 3183|      7|	int r;
 3184|      7|	u8 kid;
 3185|      7|	u8 retries = 0;
 3186|      7|	u8 pin_low = 3;
 3187|      7|	unsigned char maxtries = 0;
 3188|       |
 3189|      7|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|      7|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|      7|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|      7|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|      7|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3190|       |
 3191|      7|	internal_sanitize_pin_info(&data->pin1, 0);
 3192|      7|	internal_sanitize_pin_info(&data->pin2, 1);
 3193|      7|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|      7|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 3194|      7|	kid = data->pin_reference;
 3195|       |
 3196|      7|	if (NULL == (unsigned char *)data->pin1.data || 0 == data->pin1.len)
  ------------------
  |  Branch (3196:6): [True: 7, False: 0]
  |  Branch (3196:50): [True: 0, False: 0]
  ------------------
 3197|      7|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_PIN_CODE_INCORRECT);
  ------------------
  |  |  164|      7|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      7|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      7|	int _ret = r; \
  |  |  |  |  155|      7|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      7|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      7|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      7|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      7|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      7|	return _ret; \
  |  |  |  |  163|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3198|       |
 3199|       |	/* get pin retries */
 3200|      0|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  425|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (3200:6): [True: 0, False: 0]
  ------------------
 3201|       |
 3202|      0|		r = get_external_key_retries(card, 0x80 | kid, &retries);
 3203|      0|		if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3203:7): [True: 0, False: 0]
  ------------------
 3204|      0|			data->pin1.tries_left = retries;
 3205|      0|			if (tries_left)
  ------------------
  |  Branch (3205:8): [True: 0, False: 0]
  ------------------
 3206|      0|				*tries_left = retries;
 3207|       |
 3208|      0|			r = get_external_key_maxtries(card, &maxtries);
 3209|      0|			LOG_TEST_RET(card->ctx, r, "get max counter failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3210|       |
 3211|      0|			data->pin1.max_tries = maxtries;
 3212|      0|		}
 3213|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3214|      0|	} else if (data->cmd == SC_PIN_CMD_UNBLOCK) { /* verify */
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (3214:13): [True: 0, False: 0]
  ------------------
 3215|      0|		r = external_key_auth(card, (kid + 1), (unsigned char *)data->pin1.data,
 3216|      0|				data->pin1.len);
 3217|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3218|      0|	} else if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) { /* change */
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	} else if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) { /* change */
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (3218:13): [True: 0, False: 0]
  |  Branch (3218:47): [True: 0, False: 0]
  ------------------
 3219|      0|		r = external_key_auth(card, kid, (unsigned char *)data->pin1.data,
 3220|      0|				data->pin1.len);
 3221|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3222|       |
 3223|      0|		r = update_secret_key(card, 0x04, kid, data->pin2.data,
 3224|      0|				(unsigned long)data->pin2.len);
 3225|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3226|      0|	} else {
 3227|      0|		r = external_key_auth(card, kid, (unsigned char *)data->pin1.data,
 3228|      0|				data->pin1.len);
 3229|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3230|       |
 3231|      0|		r = get_external_key_retries(card, 0x80 | kid, &retries);
 3232|      0|		if (retries < pin_low)
  ------------------
  |  Branch (3232:7): [True: 0, False: 0]
  ------------------
 3233|      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__
  |  |  ------------------
  ------------------
 3234|       |
 3235|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3236|      0|	}
 3237|       |
 3238|      0|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (3238:6): [True: 0, False: 0]
  ------------------
 3239|      0|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|      0|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 3240|      0|	}
 3241|      0|	return r;
 3242|      0|}
card-epass2003.c:internal_sanitize_pin_info:
 3030|     14|{
 3031|     14|	pin->encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|     14|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 3032|     14|	pin->min_length = 4;
 3033|     14|	pin->max_length = 16;
 3034|     14|	pin->pad_length = 16;
 3035|     14|	pin->offset = 5 + num * 16;
 3036|     14|	pin->pad_char = 0x00;
 3037|     14|}
card-epass2003.c:epass2003_check_sw:
  245|  5.63k|{
  246|  5.63k|	const int err_count = sizeof(epass2003_errors)/sizeof(epass2003_errors[0]);
  247|  5.63k|	int i;
  248|       |
  249|       |	/* Handle special cases here */
  250|  5.63k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (250:6): [True: 46, False: 5.59k]
  ------------------
  251|     46|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|     46|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  252|     46|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|     46|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  253|     46|	}
  254|       |
  255|   259k|	for (i = 0; i < err_count; i++) {
  ------------------
  |  Branch (255:14): [True: 258k, False: 218]
  ------------------
  256|   258k|		if (epass2003_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (256:7): [True: 5.37k, False: 253k]
  ------------------
  257|  5.37k|			sc_log(card->ctx, "%s", epass2003_errors[i].errorstr);
  ------------------
  |  |   71|  5.37k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  258|  5.37k|			return epass2003_errors[i].errorno;
  259|  5.37k|		}
  260|   258k|	}
  261|       |
  262|    218|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|    218|#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|    218|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|    218|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  264|  5.59k|}

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

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

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

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

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

sc_invalidate_cache:
  164|  2.62k|{
  165|  2.62k|	if (card) {
  ------------------
  |  Branch (165:6): [True: 2.62k, False: 0]
  ------------------
  166|  2.62k|		struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  167|  2.62k|		sc_file_free(prv->cache.current_ef);
  168|  2.62k|		sc_file_free(prv->cache.current_df);
  169|  2.62k|		memset(&prv->cache, 0, sizeof(prv->cache));
  170|  2.62k|		prv->cache.valid = 0;
  171|  2.62k|	}
  172|  2.62k|}
iasecc_se_get_info:
 1633|    201|{
 1634|    201|	struct sc_context *ctx = card->ctx;
 1635|    201|	struct sc_apdu apdu;
 1636|    201|	unsigned char rbuf[0x100];
 1637|    201|	unsigned char sbuf_iasecc[10] = {
 1638|    201|		0x4D, 0x08, IASECC_SDO_TEMPLATE_TAG, 0x06,
  ------------------
  |  |   29|    201|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 1639|    201|		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   27|    201|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |  102|    201|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
              		IASECC_SDO_TAG_HEADER, IASECC_SDO_CLASS_SE | IASECC_OBJECT_REF_LOCAL,
  ------------------
  |  |   59|    201|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 1640|    201|		se->reference & 0x3F,
 1641|    201|		0x02, IASECC_SDO_CLASS_SE, 0x80
  ------------------
  |  |  102|    201|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 1642|    201|	};
 1643|    201|	int rv;
 1644|       |
 1645|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1646|       |
 1647|    201|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (1647:6): [True: 55, False: 146]
  ------------------
 1648|     55|		rv = iasecc_select_mf(card, NULL);
 1649|     55|		LOG_TEST_RET(ctx, rv, "MF invalid");
  ------------------
  |  |  174|     55|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     55|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     55|	int _ret = (r); \
  |  |  |  |  168|     55|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 44]
  |  |  |  |  ------------------
  |  |  |  |  169|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     11|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     11|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     11|		return _ret; \
  |  |  |  |  172|     11|	} \
  |  |  |  |  173|     55|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 44]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|     55|	}
 1651|       |
 1652|    190|	if (se->reference > IASECC_SE_REF_MAX)
  ------------------
  |  |   66|    190|#define IASECC_SE_REF_MAX	0x0F
  ------------------
  |  Branch (1652:6): [True: 0, False: 190]
  ------------------
 1653|    190|                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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1654|       |
 1655|    190|	rv = iasecc_se_get_info_from_cache(card, se);
 1656|    190|	if (rv == SC_ERROR_OBJECT_NOT_FOUND)   {
  ------------------
  |  |   88|    190|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  |  Branch (1656:6): [True: 188, False: 2]
  ------------------
 1657|    188|		sc_log(ctx, "No SE#%X info in cache, try to use 'GET DATA'", se->reference);
  ------------------
  |  |   71|    188|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1658|       |
 1659|    188|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    188|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1660|    188|		apdu.data = sbuf_iasecc;
 1661|    188|		apdu.datalen = sizeof(sbuf_iasecc);
 1662|    188|		apdu.lc = apdu.datalen;
 1663|    188|		apdu.resp = rbuf;
 1664|    188|		apdu.resplen = sizeof(rbuf);
 1665|    188|		apdu.le = sizeof(rbuf);
 1666|       |
 1667|    188|		rv = sc_transmit_apdu(card, &apdu);
 1668|    188|		LOG_TEST_RET(ctx, rv, "APDU transmit 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: 6, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  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|    188|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 182]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1669|    182|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1670|    182|		LOG_TEST_RET(ctx, rv, "get SE data  error");
  ------------------
  |  |  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: 27, False: 155]
  |  |  |  |  ------------------
  |  |  |  |  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|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 155]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1671|       |
 1672|    155|		rv = iasecc_se_parse(card, apdu.resp, apdu.resplen, se);
 1673|    155|		LOG_TEST_RET(ctx, rv, "cannot parse SE 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: 121, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  169|    121|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    121|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    121|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    121|		return _ret; \
  |  |  |  |  172|    121|	} \
  |  |  |  |  173|    155|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1674|       |
 1675|     34|		rv = iasecc_se_cache_info(card, se);
 1676|     34|		LOG_TEST_RET(ctx, rv, "failed to put SE data into cache");
  ------------------
  |  |  174|     34|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     34|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     34|	int _ret = (r); \
  |  |  |  |  168|     34|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1677|     34|	}
 1678|       |
 1679|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1680|     36|}
sc_get_iasecc_driver:
 3688|  15.3k|{
 3689|  15.3k|	return sc_get_driver();
 3690|  15.3k|}
card-iasecc.c:iasecc_is_cpx:
  590|  12.4k|{
  591|  12.4k|	switch(card->type) {
  592|  2.28k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (592:3): [True: 2.28k, False: 10.1k]
  ------------------
  593|  2.54k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (593:3): [True: 253, False: 12.1k]
  ------------------
  594|  2.54k|			return 1;
  595|  9.90k|		default:
  ------------------
  |  Branch (595:3): [True: 9.90k, False: 2.54k]
  ------------------
  596|  9.90k|			return 0;
  597|  12.4k|	}
  598|       |
  599|      0|	return 0;
  600|  12.4k|}
card-iasecc.c:iasecc_select_mf:
  283|  2.45k|{
  284|  2.45k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  285|  2.45k|	struct sc_context *ctx = card->ctx;
  286|  2.45k|	struct sc_file *mf_file = NULL;
  287|  2.45k|	struct sc_path path;
  288|  2.45k|	int rv;
  289|       |
  290|  2.45k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  2.45k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.45k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.45k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|  2.45k|	if (file_out)
  ------------------
  |  Branch (292:6): [True: 1.46k, False: 994]
  ------------------
  293|  1.46k|		*file_out = NULL;
  294|       |
  295|  2.45k|	memset(&path, 0, sizeof(struct sc_path));
  296|  2.45k|	if (!card->ef_atr || !card->ef_atr->aid.len)   {
  ------------------
  |  Branch (296:6): [True: 152, False: 2.30k]
  |  Branch (296:23): [True: 196, False: 2.10k]
  ------------------
  297|    348|		struct sc_apdu apdu;
  298|    348|		unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  299|       |
  300|       |		/* ISO 'select' command fails when not FCP data returned */
  301|    348|		sc_format_path("3F00", &path);
  302|    348|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    348|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  303|       |
  304|    348|		sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 0x00, 0x0C);
  ------------------
  |  |  293|    348|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  305|    348|		apdu.lc = path.len;
  306|    348|		apdu.data = path.value;
  307|    348|		apdu.datalen = path.len;
  308|    348|		apdu.resplen = sizeof(apdu_resp);
  309|    348|		apdu.resp = apdu_resp;
  310|       |
  311|       |		/* TODO: this might be obsolete now that 0x0c (no data) is default for p2 */
  312|    348|		if (card->type == SC_CARD_TYPE_IASECC_MI2)
  ------------------
  |  Branch (312:7): [True: 56, False: 292]
  ------------------
  313|     56|			apdu.p2 = 0x04;
  314|       |
  315|    348|		rv = sc_transmit_apdu(card, &apdu);
  316|    348|		LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    348|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    348|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    348|	int _ret = (r); \
  |  |  |  |  168|    348|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 345]
  |  |  |  |  ------------------
  |  |  |  |  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|    348|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 345]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  317|    345|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  318|    345|		LOG_TEST_RET(card->ctx, rv, "Cannot select MF");
  ------------------
  |  |  174|    345|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    345|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    345|	int _ret = (r); \
  |  |  |  |  168|    345|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 160, False: 185]
  |  |  |  |  ------------------
  |  |  |  |  169|    160|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    160|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    160|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    160|		return _ret; \
  |  |  |  |  172|    160|	} \
  |  |  |  |  173|    345|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 185]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  319|    345|	}
  320|  2.10k|	else   {
  321|  2.10k|		memset(&path, 0, sizeof(path));
  322|  2.10k|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  2.10k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  323|  2.10k|		memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  324|  2.10k|		path.len = card->ef_atr->aid.len;
  325|  2.10k|		rv = iasecc_select_file(card, &path, file_out);
  326|  2.10k|		LOG_TEST_RET(ctx, rv, "Unable to ROOT selection");
  ------------------
  |  |  174|  2.10k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.10k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.10k|	int _ret = (r); \
  |  |  |  |  168|  2.10k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.69k, False: 412]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.69k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.69k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.69k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.69k|		return _ret; \
  |  |  |  |  172|  1.69k|	} \
  |  |  |  |  173|  2.10k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 412]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  327|  2.10k|	}
  328|       |
  329|       |	/* Ignore the FCP of the MF, because:
  330|       |	 * - some cards do not return it;
  331|       |	 * - there is not need of it -- create/delete of the files in MF is not envisaged.
  332|       |	 */
  333|    597|	mf_file = sc_file_new();
  334|    597|	if (mf_file == NULL)
  ------------------
  |  Branch (334:6): [True: 0, False: 597]
  ------------------
  335|    597|		LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "Cannot allocate MF file");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  336|    597|	mf_file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    597|#define SC_FILE_TYPE_DF			0x04
  ------------------
  337|    597|	mf_file->path = path;
  338|       |
  339|    597|	sc_invalidate_cache(card);
  340|    597|	sc_file_dup(&prv->cache.current_df, mf_file);
  341|    597|	prv->cache.valid = 1;
  342|       |
  343|    597|	if (file_out && *file_out == NULL)
  ------------------
  |  Branch (343:6): [True: 421, False: 176]
  |  Branch (343:18): [True: 350, False: 71]
  ------------------
  344|    350|		*file_out = mf_file;
  345|    247|	else
  346|    247|		sc_file_free(mf_file);
  347|       |
  348|    597|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    597|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    597|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    597|	int _ret = r; \
  |  |  |  |  155|    597|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 597, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    597|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 597]
  |  |  |  |  ------------------
  |  |  |  |  157|    597|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    597|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    597|	return _ret; \
  |  |  |  |  163|    597|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  349|    597|}
card-iasecc.c:iasecc_select_file:
  877|  6.79k|{
  878|  6.79k|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  879|  6.79k|	struct sc_context *ctx = card->ctx;
  880|  6.79k|	struct sc_path lpath;
  881|  6.79k|	int rv, ii;
  882|       |
  883|  6.79k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  6.79k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.79k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.79k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.79k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.79k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  884|  6.79k|	memcpy(&lpath, path, sizeof(struct sc_path));
  885|  6.79k|	if (file_out)
  ------------------
  |  Branch (885:6): [True: 3.25k, False: 3.54k]
  ------------------
  886|  3.25k|		*file_out = NULL;
  887|       |
  888|  6.79k|	sc_log(ctx,
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  889|  6.79k|	       "iasecc_select_file(card:%p) path.len %"SC_FORMAT_LEN_SIZE_T"u; path.type %i; aid_len %"SC_FORMAT_LEN_SIZE_T"u",
  890|  6.79k|	       card, path->len, path->type, path->aid.len);
  891|  6.79k|	sc_log(ctx, "iasecc_select_file() path:%s", sc_print_path(path));
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  892|       |
  893|  6.79k|	if ((!iasecc_is_cpx(card)) &&
  ------------------
  |  Branch (893:6): [True: 6.05k, False: 742]
  ------------------
  894|  6.05k|	    (card->type != SC_CARD_TYPE_IASECC_GEMALTO) &&
  ------------------
  |  Branch (894:6): [True: 5.97k, False: 77]
  ------------------
  895|  5.97k|	    (path->type != SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  11.9k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (895:7): [True: 2.37k, False: 3.59k]
  ------------------
  896|  2.37k|			&& lpath.len >= 2
  ------------------
  |  Branch (896:7): [True: 2.37k, False: 0]
  ------------------
  897|  2.37k|			&& lpath.value[0] == 0x3F && lpath.value[1] == 0x00))   {
  ------------------
  |  Branch (897:7): [True: 2.33k, False: 45]
  |  Branch (897:33): [True: 2.32k, False: 9]
  ------------------
  898|  2.32k|		sc_log(ctx, "EF.ATR(aid:'%s')", card->ef_atr ? sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len) : "");
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 2.18k, False: 141]
  |  |  ------------------
  ------------------
  899|       |
  900|  2.32k|		rv = iasecc_select_mf(card, file_out);
  901|  2.32k|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|  2.32k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.32k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.32k|	int _ret = (r); \
  |  |  |  |  168|  2.32k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.79k, False: 533]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.32k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 533]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  902|       |
  903|    533|		memmove(&lpath.value[0], &lpath.value[2], lpath.len - 2);
  904|    533|		lpath.len -=  2;
  905|    533|	}
  906|       |
  907|  5.00k|	if (lpath.aid.len)	{
  ------------------
  |  Branch (907:6): [True: 8, False: 4.99k]
  ------------------
  908|      8|		struct sc_file *file = NULL;
  909|      8|		struct sc_path ppath;
  910|       |
  911|      8|		sc_log(ctx,
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  912|      8|		       "iasecc_select_file() select parent AID:%p/%"SC_FORMAT_LEN_SIZE_T"u",
  913|      8|		       lpath.aid.value, lpath.aid.len);
  914|      8|		sc_log(ctx, "iasecc_select_file() select parent AID:%s", sc_dump_hex(lpath.aid.value, lpath.aid.len));
  ------------------
  |  |   71|      8|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  915|      8|		memset(&ppath, 0, sizeof(ppath));
  916|      8|		memcpy(ppath.value, lpath.aid.value, lpath.aid.len);
  917|      8|		ppath.len = lpath.aid.len;
  918|      8|		ppath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      8|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  919|       |
  920|      8|		rv = iasecc_select_file(card, &ppath, &file);
  921|      8|		LOG_TEST_GOTO_ERR(ctx, rv, "select AID path failed");
  ------------------
  |  |  184|      8|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      8|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      8|	int _ret = (r); \
  |  |  |  |  178|      8|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  922|       |
  923|      4|		if (file_out) {
  ------------------
  |  Branch (923:7): [True: 4, False: 0]
  ------------------
  924|      4|			sc_file_free(*file_out);
  925|      4|			*file_out = file;
  926|      4|		} else {
  927|      0|			sc_file_free(file);
  928|      0|		}
  929|       |
  930|      4|		if (lpath.type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      4|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (930:7): [True: 0, False: 4]
  ------------------
  931|      0|			lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  932|      4|	}
  933|       |
  934|  4.99k|	if (lpath.type == SC_PATH_TYPE_PATH)
  ------------------
  |  |  119|  4.99k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (934:6): [True: 1.23k, False: 3.75k]
  ------------------
  935|  1.23k|		lpath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|  1.23k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  936|       |
  937|  4.99k|	if (!lpath.len) {
  ------------------
  |  Branch (937:6): [True: 10, False: 4.98k]
  ------------------
  938|     10|		if (file_out) {
  ------------------
  |  Branch (938:7): [True: 3, False: 7]
  ------------------
  939|      3|			sc_file_free(*file_out);
  940|      3|			*file_out = NULL;
  941|      3|		}
  942|     10|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  943|     10|	}
  944|       |
  945|  4.98k|	do   {
  946|  4.98k|		struct sc_apdu apdu;
  947|  4.98k|		struct sc_file *file = NULL;
  948|  4.98k|		unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
  949|  4.98k|		size_t pathlen = lpath.len;
  950|       |
  951|  4.98k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|  4.98k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  952|       |
  953|  4.98k|		if (card->type != SC_CARD_TYPE_IASECC_GEMALTO
  ------------------
  |  Branch (953:7): [True: 4.91k, False: 77]
  ------------------
  954|  4.91k|				&& card->type != SC_CARD_TYPE_IASECC_OBERTHUR
  ------------------
  |  Branch (954:8): [True: 4.76k, False: 149]
  ------------------
  955|  4.76k|				&& card->type != SC_CARD_TYPE_IASECC_SAGEM
  ------------------
  |  Branch (955:8): [True: 4.70k, False: 61]
  ------------------
  956|  4.70k|				&& card->type != SC_CARD_TYPE_IASECC_AMOS
  ------------------
  |  Branch (956:8): [True: 4.66k, False: 38]
  ------------------
  957|  4.66k|				&& card->type != SC_CARD_TYPE_IASECC_MI
  ------------------
  |  Branch (957:8): [True: 783, False: 3.88k]
  ------------------
  958|    783|				&& card->type != SC_CARD_TYPE_IASECC_MI2
  ------------------
  |  Branch (958:8): [True: 739, False: 44]
  ------------------
  959|    739|				&& !iasecc_is_cpx(card)) {
  ------------------
  |  Branch (959:8): [True: 0, False: 739]
  ------------------
  960|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  961|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  962|      0|		}
  963|       |
  964|  4.98k|		if (lpath.type == SC_PATH_TYPE_FILE_ID)   {
  ------------------
  |  |  117|  4.98k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (964:7): [True: 3, False: 4.98k]
  ------------------
  965|      3|			apdu.p1 = 0x02;
  966|      3|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (966:8): [True: 0, False: 3]
  ------------------
  967|      0|				apdu.p1 = 0x01;
  968|      3|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (968:8): [True: 0, False: 3]
  ------------------
  969|      3|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (969:8): [True: 0, False: 3]
  ------------------
  970|      3|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (970:8): [True: 0, False: 3]
  ------------------
  971|      3|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (971:8): [True: 0, False: 3]
  ------------------
  972|      3|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (972:8): [True: 0, False: 3]
  ------------------
  973|      3|			    iasecc_is_cpx(card)
  ------------------
  |  Branch (973:8): [True: 3, False: 0]
  ------------------
  974|      3|			    )   {
  975|      3|				apdu.p2 = 0x04;
  976|      3|			}
  977|      3|		}
  978|  4.98k|		else if (lpath.type == SC_PATH_TYPE_FROM_CURRENT)  {
  ------------------
  |  |  122|  4.98k|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (978:12): [True: 1.23k, False: 3.75k]
  ------------------
  979|  1.23k|			apdu.p1 = 0x09;
  980|  1.23k|			if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (980:8): [True: 63, False: 1.17k]
  ------------------
  981|  1.17k|			    card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (981:8): [True: 24, False: 1.14k]
  ------------------
  982|  1.14k|			    card->type == SC_CARD_TYPE_IASECC_MI ||
  ------------------
  |  Branch (982:8): [True: 427, False: 719]
  ------------------
  983|    719|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (983:8): [True: 21, False: 698]
  ------------------
  984|    698|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (984:8): [True: 69, False: 629]
  ------------------
  985|  1.19k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (985:8): [True: 588, False: 41]
  ------------------
  986|  1.19k|				apdu.p2 = 0x04;
  987|  1.19k|			}
  988|  1.23k|		}
  989|  3.75k|		else if (lpath.type == SC_PATH_TYPE_PARENT)   {
  ------------------
  |  |  123|  3.75k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (989:12): [True: 0, False: 3.75k]
  ------------------
  990|      0|			apdu.p1 = 0x03;
  991|      0|			pathlen = 0;
  992|      0|			apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  993|      0|		}
  994|  3.75k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  3.75k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (994:12): [True: 3.75k, False: 0]
  ------------------
  995|  3.75k|			apdu.p1 = 0x04;
  996|  3.75k|			if (card->type == SC_CARD_TYPE_IASECC_AMOS ||
  ------------------
  |  Branch (996:8): [True: 14, False: 3.73k]
  ------------------
  997|  3.73k|			    card->type == SC_CARD_TYPE_IASECC_MI2 ||
  ------------------
  |  Branch (997:8): [True: 23, False: 3.71k]
  ------------------
  998|  3.71k|			    card->type == SC_CARD_TYPE_IASECC_OBERTHUR ||
  ------------------
  |  Branch (998:8): [True: 86, False: 3.62k]
  ------------------
  999|  3.62k|			    card->type == SC_CARD_TYPE_IASECC_GEMALTO ||
  ------------------
  |  Branch (999:8): [True: 8, False: 3.62k]
  ------------------
 1000|  3.62k|			    iasecc_is_cpx(card)) {
  ------------------
  |  Branch (1000:8): [True: 148, False: 3.47k]
  ------------------
 1001|    279|				apdu.p2 = 0x04;
 1002|    279|			}
 1003|  3.75k|		}
 1004|      0|		else   {
 1005|      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__
  |  |  ------------------
  ------------------
 1006|      0|			rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1007|      0|			LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() invalid PATH type");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1008|      0|		}
 1009|       |
 1010|  5.05k|		for (ii=0; ii<2; ii++)   {
  ------------------
  |  Branch (1010:14): [True: 5.05k, False: 0]
  ------------------
 1011|  5.05k|			apdu.lc = pathlen;
 1012|  5.05k|			apdu.data = lpath.value;
 1013|  5.05k|			apdu.datalen = pathlen;
 1014|       |
 1015|  5.05k|			apdu.resp = rbuf;
 1016|  5.05k|			apdu.resplen = sizeof(rbuf);
 1017|  5.05k|			apdu.le = 256;
 1018|       |
 1019|  5.05k|			rv = sc_transmit_apdu(card, &apdu);
 1020|  5.05k|			LOG_TEST_GOTO_ERR(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  184|  5.05k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  5.05k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  5.05k|	int _ret = (r); \
  |  |  |  |  178|  5.05k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 21, False: 5.03k]
  |  |  |  |  ------------------
  |  |  |  |  179|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     21|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     21|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     21|		goto err; \
  |  |  |  |  182|     21|	} \
  |  |  |  |  183|  5.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 5.03k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1021|  5.03k|			rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1022|  5.03k|			if (rv == SC_ERROR_INCORRECT_PARAMETERS &&
  ------------------
  |  |   55|  10.0k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (1022:8): [True: 107, False: 4.92k]
  ------------------
 1023|    107|					lpath.type == SC_PATH_TYPE_DF_NAME && apdu.p2 == 0x00)   {
  ------------------
  |  |  118|  5.14k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1023:6): [True: 88, False: 19]
  |  Branch (1023:44): [True: 68, False: 20]
  ------------------
 1024|     68|				sc_log(ctx, "Warning: SC_ERROR_INCORRECT_PARAMETERS for SC_PATH_TYPE_DF_NAME, try again with P2=0x0C");
  ------------------
  |  |   71|     68|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1025|     68|				apdu.p2 = 0x0C;
 1026|     68|				continue;
 1027|     68|			}
 1028|       |
 1029|  4.96k|			if (ii)   {
  ------------------
  |  Branch (1029:8): [True: 68, False: 4.89k]
  ------------------
 1030|       |				/* 'SELECT AID' do not returned FCP. Try to emulate. */
 1031|     68|				apdu.resplen = sizeof(rbuf);
 1032|     68|				rv = iasecc_emulate_fcp(ctx, &apdu);
 1033|     68|				LOG_TEST_GOTO_ERR(ctx, rv, "Failed to emulate DF FCP");
  ------------------
  |  |  184|     68|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     68|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     68|	int _ret = (r); \
  |  |  |  |  178|     68|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1034|     68|			}
 1035|       |
 1036|  4.96k|			break;
 1037|  4.96k|		}
 1038|       |
 1039|  4.96k|		LOG_TEST_GOTO_ERR(ctx, rv, "iasecc_select_file() check SW failed");
  ------------------
  |  |  184|  4.96k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.96k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.96k|	int _ret = (r); \
  |  |  |  |  178|  4.96k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2.77k, False: 2.19k]
  |  |  |  |  ------------------
  |  |  |  |  179|  2.77k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.77k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  2.77k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  2.77k|		goto err; \
  |  |  |  |  182|  2.77k|	} \
  |  |  |  |  183|  4.96k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1040|       |
 1041|  2.19k|		sc_log(ctx,
  ------------------
  |  |   71|  2.19k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1042|  2.19k|		       "iasecc_select_file() apdu.resp %"SC_FORMAT_LEN_SIZE_T"u",
 1043|  2.19k|		       apdu.resplen);
 1044|  2.19k|		if (apdu.resplen)   {
  ------------------
  |  Branch (1044:7): [True: 949, False: 1.24k]
  ------------------
 1045|    949|			sc_log(ctx, "apdu.resp %02X:%02X:%02X...", apdu.resp[0], apdu.resp[1], apdu.resp[2]);
  ------------------
  |  |   71|    949|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1046|       |
 1047|    949|			switch (apdu.resp[0]) {
 1048|     81|			case 0x62:
  ------------------
  |  Branch (1048:4): [True: 81, False: 868]
  ------------------
 1049|    885|			case 0x6F:
  ------------------
  |  Branch (1049:4): [True: 804, False: 145]
  ------------------
 1050|    885|				file = sc_file_new();
 1051|    885|				if (file == NULL) {
  ------------------
  |  Branch (1051:9): [True: 0, False: 885]
  ------------------
 1052|      0|					if (file_out) {
  ------------------
  |  Branch (1052:10): [True: 0, False: 0]
  ------------------
 1053|      0|						sc_file_free(*file_out);
 1054|      0|						*file_out = NULL;
 1055|      0|					}
 1056|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1057|      0|				}
 1058|    885|				file->path = lpath;
 1059|       |
 1060|    885|				rv = iasecc_process_fci(card, file, apdu.resp, apdu.resplen);
 1061|    885|				if (rv) {
  ------------------
  |  Branch (1061:9): [True: 81, False: 804]
  ------------------
 1062|     81|					sc_file_free(file);
 1063|     81|					if (file_out) {
  ------------------
  |  Branch (1063:10): [True: 49, False: 32]
  ------------------
 1064|     49|						sc_file_free(*file_out);
 1065|     49|						*file_out = NULL;
 1066|     49|					}
 1067|     81|					LOG_FUNC_RETURN(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: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     81|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     81|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1068|     81|				}
 1069|    804|				break;
 1070|    804|			default:
  ------------------
  |  Branch (1070:4): [True: 64, False: 885]
  ------------------
 1071|     64|				if (file_out) {
  ------------------
  |  Branch (1071:9): [True: 26, False: 38]
  ------------------
 1072|     26|					sc_file_free(*file_out);
 1073|     26|					*file_out = NULL;
 1074|     26|				}
 1075|     64|				LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     64|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     64|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     64|	int _ret = r; \
  |  |  |  |  155|     64|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     64|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     64|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 64, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     64|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     64|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     64|	return _ret; \
  |  |  |  |  163|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1076|    949|			}
 1077|       |
 1078|    804|			sc_log(ctx, "FileType %i", file->type);
  ------------------
  |  |   71|    804|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1079|    804|			if (file->type == SC_FILE_TYPE_DF)   {
  ------------------
  |  |  214|    804|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1079:8): [True: 77, False: 727]
  ------------------
 1080|     77|				sc_invalidate_cache(card);
 1081|     77|				sc_file_dup(&prv->cache.current_df, file);
 1082|     77|				prv->cache.valid = 1;
 1083|     77|			}
 1084|    727|			else   {
 1085|    727|				sc_file_free(prv->cache.current_ef);
 1086|    727|				sc_file_dup(&prv->cache.current_ef, file);
 1087|    727|				prv->cache.valid = 1;
 1088|    727|			}
 1089|       |
 1090|    804|			if (file_out)   {
  ------------------
  |  Branch (1090:8): [True: 670, False: 134]
  ------------------
 1091|    670|				sc_file_free(*file_out);
 1092|    670|				*file_out = file;
 1093|    670|			}
 1094|    134|			else   {
 1095|    134|				sc_file_free(file);
 1096|    134|			}
 1097|    804|		}
 1098|  1.24k|		else if (lpath.type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  1.24k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1098:12): [True: 1.11k, False: 127]
  ------------------
 1099|  1.11k|			sc_invalidate_cache(card);
 1100|  1.11k|			prv->cache.valid = 1;
 1101|  1.11k|		}
 1102|  2.19k|	} while(0);
  ------------------
  |  Branch (1102:10): [Folded, False: 2.04k]
  ------------------
 1103|       |
 1104|  2.04k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.04k|	int _ret = r; \
  |  |  |  |  155|  2.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.04k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.04k|	return _ret; \
  |  |  |  |  163|  2.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1105|  2.80k|err:
 1106|  2.80k|	if (file_out) {
  ------------------
  |  Branch (1106:6): [True: 1.16k, False: 1.63k]
  ------------------
 1107|  1.16k|		sc_file_free(*file_out);
 1108|       |		*file_out = NULL;
 1109|  1.16k|	}
 1110|  2.80k|	return rv;
 1111|  2.04k|}
card-iasecc.c:iasecc_emulate_fcp:
  842|     68|{
  843|     68|	unsigned char dummy_df_fcp[] = {
  844|     68|		0x62,0xFF,
  845|     68|			0x82,0x01,0x38,
  846|     68|			0x8A,0x01,0x05,
  847|     68|			0xA1,0x04,0x8C,0x02,0x02,0x00,
  848|     68|			0x84,0xFF,
  849|     68|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  850|     68|				0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  851|     68|	};
  852|       |
  853|     68|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     68|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     68|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     68|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     68|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 68]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  854|       |
  855|     68|	if (apdu->p1 != 0x04)
  ------------------
  |  Branch (855:6): [True: 0, False: 68]
  ------------------
  856|     68|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  857|     68|	if (apdu->datalen > 16)
  ------------------
  |  Branch (857:6): [True: 0, False: 68]
  ------------------
  858|     68|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|     68|	if (apdu->resplen < apdu->datalen + 16)
  ------------------
  |  Branch (859:6): [True: 0, False: 68]
  ------------------
  860|     68|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  861|       |
  862|     68|	memcpy(dummy_df_fcp + 16, apdu->data, apdu->datalen);
  863|     68|	dummy_df_fcp[15] = apdu->datalen;
  864|     68|	dummy_df_fcp[1] = apdu->datalen + 14;
  865|     68|	apdu->resplen = apdu->datalen + 16;
  866|     68|	memcpy(apdu->resp, dummy_df_fcp, apdu->resplen);
  867|       |
  868|     68|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     68|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     68|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     68|	int _ret = r; \
  |  |  |  |  155|     68|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 68, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 68]
  |  |  |  |  ------------------
  |  |  |  |  157|     68|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     68|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     68|	return _ret; \
  |  |  |  |  163|     68|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  869|     68|}
card-iasecc.c:iasecc_process_fci:
 1117|    885|{
 1118|    885|	struct sc_context *ctx = card->ctx;
 1119|    885|	size_t taglen, offs, ii;
 1120|    885|	int rv;
 1121|    885|	const unsigned char *acls = NULL, *tag = NULL;
 1122|    885|	unsigned char mask;
 1123|    885|	unsigned char ops_DF[7] = {
 1124|    885|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_CREATE, 0xFF
  ------------------
  |  |  168|    885|#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|    885|#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|    885|#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|    885|#define SC_AC_OP_CREATE			3
  ------------------
 1125|    885|	};
 1126|    885|	unsigned char ops_EF[7] = {
 1127|    885|		SC_AC_OP_DELETE, 0xFF, SC_AC_OP_ACTIVATE, SC_AC_OP_DEACTIVATE, 0xFF, SC_AC_OP_UPDATE, SC_AC_OP_READ
  ------------------
  |  |  168|    885|#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|    885|#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|    885|#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|    885|#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|    885|#define SC_AC_OP_READ			22
  ------------------
 1128|    885|	};
 1129|       |
 1130|    885|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    885|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    885|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    885|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    885|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 885]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1131|       |
 1132|    885|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x6F, &taglen);
 1133|    885|	sc_log(ctx, "processing FCI: 0x6F tag %p", tag);
  ------------------
  |  |   71|    885|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1134|    885|	if (tag != NULL) {
  ------------------
  |  Branch (1134:6): [True: 785, False: 100]
  ------------------
 1135|    785|		sc_log(ctx, "  FCP length %"SC_FORMAT_LEN_SIZE_T"u", taglen);
  ------------------
  |  |   71|    785|#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|    785|		buf = tag;
 1137|    785|		buflen = taglen;
 1138|    785|	}
 1139|       |
 1140|    885|	tag = sc_asn1_find_tag(ctx,  buf, buflen, 0x62, &taglen);
 1141|    885|	sc_log(ctx, "processing FCI: 0x62 tag %p", tag);
  ------------------
  |  |   71|    885|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1142|    885|	if (tag != NULL) {
  ------------------
  |  Branch (1142:6): [True: 74, False: 811]
  ------------------
 1143|     74|		sc_log(ctx, "  FCP length %"SC_FORMAT_LEN_SIZE_T"u", taglen);
  ------------------
  |  |   71|     74|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1144|     74|		buf = tag;
 1145|     74|		buflen = taglen;
 1146|     74|	}
 1147|       |
 1148|    885|	rv = iso_ops->process_fci(card, file, buf, buflen);
 1149|    885|	LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
  ------------------
  |  |  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: 0, False: 885]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    885|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 885]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1150|       |/*
 1151|       |	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
 1152|       |	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
 1153|       |	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
 1154|       |*/
 1155|       |
 1156|    885|	sc_log(ctx, "iasecc_process_fci() type %i; let's parse file ACLs", file->type);
  ------------------
  |  |   71|    885|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1157|    885|	tag = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS, &taglen);
  ------------------
  |  |   39|    885|#define IASECC_DOCP_TAG_ACLS			0xA1
  ------------------
 1158|    885|	if (tag)
  ------------------
  |  Branch (1158:6): [True: 68, False: 817]
  ------------------
 1159|     68|		acls = sc_asn1_find_tag(ctx, tag, taglen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|     68|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1160|    817|	else
 1161|    817|		acls = sc_asn1_find_tag(ctx, buf, buflen, IASECC_DOCP_TAG_ACLS_CONTACT, &taglen);
  ------------------
  |  |   40|    817|#define IASECC_DOCP_TAG_ACLS_CONTACT		0x8C
  ------------------
 1162|       |
 1163|    885|	if (!acls)   {
  ------------------
  |  Branch (1163:6): [True: 81, False: 804]
  ------------------
 1164|     81|		sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1165|     81|		       "ACLs not found in data(%"SC_FORMAT_LEN_SIZE_T"u) %s",
 1166|     81|		       buflen, sc_dump_hex(buf, buflen));
 1167|     81|		LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "ACLs tag missing");
  ------------------
  |  |  174|     81|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     81|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     81|	int _ret = (r); \
  |  |  |  |  168|     81|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 81, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     81|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     81|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     81|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     81|		return _ret; \
  |  |  |  |  172|     81|	} \
  |  |  |  |  173|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1168|     81|	}
 1169|       |
 1170|    804|	sc_log(ctx, "ACLs(%"SC_FORMAT_LEN_SIZE_T"u) '%s'", taglen,
  ------------------
  |  |   71|    804|#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|    804|	       sc_dump_hex(acls, taglen));
 1172|    804|	mask = 0x40, offs = 1;
 1173|  4.86k|	for (ii = 0; ii < 7; ii++, mask /= 2)  {
  ------------------
  |  Branch (1173:15): [True: 4.38k, False: 487]
  ------------------
 1174|  4.38k|		unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
  ------------------
  |  |  214|  4.38k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (1174:22): [True: 511, False: 3.87k]
  ------------------
 1175|       |
 1176|       |		/* avoid any access to acls[offs] beyond the taglen */
 1177|  4.38k|		if (offs >= taglen) {
  ------------------
  |  Branch (1177:7): [True: 317, False: 4.06k]
  ------------------
 1178|    317|			sc_log(ctx, "Warning: Invalid offset reached during ACL parsing");
  ------------------
  |  |   71|    317|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1179|    317|			break;
 1180|    317|		}
 1181|  4.06k|		if (!(mask & acls[0]))
  ------------------
  |  Branch (1181:7): [True: 1.56k, False: 2.49k]
  ------------------
 1182|  1.56k|			continue;
 1183|       |
 1184|  2.49k|		sc_log(ctx, "ACLs mask 0x%X, offs %"SC_FORMAT_LEN_SIZE_T"u, op 0x%X, acls[offs] 0x%X", mask, offs, op, acls[offs]);
  ------------------
  |  |   71|  2.49k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1185|  2.49k|		if (op == 0xFF)   {
  ------------------
  |  Branch (1185:7): [True: 646, False: 1.85k]
  ------------------
 1186|    646|			;
 1187|    646|		}
 1188|  1.85k|		else if (acls[offs] == 0)   {
  ------------------
  |  Branch (1188:12): [True: 433, False: 1.42k]
  ------------------
 1189|    433|			sc_file_add_acl_entry(file, op, SC_AC_NONE, 0);
  ------------------
  |  |  150|    433|#define SC_AC_NONE			0x00000000
  ------------------
 1190|    433|		}
 1191|  1.42k|		else if (acls[offs] == 0xFF)   {
  ------------------
  |  Branch (1191:12): [True: 152, False: 1.26k]
  ------------------
 1192|    152|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    152|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1193|    152|		}
 1194|  1.26k|		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   89|  1.26k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
              		else if ((acls[offs] & IASECC_SCB_METHOD_MASK) == IASECC_SCB_METHOD_USER_AUTH)   {
  ------------------
  |  |   93|  1.26k|#define IASECC_SCB_METHOD_USER_AUTH	0x10
  ------------------
  |  Branch (1194:12): [True: 149, False: 1.11k]
  ------------------
 1195|    149|			sc_file_add_acl_entry(file, op, SC_AC_SEN, acls[offs] & IASECC_SCB_METHOD_MASK_REF);
  ------------------
  |  |  156|    149|#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|    149|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
 1196|    149|		}
 1197|  1.11k|		else if (acls[offs] & IASECC_SCB_METHOD_MASK)   {
  ------------------
  |  |   89|  1.11k|#define IASECC_SCB_METHOD_MASK		0x70
  ------------------
  |  Branch (1197:12): [True: 809, False: 310]
  ------------------
 1198|    809|			sc_file_add_acl_entry(file, op, SC_AC_SCB, acls[offs]);
  ------------------
  |  |  157|    809|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
 1199|    809|		}
 1200|    310|		else   {
 1201|    310|			sc_log(ctx, "Warning: non supported SCB method: %X", acls[offs]);
  ------------------
  |  |   71|    310|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1202|    310|			sc_file_add_acl_entry(file, op, SC_AC_NEVER, 0);
  ------------------
  |  |  163|    310|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1203|    310|		}
 1204|       |
 1205|  2.49k|		offs++;
 1206|  2.49k|	}
 1207|       |
 1208|    804|	LOG_FUNC_RETURN(ctx, 0);
  ------------------
  |  |  164|    804|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    804|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    804|	int _ret = r; \
  |  |  |  |  155|    804|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 804, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    804|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 804]
  |  |  |  |  ------------------
  |  |  |  |  157|    804|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    804|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    804|	return _ret; \
  |  |  |  |  163|    804|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1209|    804|}
card-iasecc.c:iasecc_se_get_info_from_cache:
 1592|    190|{
 1593|    190|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1594|    190|	struct sc_context *ctx = card->ctx;
 1595|    190|	struct iasecc_se_info *si = NULL;
 1596|    190|	int rv;
 1597|       |
 1598|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1599|       |
 1600|    215|	for(si = prv->se_info; si; si = si->next)   {
  ------------------
  |  Branch (1600:25): [True: 27, False: 188]
  ------------------
 1601|     27|		if (si->reference != se->reference)
  ------------------
  |  Branch (1601:7): [True: 23, False: 4]
  ------------------
 1602|     23|			continue;
 1603|      4|		if (!(prv->cache.valid && prv->cache.current_df) && si->df)
  ------------------
  |  Branch (1603:9): [True: 4, False: 0]
  |  Branch (1603:29): [True: 2, False: 2]
  |  Branch (1603:55): [True: 2, False: 0]
  ------------------
 1604|      2|			continue;
 1605|      2|		if (prv->cache.valid && prv->cache.current_df && !si->df)
  ------------------
  |  Branch (1605:7): [True: 2, False: 0]
  |  Branch (1605:27): [True: 2, False: 0]
  |  Branch (1605:52): [True: 0, False: 2]
  ------------------
 1606|      0|			continue;
 1607|      2|		if (prv->cache.valid && prv->cache.current_df && si->df)
  ------------------
  |  Branch (1607:7): [True: 2, False: 0]
  |  Branch (1607:27): [True: 2, False: 0]
  |  Branch (1607:52): [True: 2, False: 0]
  ------------------
 1608|      2|			if (memcmp(&prv->cache.current_df->path, &si->df->path, sizeof(struct sc_path)))
  ------------------
  |  Branch (1608:8): [True: 0, False: 2]
  ------------------
 1609|      0|				continue;
 1610|      2|		break;
 1611|      2|	}
 1612|       |
 1613|    190|	if (!si)
  ------------------
  |  Branch (1613:6): [True: 188, False: 2]
  ------------------
 1614|    188|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    188|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1615|       |
 1616|      2|	memcpy(se, si, sizeof(struct iasecc_se_info));
 1617|       |
 1618|      2|	if (si->df)   {
  ------------------
  |  Branch (1618:6): [True: 2, False: 0]
  ------------------
 1619|      2|		sc_file_dup(&se->df, si->df);
 1620|      2|		if (se->df == NULL)
  ------------------
  |  Branch (1620:7): [True: 0, False: 2]
  ------------------
 1621|      2|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|      2|	}
 1623|       |
 1624|      2|	rv = iasecc_docp_copy(ctx, &si->docp, &se->docp);
 1625|      2|	LOG_TEST_RET(ctx, rv, "Cannot make copy of DOCP");
  ------------------
  |  |  174|      2|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      2|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      2|	int _ret = (r); \
  |  |  |  |  168|      2|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1626|       |
 1627|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1628|      2|}
card-iasecc.c:iasecc_se_cache_info:
 1549|     34|{
 1550|     34|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 1551|     34|	struct sc_context *ctx = card->ctx;
 1552|     34|	struct iasecc_se_info *se_info = NULL, *si = NULL;
 1553|     34|	int rv;
 1554|       |
 1555|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1556|       |
 1557|     34|	se_info = calloc(1, sizeof(struct iasecc_se_info));
 1558|     34|	if (!se_info)
  ------------------
  |  Branch (1558:6): [True: 0, False: 34]
  ------------------
 1559|     34|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1560|     34|	memcpy(se_info, se, sizeof(struct iasecc_se_info));
 1561|       |
 1562|     34|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (1562:6): [True: 34, False: 0]
  |  Branch (1562:26): [True: 32, False: 2]
  ------------------
 1563|     32|		sc_file_dup(&se_info->df, prv->cache.current_df);
 1564|     32|		if (se_info->df == NULL)   {
  ------------------
  |  Branch (1564:7): [True: 0, False: 32]
  ------------------
 1565|      0|			free(se_info);
 1566|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1567|      0|		}
 1568|     32|	}
 1569|       |
 1570|     34|	rv = iasecc_docp_copy(ctx, &se->docp, &se_info->docp);
 1571|     34|	if (rv < 0)   {
  ------------------
  |  Branch (1571:6): [True: 0, False: 34]
  ------------------
 1572|      0|		free(se_info->df);
 1573|      0|		free(se_info);
 1574|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1575|      0|	}
 1576|       |
 1577|     34|	if (!prv->se_info)   {
  ------------------
  |  Branch (1577:6): [True: 23, False: 11]
  ------------------
 1578|     23|		prv->se_info = se_info;
 1579|     23|	}
 1580|     11|	else    {
 1581|     16|		for (si = prv->se_info; si->next; si = si->next)
  ------------------
  |  Branch (1581:27): [True: 5, False: 11]
  ------------------
 1582|      5|			;
 1583|     11|		si->next = se_info;
 1584|     11|	}
 1585|       |
 1586|     34|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|     34|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     34|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     34|	int _ret = r; \
  |  |  |  |  155|     34|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     34|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  157|     34|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     34|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     34|	return _ret; \
  |  |  |  |  163|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1587|     34|}
card-iasecc.c:sc_get_driver:
 3641|  15.3k|{
 3642|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 3643|       |
 3644|  15.3k|	if (!iso_ops)
  ------------------
  |  Branch (3644:6): [True: 1, False: 15.3k]
  ------------------
 3645|      1|		iso_ops = iso_drv->ops;
 3646|       |
 3647|  15.3k|	iasecc_ops = *iso_ops;
 3648|       |
 3649|  15.3k|	iasecc_ops.match_card = iasecc_match_card;
 3650|  15.3k|	iasecc_ops.init = iasecc_init;
 3651|  15.3k|	iasecc_ops.finish = iasecc_finish;
 3652|  15.3k|	iasecc_ops.read_binary = iasecc_read_binary;
 3653|       |	/*	write_binary: ISO7816 implementation works	*/
 3654|       |	/*	update_binary: ISO7816 implementation works	*/
 3655|  15.3k|	iasecc_ops.erase_binary = iasecc_erase_binary;
 3656|       |	/*	resize_binary	*/
 3657|       |	/* 	read_record: Untested	*/
 3658|       |	/*	write_record: Untested	*/
 3659|       |	/*	append_record: Untested	*/
 3660|       |	/*	update_record: Untested	*/
 3661|  15.3k|	iasecc_ops.select_file = iasecc_select_file;
 3662|       |	/*	get_response: Untested	*/
 3663|  15.3k|	iasecc_ops.get_challenge = iasecc_get_challenge;
 3664|  15.3k|	iasecc_ops.logout = iasecc_logout;
 3665|       |	/*	restore_security_env	*/
 3666|  15.3k|	iasecc_ops.set_security_env = iasecc_set_security_env;
 3667|  15.3k|	iasecc_ops.decipher = iasecc_decipher;
 3668|  15.3k|	iasecc_ops.compute_signature = iasecc_compute_signature;
 3669|  15.3k|	iasecc_ops.create_file = iasecc_create_file;
 3670|  15.3k|	iasecc_ops.delete_file = iasecc_delete_file;
 3671|       |	/*	list_files	*/
 3672|  15.3k|	iasecc_ops.check_sw = iasecc_check_sw;
 3673|  15.3k|	iasecc_ops.card_ctl = iasecc_card_ctl;
 3674|  15.3k|	iasecc_ops.process_fci = iasecc_process_fci;
 3675|       |	/*	construct_fci: Not needed	*/
 3676|  15.3k|	iasecc_ops.pin_cmd = iasecc_pin_cmd;
 3677|       |	/*	get_data: Not implemented	*/
 3678|       |	/*	put_data: Not implemented	*/
 3679|       |	/*	delete_record: Not implemented	*/
 3680|       |
 3681|  15.3k|	iasecc_ops.read_public_key = iasecc_read_public_key;
 3682|       |
 3683|  15.3k|	return &iasecc_drv;
 3684|  15.3k|}
card-iasecc.c:iasecc_match_card:
  353|  9.92k|{
  354|  9.92k|	struct sc_context *ctx = card->ctx;
  355|  9.92k|	int i;
  356|       |
  357|  9.92k|	i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
  358|  9.92k|	if (i < 0)   {
  ------------------
  |  Branch (358:6): [True: 9.09k, False: 836]
  ------------------
  359|  9.09k|		sc_log(ctx, "card not matched");
  ------------------
  |  |   71|  9.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__
  |  |  ------------------
  ------------------
  360|  9.09k|		return 0;
  361|  9.09k|	}
  362|       |
  363|    836|	sc_log(ctx, "'%s' card matched", iasecc_known_atrs[i].name);
  ------------------
  |  |   71|    836|#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|    836|	return 1;
  365|  9.92k|}
card-iasecc.c:iasecc_init:
  628|    836|{
  629|    836|	struct sc_context *ctx = card->ctx;
  630|    836|	struct iasecc_private_data *private_data = NULL;
  631|    836|	int rv = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|    836|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
  632|    836|	void *old_drv_data = card->drv_data;
  633|       |
  634|    836|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    836|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    836|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    836|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    836|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 836]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  635|    836|	private_data = (struct iasecc_private_data *) calloc(1, sizeof(struct iasecc_private_data));
  636|    836|	if (private_data == NULL)
  ------------------
  |  Branch (636:6): [True: 0, False: 836]
  ------------------
  637|    836|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  638|       |
  639|    836|	card->cla  = 0x00;
  640|    836|	card->drv_data = private_data;
  641|       |
  642|    836|	if (card->type == SC_CARD_TYPE_IASECC_GEMALTO)
  ------------------
  |  Branch (642:6): [True: 22, False: 814]
  ------------------
  643|     22|		rv = iasecc_init_gemalto(card);
  644|    814|	else if (card->type == SC_CARD_TYPE_IASECC_OBERTHUR)
  ------------------
  |  Branch (644:11): [True: 65, False: 749]
  ------------------
  645|     65|		rv = iasecc_init_oberthur(card);
  646|    749|	else if (card->type == SC_CARD_TYPE_IASECC_SAGEM)
  ------------------
  |  Branch (646:11): [True: 35, False: 714]
  ------------------
  647|     35|		rv = iasecc_init_amos_or_sagem(card);
  648|    714|	else if (card->type == SC_CARD_TYPE_IASECC_AMOS)
  ------------------
  |  Branch (648:11): [True: 10, False: 704]
  ------------------
  649|     10|		rv = iasecc_init_amos_or_sagem(card);
  650|    704|	else if (card->type == SC_CARD_TYPE_IASECC_MI)
  ------------------
  |  Branch (650:11): [True: 445, False: 259]
  ------------------
  651|    445|		rv = iasecc_init_amos_or_sagem(card);
  652|    259|	else if (iasecc_is_cpx(card))
  ------------------
  |  Branch (652:11): [True: 259, False: 0]
  ------------------
  653|    259|		rv = iasecc_init_cpx(card);
  654|      0|	else {
  655|      0|		LOG_TEST_GOTO_ERR(ctx, SC_ERROR_INVALID_CARD, "");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  656|      0|	}
  657|       |
  658|       |
  659|    836|	if (!rv)   {
  ------------------
  |  Branch (659:6): [True: 529, False: 307]
  ------------------
  660|    529|		if (card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (660:7): [True: 529, False: 0]
  |  Branch (660:23): [True: 425, False: 104]
  ------------------
  661|    425|			struct sc_path path;
  662|       |
  663|    425|			memset(&path, 0, sizeof(struct sc_path));
  664|    425|			path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    425|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  665|    425|			memcpy(path.value, card->ef_atr->aid.value, card->ef_atr->aid.len);
  666|    425|			path.len = card->ef_atr->aid.len;
  667|       |
  668|    425|			rv = iasecc_select_file(card, &path, NULL);
  669|    425|			sc_log(ctx, "Select ECC ROOT with the AID from EF.ATR: rv %i", rv);
  ------------------
  |  |   71|    425|#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|    425|			LOG_TEST_GOTO_ERR(ctx, rv, "Select EF.ATR AID failed");
  ------------------
  |  |  184|    425|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    425|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    425|	int _ret = (r); \
  |  |  |  |  178|    425|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 8, False: 417]
  |  |  |  |  ------------------
  |  |  |  |  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|    425|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 417]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  671|    425|		}
  672|       |
  673|    521|		iasecc_get_serialnr(card, NULL);
  674|    521|	}
  675|       |
  676|    828|#ifdef ENABLE_SM
  677|    828|	card->sm_ctx.ops.read_binary = _iasecc_sm_read_binary;
  678|    828|	card->sm_ctx.ops.update_binary = _iasecc_sm_update_binary;
  679|    828|#endif
  680|       |
  681|    828|	if (!rv && card->ef_atr && card->ef_atr->aid.len)   {
  ------------------
  |  Branch (681:6): [True: 521, False: 307]
  |  Branch (681:13): [True: 521, False: 0]
  |  Branch (681:29): [True: 417, False: 104]
  ------------------
  682|    417|		sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   71|    417|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  683|    417|	}
  684|       |
  685|    836|err:
  686|    836|	if (rv < 0) {
  ------------------
  |  Branch (686:6): [True: 315, False: 521]
  ------------------
  687|    315|		sc_invalidate_cache(card);
  688|    315|		free(private_data);
  689|    315|		card->drv_data = old_drv_data;
  690|    521|	} else {
  691|    521|		free(old_drv_data);
  692|    521|	}
  693|       |
  694|    836|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    836|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    836|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    836|	int _ret = r; \
  |  |  |  |  155|    836|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 836, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    836|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    315|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 315, False: 521]
  |  |  |  |  ------------------
  |  |  |  |  157|    836|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    836|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    836|	return _ret; \
  |  |  |  |  163|    836|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  695|    836|}
card-iasecc.c:iasecc_init_gemalto:
  423|     22|{
  424|     22|	struct sc_context *ctx = card->ctx;
  425|     22|	struct sc_path path;
  426|     22|	unsigned int flags;
  427|     22|	int rv = 0;
  428|       |
  429|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  430|       |
  431|     22|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     22|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     22|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |  102|     22|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     22|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  115|     22|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     22|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  120|     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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  118|     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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  119|     22|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     22|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  142|     22|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     22|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  143|     22|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     22|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  147|     22|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  432|       |
  433|     22|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     22|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     22|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  557|     22|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     22|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  554|     22|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     22|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  564|     22|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     22|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  560|     22|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  434|       |
  435|     22|	sc_format_path("3F00", &path);
  436|     22|	if (SC_SUCCESS != sc_select_file(card, &path, NULL)) {
  ------------------
  |  |   28|     22|#define SC_SUCCESS				0
  ------------------
  |  Branch (436:6): [True: 20, False: 2]
  ------------------
  437|       |		/* Result ignored*/
  438|     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__
  |  |  ------------------
  ------------------
  439|     20|	}
  440|       |
  441|     22|	rv = iasecc_parse_ef_atr(card);
  442|     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__
  |  |  ------------------
  ------------------
  443|     22|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     22|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (443:6): [True: 2, False: 20]
  ------------------
  444|      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__
  |  |  ------------------
  ------------------
  445|      2|		rv = iasecc_select_mf(card, NULL);
  446|      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__
  |  |  ------------------
  ------------------
  447|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  448|       |
  449|      1|		rv = iasecc_parse_ef_atr(card);
  450|      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__
  |  |  ------------------
  ------------------
  451|      1|	}
  452|     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__
  |  |  ------------------
  ------------------
  453|     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: 16, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|     21|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  454|       |
  455|      5|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  456|      5|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  457|       |
  458|      5|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      5|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      5|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      5|	int _ret = r; \
  |  |  |  |  155|      5|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|      5|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      5|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      5|	return _ret; \
  |  |  |  |  163|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  459|      5|}
card-iasecc.c:iasecc_parse_ef_atr:
  369|    435|{
  370|    435|	struct sc_context *ctx = card->ctx;
  371|    435|	struct iasecc_private_data *pdata = (struct iasecc_private_data *) card->drv_data;
  372|    435|	struct iasecc_version *version = &pdata->version;
  373|    435|	struct iasecc_io_buffer_sizes *sizes = &pdata->max_sizes;
  374|    435|	int rv;
  375|       |
  376|    435|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    435|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    435|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    435|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    435|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 435]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  377|    435|	rv = sc_parse_ef_atr(card);
  378|    435|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|    435|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    435|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    435|	int _ret = (r); \
  |  |  |  |  168|    435|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 200, False: 235]
  |  |  |  |  ------------------
  |  |  |  |  169|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    200|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    200|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    200|		return _ret; \
  |  |  |  |  172|    200|	} \
  |  |  |  |  173|    435|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 235]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|       |
  380|    235|	if (card->ef_atr->pre_issuing_len < 4)
  ------------------
  |  Branch (380:6): [True: 121, False: 114]
  ------------------
  381|    235|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid pre-issuing data");
  ------------------
  |  |  174|    121|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    121|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    121|	int _ret = (r); \
  |  |  |  |  168|    121|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 121, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    121|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    121|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    121|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    121|		return _ret; \
  |  |  |  |  172|    121|	} \
  |  |  |  |  173|    121|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  382|       |
  383|    114|	version->ic_manufacturer =	card->ef_atr->pre_issuing[0];
  384|    114|	version->ic_type =		card->ef_atr->pre_issuing[1];
  385|    114|	version->os_version =		card->ef_atr->pre_issuing[2];
  386|    114|	version->iasecc_version =	card->ef_atr->pre_issuing[3];
  387|    114|	sc_log(ctx, "EF.ATR: IC manufacturer/type %X/%X, OS/IasEcc versions %X/%X",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  388|    114|		version->ic_manufacturer, version->ic_type, version->os_version, version->iasecc_version);
  389|       |
  390|    114|	if (card->ef_atr->issuer_data_len < 16)
  ------------------
  |  Branch (390:6): [True: 6, False: 108]
  ------------------
  391|    114|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "Invalid issuer data");
  ------------------
  |  |  174|      6|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      6|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      6|	int _ret = (r); \
  |  |  |  |  168|      6|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  392|       |
  393|    108|	sizes->send =	 card->ef_atr->issuer_data[2] * 0x100 + card->ef_atr->issuer_data[3];
  394|    108|	sizes->send_sc = card->ef_atr->issuer_data[6] * 0x100 + card->ef_atr->issuer_data[7];
  395|    108|	sizes->recv =	 card->ef_atr->issuer_data[10] * 0x100 + card->ef_atr->issuer_data[11];
  396|    108|	sizes->recv_sc = card->ef_atr->issuer_data[14] * 0x100 + card->ef_atr->issuer_data[15];
  397|       |
  398|    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__
  |  |  ------------------
  ------------------
  399|    108|		"EF.ATR: IO Buffer Size send/sc %"SC_FORMAT_LEN_SIZE_T"d/%"SC_FORMAT_LEN_SIZE_T"d "
  400|    108|		"recv/sc %"SC_FORMAT_LEN_SIZE_T"d/%"SC_FORMAT_LEN_SIZE_T"d",
  401|    108|		sizes->send, sizes->send_sc, sizes->recv, sizes->recv_sc);
  402|       |
  403|    108|	card->max_send_size = sizes->send;
  404|    108|	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|    108|	if (card->max_send_size > 0xFF)
  ------------------
  |  Branch (410:6): [True: 91, False: 17]
  ------------------
  411|     91|		card->max_send_size -= 5;
  412|       |
  413|    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__
  |  |  ------------------
  ------------------
  414|    108|	       "EF.ATR: max send/recv sizes %"SC_FORMAT_LEN_SIZE_T"X/%"SC_FORMAT_LEN_SIZE_T"X",
  415|    108|	       card->max_send_size, card->max_recv_size);
  416|       |
  417|    108|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    108|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    108|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    108|	int _ret = r; \
  |  |  |  |  155|    108|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 108, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    108|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 108]
  |  |  |  |  ------------------
  |  |  |  |  157|    108|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    108|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    108|	return _ret; \
  |  |  |  |  163|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  418|    108|}
card-iasecc.c:iasecc_init_oberthur:
  492|     65|{
  493|     65|	struct sc_context *ctx = card->ctx;
  494|     65|	unsigned int flags;
  495|     65|	int rv = 0;
  496|       |
  497|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  498|       |
  499|     65|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|     65|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|     65|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |  102|     65|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|     65|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  115|     65|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|     65|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  120|     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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  118|     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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  119|     65|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|     65|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  142|     65|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|     65|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  143|     65|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|     65|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  147|     65|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  500|       |
  501|     65|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  502|     65|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  503|       |
  504|     65|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|     65|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|     65|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  557|     65|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|     65|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  554|     65|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|     65|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  564|     65|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|     65|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  560|     65|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  505|       |
  506|     65|	iasecc_parse_ef_atr(card);
  507|       |
  508|       |	/* if we fail to select CM, */
  509|     65|	if (gp_select_card_manager(card)) {
  ------------------
  |  Branch (509:6): [True: 51, False: 14]
  ------------------
  510|     51|		gp_select_isd_rid(card);
  511|     51|	}
  512|       |
  513|     65|	rv = iasecc_oberthur_match(card);
  514|     65|	LOG_TEST_RET(ctx, rv, "unknown Oberthur's IAS/ECC card");
  ------------------
  |  |  174|     65|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     65|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     65|	int _ret = (r); \
  |  |  |  |  168|     65|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 65]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 65]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  515|       |
  516|     65|	rv = iasecc_select_mf(card, NULL);
  517|     65|	LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  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: 53, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  169|     53|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     53|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     53|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     53|		return _ret; \
  |  |  |  |  172|     53|	} \
  |  |  |  |  173|     65|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  518|       |
  519|     12|	rv = iasecc_parse_ef_atr(card);
  520|     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: 7, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  521|       |
  522|      5|	sc_log(ctx, "EF.ATR(aid:'%s')", sc_dump_hex(card->ef_atr->aid.value, card->ef_atr->aid.len));
  ------------------
  |  |   71|      5|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  523|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  524|      5|}
card-iasecc.c:iasecc_oberthur_match:
  464|     65|{
  465|     65|	struct sc_context *ctx = card->ctx;
  466|     65|	unsigned char *hist = card->reader->atr_info.hist_bytes;
  467|       |
  468|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  469|       |
  470|     65|	if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
  ------------------
  |  Branch (470:6): [True: 0, False: 65]
  |  Branch (470:23): [True: 0, False: 65]
  ------------------
  471|     65|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  472|       |
  473|     65|	sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
  ------------------
  |  |  129|     65|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     65|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  474|       |
  475|     65|	if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
  ------------------
  |  Branch (475:6): [True: 0, False: 65]
  ------------------
  476|     65|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  477|       |
  478|     65|	if (!card->ef_atr)
  ------------------
  |  Branch (478:6): [True: 34, False: 31]
  ------------------
  479|     34|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  480|     65|	if (!card->ef_atr)
  ------------------
  |  Branch (480:6): [True: 0, False: 65]
  ------------------
  481|     65|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  482|       |
  483|     65|	memcpy(card->ef_atr->aid.value, OberthurIASECC_AID.value, OberthurIASECC_AID.len);
  484|     65|	card->ef_atr->aid.len = OberthurIASECC_AID.len;
  485|       |
  486|     65|	LOG_FUNC_RETURN(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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  487|     65|}
card-iasecc.c:iasecc_init_amos_or_sagem:
  554|    490|{
  555|    490|	struct sc_context *ctx = card->ctx;
  556|    490|	unsigned int flags;
  557|    490|	int rv = 0;
  558|       |
  559|    490|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    490|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    490|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    490|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    490|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 490]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  560|       |
  561|    490|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    490|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    490|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |  102|    490|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    490|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  115|    490|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    490|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  120|    490|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  118|    490|#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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  119|    490|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    490|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  142|    490|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    490|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  143|    490|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    490|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  147|    490|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  562|       |
  563|    490|	_sc_card_add_rsa_alg(card, 1024, flags, 0x10001);
  564|    490|	_sc_card_add_rsa_alg(card, 2048, flags, 0x10001);
  565|       |
  566|    490|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    490|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    490|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  557|    490|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    490|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  554|    490|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    490|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  564|    490|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    490|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  560|    490|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  567|       |
  568|    490|	if (card->type == SC_CARD_TYPE_IASECC_MI)   {
  ------------------
  |  Branch (568:6): [True: 445, False: 45]
  ------------------
  569|    445|		rv = iasecc_mi_match(card);
  570|    445|		if (rv)
  ------------------
  |  Branch (570:7): [True: 24, False: 421]
  ------------------
  571|     24|			card->type = SC_CARD_TYPE_IASECC_MI2;
  572|    421|		else
  573|    445|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    421|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    421|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    421|	int _ret = r; \
  |  |  |  |  155|    421|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 421, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    421|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 421]
  |  |  |  |  ------------------
  |  |  |  |  157|    421|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    421|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    421|	return _ret; \
  |  |  |  |  163|    421|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  574|    445|	}
  575|       |
  576|     69|	rv = iasecc_parse_ef_atr(card);
  577|     69|	if (rv == SC_ERROR_FILE_NOT_FOUND)   {
  ------------------
  |  |   51|     69|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (577:6): [True: 9, False: 60]
  ------------------
  578|      9|		rv = iasecc_select_mf(card, NULL);
  579|      9|		LOG_TEST_RET(ctx, rv, "MF selection error");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  169|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      2|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      2|		return _ret; \
  |  |  |  |  172|      2|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  580|       |
  581|      7|		rv = iasecc_parse_ef_atr(card);
  582|      7|	}
  583|     67|	LOG_TEST_RET(ctx, rv, "IASECC: ATR parse 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: 40, False: 27]
  |  |  |  |  ------------------
  |  |  |  |  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|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  584|       |
  585|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  586|     27|}
card-iasecc.c:iasecc_mi_match:
  529|    445|{
  530|    445|	struct sc_context *ctx = card->ctx;
  531|    445|	unsigned char resp[0x100];
  532|    445|	size_t resp_len = sizeof(resp);
  533|    445|	int rv = 0;
  534|       |
  535|    445|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    445|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    445|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    445|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    445|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 445]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  536|       |
  537|    445|	rv = iso7816_select_aid(card, MIIASECC_AID.value, MIIASECC_AID.len, resp, &resp_len);
  538|    445|	LOG_TEST_RET(ctx, rv, "IASECC: failed to select MI IAS/ECC applet");
  ------------------
  |  |  174|    445|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    445|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    445|	int _ret = (r); \
  |  |  |  |  168|    445|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 24, False: 421]
  |  |  |  |  ------------------
  |  |  |  |  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|    445|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 421]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|       |
  540|    421|	if (!card->ef_atr)
  ------------------
  |  Branch (540:6): [True: 421, False: 0]
  ------------------
  541|    421|		card->ef_atr = calloc(1, sizeof(struct sc_ef_atr));
  542|    421|	if (!card->ef_atr)
  ------------------
  |  Branch (542:6): [True: 0, False: 421]
  ------------------
  543|    421|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  544|       |
  545|    421|	memcpy(card->ef_atr->aid.value, MIIASECC_AID.value, MIIASECC_AID.len);
  546|    421|	card->ef_atr->aid.len = MIIASECC_AID.len;
  547|       |
  548|    421|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    421|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    421|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    421|	int _ret = r; \
  |  |  |  |  155|    421|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 421, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    421|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 421]
  |  |  |  |  ------------------
  |  |  |  |  157|    421|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    421|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    421|	return _ret; \
  |  |  |  |  163|    421|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  549|    421|}
card-iasecc.c:iasecc_init_cpx:
  604|    259|{
  605|    259|	struct sc_context *ctx = card->ctx;
  606|    259|	unsigned int flags;
  607|    259|	int rv = 0;
  608|       |
  609|    259|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    259|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    259|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    259|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    259|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 259]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  610|       |
  611|    259|	card->caps = IASECC_CARD_DEFAULT_CAPS;
  ------------------
  |  |   61|    259|#define IASECC_CARD_DEFAULT_CAPS ( 0 			\
  |  |   62|    259|		| SC_CARD_CAP_RNG			\
  |  |  ------------------
  |  |  |  |  557|    259|#define SC_CARD_CAP_RNG			0x00000004
  |  |  ------------------
  |  |   63|    259|		| SC_CARD_CAP_APDU_EXT			\
  |  |  ------------------
  |  |  |  |  554|    259|#define SC_CARD_CAP_APDU_EXT		0x00000001
  |  |  ------------------
  |  |   64|    259|		| SC_CARD_CAP_USE_FCI_AC		\
  |  |  ------------------
  |  |  |  |  564|    259|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  |  |  ------------------
  |  |   65|    259|		| SC_CARD_CAP_ISO7816_PIN_INFO)
  |  |  ------------------
  |  |  |  |  560|    259|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  |  |  ------------------
  ------------------
  612|       |
  613|    259|	flags = IASECC_CARD_DEFAULT_FLAGS;
  ------------------
  |  |   53|    259|#define IASECC_CARD_DEFAULT_FLAGS ( 0			\
  |  |   54|    259|		| SC_ALGORITHM_ONBOARD_KEY_GEN		\
  |  |  ------------------
  |  |  |  |  102|    259|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  |  |  ------------------
  |  |   55|    259|		| SC_ALGORITHM_RSA_PAD_ISO9796		\
  |  |  ------------------
  |  |  |  |  115|    259|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  |  |  ------------------
  |  |   56|    259|		| SC_ALGORITHM_RSA_PAD_PKCS1		\
  |  |  ------------------
  |  |  |  |  120|    259|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  118|    259|#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) */
  |  |  |  |  ------------------
  |  |  |  |  |  |  119|    259|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  |  |  ------------------
  |  |  ------------------
  |  |   57|    259|		| SC_ALGORITHM_RSA_HASH_NONE		\
  |  |  ------------------
  |  |  |  |  142|    259|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  |  |   58|    259|		| SC_ALGORITHM_RSA_HASH_SHA1		\
  |  |  ------------------
  |  |  |  |  143|    259|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  |  |   59|    259|		| SC_ALGORITHM_RSA_HASH_SHA256)
  |  |  ------------------
  |  |  |  |  147|    259|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  614|       |
  615|    259|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  616|    259|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  617|    259|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  618|       |
  619|    259|	rv = iasecc_parse_ef_atr(card);
  620|    259|	LOG_TEST_RET(ctx, rv, "Parse EF.ATR");
  ------------------
  |  |  174|    259|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    259|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    259|	int _ret = (r); \
  |  |  |  |  168|    259|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 188, False: 71]
  |  |  |  |  ------------------
  |  |  |  |  169|    188|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    188|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    188|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    188|		return _ret; \
  |  |  |  |  172|    188|	} \
  |  |  |  |  173|    259|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 71]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|       |
  622|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  623|     71|}
card-iasecc.c:iasecc_get_serialnr:
 2496|    728|{
 2497|    728|	struct sc_context *ctx = card->ctx;
 2498|    728|	struct sc_iin *iin = &card->serialnr.iin;
 2499|    728|	struct sc_apdu apdu;
 2500|    728|	unsigned char rbuf[0xC0];
 2501|    728|	size_t ii, offs, len;
 2502|    728|	int rv;
 2503|       |
 2504|    728|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    728|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    728|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    728|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    728|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 728]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2505|    728|	if (card->serialnr.len)
  ------------------
  |  Branch (2505:6): [True: 0, False: 728]
  ------------------
 2506|      0|		goto end;
 2507|       |
 2508|    728|	memset(&card->serialnr, 0, sizeof(card->serialnr));
 2509|       |
 2510|    728|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, 0x80 | IASECC_SFI_EF_SN, 0);
  ------------------
  |  |  292|    728|#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|    728|#define IASECC_SFI_EF_SN	0x1C
  ------------------
 2511|    728|	apdu.le = sizeof(rbuf);
 2512|    728|	apdu.resp = rbuf;
 2513|    728|	apdu.resplen = sizeof(rbuf);
 2514|       |
 2515|    728|	rv = sc_transmit_apdu(card, &apdu);
 2516|    728|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    728|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    728|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    728|	int _ret = (r); \
  |  |  |  |  168|    728|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 719]
  |  |  |  |  ------------------
  |  |  |  |  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|    728|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 719]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2517|    719|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2518|    719|	LOG_TEST_RET(ctx, rv, "Get 'serial number' data failed");
  ------------------
  |  |  174|    719|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    719|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    719|	int _ret = (r); \
  |  |  |  |  168|    719|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 441, False: 278]
  |  |  |  |  ------------------
  |  |  |  |  169|    441|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    441|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    441|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    441|		return _ret; \
  |  |  |  |  172|    441|	} \
  |  |  |  |  173|    719|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 278]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2519|       |
 2520|    278|	if (apdu.resplen < 2 || rbuf[0] != ISO7812_PAN_SN_TAG || rbuf[1] > (apdu.resplen-2))
  ------------------
  |  |   29|    302|#define ISO7812_PAN_SN_TAG	0x5A
  ------------------
  |  Branch (2520:6): [True: 254, False: 24]
  |  Branch (2520:26): [True: 10, False: 14]
  |  Branch (2520:59): [True: 2, False: 12]
  ------------------
 2521|    278|		LOG_TEST_RET(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "serial number parse error");
  ------------------
  |  |  174|    266|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    266|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    266|	int _ret = (r); \
  |  |  |  |  168|    266|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 266, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    266|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    266|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    266|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    266|		return _ret; \
  |  |  |  |  172|    266|	} \
  |  |  |  |  173|    266|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2522|     12|	len = rbuf[1];
 2523|       |
 2524|     12|	iin->mii = (rbuf[2] >> 4) & 0x0F;
 2525|       |
 2526|     12|	iin->country = 0;
 2527|     48|	for (ii=5; ii<8; ii++)   {
  ------------------
  |  Branch (2527:13): [True: 36, False: 12]
  ------------------
 2528|     36|		iin->country *= 10;
 2529|     36|		iin->country += (rbuf[ii/2] >> ((ii & 0x01) ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2529:35): [True: 24, False: 12]
  ------------------
 2530|     36|	}
 2531|       |
 2532|     12|	iin->issuer_id = 0;
 2533|     36|	for (ii=8; ii<10; ii++)   {
  ------------------
  |  Branch (2533:13): [True: 24, False: 12]
  ------------------
 2534|     24|		iin->issuer_id *= 10;
 2535|     24|		iin->issuer_id += (rbuf[ii/2] >> (ii & 0x01 ? 0 : 4)) & 0x0F;
  ------------------
  |  Branch (2535:37): [True: 12, False: 12]
  ------------------
 2536|     24|	}
 2537|       |
 2538|       |	/* Copy the serial number from the last 8 bytes (at most) */
 2539|     12|	offs = len > 8 ? len - 8 : 0;
  ------------------
  |  Branch (2539:9): [True: 1, False: 11]
  ------------------
 2540|     12|	if (card->type == SC_CARD_TYPE_IASECC_SAGEM)   {
  ------------------
  |  Branch (2540:6): [True: 5, False: 7]
  ------------------
 2541|       |		/* 5A 0A 92 50 00 20 10 10 25 00 01 3F */
 2542|       |		/*            00 02 01 01 02 50 00 13  */
 2543|     24|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2543:14): [True: 19, False: 5]
  ------------------
 2544|     19|			*(card->serialnr.value + ii) = ((rbuf[ii + offs + 1] & 0x0F) << 4)
 2545|     19|				+ ((rbuf[ii + offs + 2] & 0xF0) >> 4) ;
 2546|      5|		card->serialnr.len = ii;
 2547|      5|	}
 2548|      7|	else   {
 2549|     29|		for (ii=0; ii < len - offs; ii++)
  ------------------
  |  Branch (2549:14): [True: 22, False: 7]
  ------------------
 2550|     22|			*(card->serialnr.value + ii) = rbuf[ii + offs + 2];
 2551|      7|		card->serialnr.len = ii;
 2552|      7|	}
 2553|       |
 2554|     12|	do  {
 2555|     12|		char txt[0x200];
 2556|       |
 2557|     53|		for (ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (2557:13): [True: 41, False: 12]
  ------------------
 2558|     41|			sprintf(txt + ii*2, "%02X", *(card->serialnr.value + ii));
 2559|       |
 2560|     12|		sc_log(ctx, "serial number '%s'; mii %i; country %i; issuer_id %li", txt, iin->mii, iin->country, iin->issuer_id);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2561|     12|	} while(0);
  ------------------
  |  Branch (2561:10): [Folded, False: 12]
  ------------------
 2562|       |
 2563|     12|end:
 2564|     12|	if (serial)
  ------------------
  |  Branch (2564:6): [True: 1, False: 11]
  ------------------
 2565|      1|		memcpy(serial, &card->serialnr, sizeof(*serial));
 2566|       |
 2567|     12|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     12|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     12|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     12|	int _ret = r; \
  |  |  |  |  155|     12|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 12]
  |  |  |  |  ------------------
  |  |  |  |  157|     12|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     12|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     12|	return _ret; \
  |  |  |  |  163|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2568|     12|}
card-iasecc.c:_iasecc_sm_read_binary:
  770|    271|{
  771|    271|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
  772|    271|	struct sc_context *ctx = card->ctx;
  773|    271|	const struct sc_acl_entry *entry = NULL;
  774|    271|	int rv;
  775|       |
  776|    271|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    271|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    271|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    271|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    271|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 271]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  777|    271|	sc_log(ctx,
  ------------------
  |  |   71|    271|#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|    271|	       "iasecc_sm_read_binary() card:%p offs:%i count:%"SC_FORMAT_LEN_SIZE_T"u ",
  779|    271|	       card, offs, count);
  780|    271|	if (offs > 0x7fff)
  ------------------
  |  Branch (780:6): [True: 0, False: 271]
  ------------------
  781|    271|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  782|       |
  783|    271|	if (count == 0)
  ------------------
  |  Branch (783:6): [True: 0, False: 271]
  ------------------
  784|      0|		return 0;
  785|       |
  786|    271|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (786:6): [True: 271, False: 0]
  |  Branch (786:26): [True: 256, False: 15]
  ------------------
  787|    256|		entry = sc_file_get_acl_entry(prv->cache.current_ef, SC_AC_OP_READ);
  ------------------
  |  |  188|    256|#define SC_AC_OP_READ			22
  ------------------
  788|    256|		if (!entry)
  ------------------
  |  Branch (788:7): [True: 16, False: 240]
  ------------------
  789|    256|			LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "iasecc_sm_read() 'READ' ACL not present");
  ------------------
  |  |  174|     16|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     16|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     16|	int _ret = (r); \
  |  |  |  |  168|     16|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  790|       |
  791|    240|		sc_log(ctx, "READ method/reference %X/%X", entry->method, entry->key_ref);
  ------------------
  |  |   71|    240|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  792|    240|		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |  157|    240|#define SC_AC_SCB                       0x00000040 /* IAS/ECC SCB byte. */
  ------------------
              		if ((entry->method == SC_AC_SCB) && (entry->key_ref & IASECC_SCB_METHOD_SM))   {
  ------------------
  |  |   91|    214|#define IASECC_SCB_METHOD_SM		0x40
  ------------------
  |  Branch (792:7): [True: 214, False: 26]
  |  Branch (792:39): [True: 201, False: 13]
  ------------------
  793|    201|			unsigned char se_num = entry->key_ref & IASECC_SCB_METHOD_MASK_REF;
  ------------------
  |  |   90|    201|#define IASECC_SCB_METHOD_MASK_REF	0x0F
  ------------------
  794|       |
  795|    201|			rv = iasecc_sm_read_binary(card, se_num, offs, buff, count);
  796|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  797|    201|		}
  798|    240|	}
  799|       |
  800|     54|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|     54|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     54|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     54|	int _ret = r; \
  |  |  |  |  155|     54|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 54, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     54|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  157|     54|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     54|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     54|	return _ret; \
  |  |  |  |  163|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  801|     54|}
card-iasecc.c:iasecc_finish:
 1438|    521|{
 1439|    521|	struct sc_context *ctx = card->ctx;
 1440|    521|	struct iasecc_private_data *private_data = (struct iasecc_private_data *)card->drv_data;
 1441|    521|	struct iasecc_se_info *se_info = private_data->se_info, *next;
 1442|       |
 1443|    521|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    521|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    521|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    521|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    521|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 521]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1444|       |
 1445|    521|	sc_invalidate_cache(card);
 1446|       |
 1447|    555|	while (se_info)   {
  ------------------
  |  Branch (1447:9): [True: 34, False: 521]
  ------------------
 1448|     34|		sc_file_free(se_info->df);
 1449|     34|		next = se_info->next;
 1450|     34|		free(se_info);
 1451|     34|		se_info = next;
 1452|     34|	}
 1453|       |
 1454|    521|	free(card->drv_data);
 1455|    521|	card->drv_data = NULL;
 1456|       |
 1457|    521|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|    521|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    521|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    521|	int _ret = r; \
  |  |  |  |  155|    521|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 521, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    521|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 521]
  |  |  |  |  ------------------
  |  |  |  |  157|    521|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    521|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    521|	return _ret; \
  |  |  |  |  163|    521|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1458|    521|}
card-iasecc.c:iasecc_read_binary:
  701|  1.28k|{
  702|  1.28k|	struct sc_context *ctx = card->ctx;
  703|  1.28k|	struct sc_apdu apdu;
  704|  1.28k|	int rv;
  705|       |
  706|  1.28k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  1.28k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  707|  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__
  |  |  ------------------
  ------------------
  708|  1.28k|	       "iasecc_read_binary(card:%p) offs %i; count %"SC_FORMAT_LEN_SIZE_T"u",
  709|  1.28k|	       card, offs, count);
  710|  1.28k|	if (offs > 0x7fff) {
  ------------------
  |  Branch (710:6): [True: 2, False: 1.27k]
  ------------------
  711|      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__
  |  |  ------------------
  ------------------
  712|      2|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      2|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  713|      2|	}
  714|       |
  715|  1.27k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB0, (offs >> 8) & 0x7F, offs & 0xFF);
  ------------------
  |  |  292|  1.27k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  716|  1.27k|	apdu.le = count < 0x100 ? count : 0x100;
  ------------------
  |  Branch (716:12): [True: 132, False: 1.14k]
  ------------------
  717|  1.27k|	apdu.resplen = count;
  718|  1.27k|	apdu.resp = buf;
  719|       |
  720|  1.27k|	rv = sc_transmit_apdu(card, &apdu);
  721|  1.27k|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.27k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.27k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.27k|	int _ret = (r); \
  |  |  |  |  168|  1.27k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 1.26k]
  |  |  |  |  ------------------
  |  |  |  |  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.27k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.26k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  722|  1.26k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
  723|  1.26k|	LOG_TEST_RET(ctx, rv, "iasecc_read_binary() failed");
  ------------------
  |  |  174|  1.26k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.26k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.26k|	int _ret = (r); \
  |  |  |  |  168|  1.26k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 331, False: 930]
  |  |  |  |  ------------------
  |  |  |  |  169|    331|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    331|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    331|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    331|		return _ret; \
  |  |  |  |  172|    331|	} \
  |  |  |  |  173|  1.26k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 930]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  724|    930|	sc_log(ctx,
  ------------------
  |  |   71|    930|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  725|    930|	       "iasecc_read_binary() apdu.resplen %"SC_FORMAT_LEN_SIZE_T"u",
  726|    930|	       apdu.resplen);
  727|       |
  728|    930|	if (apdu.resplen == IASECC_READ_BINARY_LENGTH_MAX && apdu.resplen < count)   {
  ------------------
  |  |   76|  1.86k|#define IASECC_READ_BINARY_LENGTH_MAX	0xE7
  ------------------
  |  Branch (728:6): [True: 56, False: 874]
  |  Branch (728:55): [True: 55, False: 1]
  ------------------
  729|     55|		rv = iasecc_read_binary(card, (int)(offs + apdu.resplen), buf + apdu.resplen, count - apdu.resplen, flags);
  730|     55|		if (rv != SC_ERROR_WRONG_LENGTH)   {
  ------------------
  |  |   56|     55|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  |  Branch (730:7): [True: 45, False: 10]
  ------------------
  731|     45|			LOG_TEST_RET(ctx, rv, "iasecc_read_binary() read tail failed");
  ------------------
  |  |  174|     45|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     45|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     45|	int _ret = (r); \
  |  |  |  |  168|     45|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 19, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  732|     26|			apdu.resplen += rv;
  733|     26|		}
  734|     55|	}
  735|       |
  736|    911|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    911|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    911|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    911|	int _ret = r; \
  |  |  |  |  155|    911|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 32, False: 879]
  |  |  |  |  ------------------
  |  |  |  |  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|    879|	} else { \
  |  |  |  |  159|    879|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    879|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    879|	} \
  |  |  |  |  162|    911|	return _ret; \
  |  |  |  |  163|    911|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|    911|}
card-iasecc.c:iasecc_sdo_get_data:
 2880|    197|{
 2881|    197|	struct sc_context *ctx = card->ctx;
 2882|    197|	int rv, sdo_tag;
 2883|       |
 2884|    197|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    197|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    197|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    197|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    197|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 197]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2885|       |
 2886|    197|	sdo_tag = iasecc_sdo_tag_from_class(sdo->sdo_class);
 2887|       |
 2888|    197|	rv = iasecc_sdo_get_tagged_data(card, sdo_tag, sdo);
 2889|       |	/* When there is no public data 'GET DATA' returns error */
 2890|    197|	if (rv != SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|    197|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (2890:6): [True: 193, False: 4]
  ------------------
 2891|    197|		LOG_TEST_RET(ctx, rv, "cannot parse ECC SDO data");
  ------------------
  |  |  174|    193|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    193|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    193|	int _ret = (r); \
  |  |  |  |  168|    193|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 192, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|    192|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    192|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    192|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    192|		return _ret; \
  |  |  |  |  172|    192|	} \
  |  |  |  |  173|    193|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2892|       |
 2893|      5|	rv = iasecc_sdo_get_tagged_data(card, IASECC_DOCP_TAG, sdo);
  ------------------
  |  |   31|      5|#define IASECC_DOCP_TAG				0xA0
  ------------------
 2894|      5|	LOG_TEST_RET(ctx, rv, "cannot parse ECC DOCP data");
  ------------------
  |  |  174|      5|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      5|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      5|	int _ret = (r); \
  |  |  |  |  168|      5|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      5|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      5|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      5|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      5|		return _ret; \
  |  |  |  |  172|      5|	} \
  |  |  |  |  173|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2895|       |
 2896|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2897|      0|}
card-iasecc.c:iasecc_sdo_tag_from_class:
 2781|    197|{
 2782|    197|	switch (sdo_class & ~IASECC_OBJECT_REF_LOCAL)   {
  ------------------
  |  |   59|    197|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2782:10): [True: 197, False: 0]
  ------------------
 2783|    197|	case IASECC_SDO_CLASS_CHV:
  ------------------
  |  |   98|    197|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
  |  Branch (2783:2): [True: 197, False: 0]
  ------------------
 2784|    197|		return IASECC_SDO_CHV_TAG;
  ------------------
  |  |   63|    197|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
 2785|      0|	case IASECC_SDO_CLASS_RSA_PRIVATE:
  ------------------
  |  |  100|      0|#define IASECC_SDO_CLASS_RSA_PRIVATE	0x10
  ------------------
  |  Branch (2785:2): [True: 0, False: 197]
  ------------------
 2786|      0|		return IASECC_SDO_PRVKEY_TAG;
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
 2787|      0|	case IASECC_SDO_CLASS_RSA_PUBLIC:
  ------------------
  |  |  101|      0|#define IASECC_SDO_CLASS_RSA_PUBLIC	0x20
  ------------------
  |  Branch (2787:2): [True: 0, False: 197]
  ------------------
 2788|      0|		return IASECC_SDO_PUBKEY_TAG;
  ------------------
  |  |   76|      0|#define IASECC_SDO_PUBKEY_TAG			0x7F49
  ------------------
 2789|      0|	case IASECC_SDO_CLASS_SE:
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
  |  Branch (2789:2): [True: 0, False: 197]
  ------------------
 2790|      0|		return IASECC_SDO_CLASS_SE;
  ------------------
  |  |  102|      0|#define IASECC_SDO_CLASS_SE		0x7B
  ------------------
 2791|      0|	case IASECC_SDO_CLASS_KEYSET:
  ------------------
  |  |   99|      0|#define IASECC_SDO_CLASS_KEYSET		0x0A
  ------------------
  |  Branch (2791:2): [True: 0, False: 197]
  ------------------
 2792|      0|		return IASECC_SDO_KEYSET_TAG;
  ------------------
  |  |   83|      0|#define IASECC_SDO_KEYSET_TAG			0xA2
  ------------------
 2793|    197|	}
 2794|       |
 2795|      0|	return -1;
 2796|    197|}
card-iasecc.c:iasecc_sdo_get_tagged_data:
 2801|    202|{
 2802|    202|	struct sc_context *ctx = card->ctx;
 2803|    202|	struct sc_apdu apdu;
 2804|    202|	unsigned char sbuf[0x100];
 2805|    202|	size_t offs = sizeof(sbuf) - 1;
 2806|    202|	unsigned char rbuf[0x400];
 2807|    202|	int rv;
 2808|       |
 2809|    202|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    202|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    202|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    202|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    202|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 202]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2810|       |
 2811|    202|	sc_log(ctx, "sdo_tag=0x%x sdo_ref=0x%x sdo_class=0x%x", sdo_tag,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2812|    202|			sdo->sdo_ref, sdo->sdo_class);
 2813|       |
 2814|       |	/* XXX: for the CPx, the SDO are available from some specific path */
 2815|    202|	if (iasecc_is_cpx(card)) {
  ------------------
  |  Branch (2815:6): [True: 7, False: 195]
  ------------------
 2816|      7|		struct sc_path path;
 2817|      7|		char *path_str = NULL;
 2818|      7|		switch(sdo_tag) {
 2819|      0|			case IASECC_SDO_PRVKEY_TAG:
  ------------------
  |  |   68|      0|#define IASECC_SDO_PRVKEY_TAG			0x7F48
  ------------------
  |  Branch (2819:4): [True: 0, False: 7]
  ------------------
 2820|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 90 02 03 7F 48 80 */
 2821|      0|			path_str = "3F00:0001";
 2822|      0|			break;
 2823|      5|			case IASECC_SDO_CHV_TAG:
  ------------------
  |  |   63|      5|#define IASECC_SDO_CHV_TAG		0x7F41
  ------------------
  |  Branch (2823:4): [True: 5, False: 2]
  ------------------
 2824|       |			/* APDU 00 CB 3F FF 0B 4D 09 70 07 BF 81 01 03 7F 41 80 */
 2825|      5|			path_str = "3F00";
 2826|      5|			break;
 2827|      2|			default:
  ------------------
  |  Branch (2827:4): [True: 2, False: 5]
  ------------------
 2828|      2|			path_str = NULL;
 2829|      2|			break;
 2830|      7|		}
 2831|      7|		if (path_str) {
  ------------------
  |  Branch (2831:7): [True: 5, False: 2]
  ------------------
 2832|      5|			sc_log(ctx, "Warning: Enforce the path=%s", path_str);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2833|      5|			sc_format_path(path_str, &path);
 2834|      5|			rv = iasecc_select_file(card, &path, NULL);
 2835|      5|			LOG_TEST_RET(ctx, rv, "path 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: 3, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|      5|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2836|      5|		}
 2837|      7|	}
 2838|       |
 2839|    199|	sbuf[offs--] = 0x80;
 2840|    199|	sbuf[offs--] = sdo_tag & 0xFF;
 2841|    199|	if ((sdo_tag >> 8) & 0xFF)
  ------------------
  |  Branch (2841:6): [True: 194, False: 5]
  ------------------
 2842|    194|		sbuf[offs--] = (sdo_tag >> 8) & 0xFF;
 2843|    199|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2844|    199|	offs--;
 2845|       |
 2846|    199|	sbuf[offs--] = sdo->sdo_ref & 0x9F;
 2847|    199|	sbuf[offs--] = sdo->sdo_class | IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    199|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2848|    199|	sbuf[offs--] = IASECC_SDO_TAG_HEADER;
  ------------------
  |  |   27|    199|#define IASECC_SDO_TAG_HEADER	0xBF
  ------------------
 2849|       |
 2850|    199|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2851|    199|	offs--;
 2852|    199|	sbuf[offs--] = IASECC_SDO_TEMPLATE_TAG;
  ------------------
  |  |   29|    199|#define IASECC_SDO_TEMPLATE_TAG	0x70
  ------------------
 2853|       |
 2854|    199|	sbuf[offs] = sizeof(sbuf) - offs - 1;
 2855|    199|	offs--;
 2856|    199|	sbuf[offs] = 0x4D;
 2857|       |
 2858|    199|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xCB, 0x3F, 0xFF);
  ------------------
  |  |  294|    199|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 2859|    199|	apdu.data = sbuf + offs;
 2860|    199|	apdu.datalen = sizeof(sbuf) - offs;
 2861|    199|	apdu.lc = sizeof(sbuf) - offs;
 2862|    199|	apdu.resp = rbuf;
 2863|    199|	apdu.resplen = sizeof(rbuf);
 2864|    199|	apdu.le = 0x100;
 2865|       |
 2866|    199|	rv = sc_transmit_apdu(card, &apdu);
 2867|    199|	LOG_TEST_RET(ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    199|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    199|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    199|	int _ret = (r); \
  |  |  |  |  168|    199|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 196]
  |  |  |  |  ------------------
  |  |  |  |  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|    199|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 196]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2868|    196|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2869|    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: 14, False: 182]
  |  |  |  |  ------------------
  |  |  |  |  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|    196|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 182]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2870|       |
 2871|    182|	rv = iasecc_sdo_parse(card, apdu.resp, apdu.resplen, sdo);
 2872|    182|	LOG_TEST_RET(ctx, rv, "cannot parse SDO 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: 181, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  169|    181|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    181|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    181|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    181|		return _ret; \
  |  |  |  |  172|    181|	} \
  |  |  |  |  173|    182|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2873|       |
 2874|      1|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2875|      1|}
card-iasecc.c:iasecc_check_sw:
 1511|  8.62k|{
 1512|  8.62k|	if (sw1 == 0x62 && sw2 == 0x82)
  ------------------
  |  Branch (1512:6): [True: 289, False: 8.33k]
  |  Branch (1512:21): [True: 260, False: 29]
  ------------------
 1513|    260|		return SC_SUCCESS;
  ------------------
  |  |   28|    260|#define SC_SUCCESS				0
  ------------------
 1514|       |
 1515|  8.36k|	return iso_ops->check_sw(card, sw1, sw2);
 1516|  8.62k|}
card-iasecc.c:iasecc_card_ctl:
 3005|    207|{
 3006|    207|	struct sc_context *ctx = card->ctx;
 3007|    207|	struct iasecc_sdo *sdo = (struct iasecc_sdo *) ptr;
 3008|       |
 3009|    207|	switch (cmd) {
  ------------------
  |  Branch (3009:10): [True: 207, False: 0]
  ------------------
 3010|    207|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (3010:2): [True: 207, False: 0]
  ------------------
 3011|    207|		return iasecc_get_serialnr(card, (struct sc_serial_number *)ptr);
 3012|      0|	case SC_CARDCTL_IASECC_SDO_CREATE:
  ------------------
  |  Branch (3012:2): [True: 0, False: 207]
  ------------------
 3013|      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__
  |  |  ------------------
  ------------------
 3014|      0|		return iasecc_sdo_create(card, (struct iasecc_sdo *) ptr);
 3015|      0|	case SC_CARDCTL_IASECC_SDO_DELETE:
  ------------------
  |  Branch (3015:2): [True: 0, False: 207]
  ------------------
 3016|      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__
  |  |  ------------------
  ------------------
 3017|      0|		return iasecc_sdo_delete(card, (struct iasecc_sdo *) ptr);
 3018|      0|	case SC_CARDCTL_IASECC_SDO_PUT_DATA:
  ------------------
  |  Branch (3018:2): [True: 0, False: 207]
  ------------------
 3019|      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__
  |  |  ------------------
  ------------------
 3020|      0|		return iasecc_sdo_put_data(card, (struct iasecc_sdo_update *) ptr);
 3021|      0|	case SC_CARDCTL_IASECC_SDO_KEY_RSA_PUT_DATA:
  ------------------
  |  Branch (3021:2): [True: 0, False: 207]
  ------------------
 3022|      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__
  |  |  ------------------
  ------------------
 3023|      0|		return iasecc_sdo_key_rsa_put_data(card, (struct iasecc_sdo_rsa_update *) ptr);
 3024|      0|	case SC_CARDCTL_IASECC_SDO_GET_DATA:
  ------------------
  |  Branch (3024:2): [True: 0, False: 207]
  ------------------
 3025|      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__
  |  |  ------------------
  ------------------
 3026|      0|		return iasecc_sdo_get_data(card, (struct iasecc_sdo *) ptr);
 3027|      0|	case SC_CARDCTL_IASECC_SDO_GENERATE:
  ------------------
  |  Branch (3027:2): [True: 0, False: 207]
  ------------------
 3028|      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__
  |  |  ------------------
  ------------------
 3029|      0|		return iasecc_sdo_generate(card, (struct iasecc_sdo *) ptr);
 3030|      0|	case SC_CARDCTL_GET_SE_INFO:
  ------------------
  |  Branch (3030:2): [True: 0, False: 207]
  ------------------
 3031|      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__
  |  |  ------------------
  ------------------
 3032|      0|		return iasecc_se_get_info(card, (struct iasecc_se_info *) ptr);
 3033|      0|	case SC_CARDCTL_GET_CHV_REFERENCE_IN_SE:
  ------------------
  |  Branch (3033:2): [True: 0, False: 207]
  ------------------
 3034|      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__
  |  |  ------------------
  ------------------
 3035|      0|		return iasecc_get_chv_reference_from_se(card, (int *)ptr);
 3036|      0|	case SC_CARDCTL_IASECC_GET_FREE_KEY_REFERENCE:
  ------------------
  |  Branch (3036:2): [True: 0, False: 207]
  ------------------
 3037|      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__
  |  |  ------------------
  ------------------
 3038|      0|		return iasecc_get_free_reference(card, (struct iasecc_ctl_get_free_reference *)ptr);
 3039|    207|	}
 3040|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 3041|    207|}
card-iasecc.c:iasecc_pin_cmd:
 2460|    207|{
 2461|    207|	struct sc_context *ctx = card->ctx;
 2462|    207|	int rv;
 2463|       |
 2464|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2465|    207|	sc_log(ctx, "iasecc_pin_cmd() cmd 0x%X, PIN type 0x%X, PIN reference %i, PIN-1 %p:%zu, PIN-2 %p:%zu",
  ------------------
  |  |   71|    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__
  |  |  ------------------
  ------------------
 2466|    207|			data->cmd, data->pin_type, data->pin_reference,
 2467|    207|			data->pin1.data, data->pin1.len, data->pin2.data, data->pin2.len);
 2468|       |
 2469|    207|	switch (data->cmd)   {
 2470|      0|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (2470:2): [True: 0, False: 207]
  ------------------
 2471|      0|		rv = iasecc_pin_verify(card, data, tries_left);
 2472|      0|		break;
 2473|      0|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2473:2): [True: 0, False: 207]
  ------------------
 2474|      0|		if (data->pin_type == SC_AC_AUT)
  ------------------
  |  |  154|      0|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  |  Branch (2474:7): [True: 0, False: 0]
  ------------------
 2475|      0|			rv = iasecc_keyset_change(card, data, tries_left);
 2476|      0|		else
 2477|      0|			rv = iasecc_pin_change(card, data, tries_left);
 2478|      0|		break;
 2479|      0|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2479:2): [True: 0, False: 207]
  ------------------
 2480|      0|		rv = iasecc_pin_reset(card, data, tries_left);
 2481|      0|		break;
 2482|    207|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|    207|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (2482:2): [True: 207, False: 0]
  ------------------
 2483|    207|		rv = iasecc_pin_get_info(card, data, tries_left);
 2484|    207|		break;
 2485|      0|	default:
  ------------------
  |  Branch (2485:2): [True: 0, False: 207]
  ------------------
 2486|      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__
  |  |  ------------------
  ------------------
 2487|      0|		rv = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 2488|    207|	}
 2489|       |
 2490|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2491|    207|}
card-iasecc.c:iasecc_pin_get_status:
 1921|    207|{
 1922|    207|	struct sc_context *ctx = card->ctx;
 1923|    207|	struct sc_pin_cmd_data info;
 1924|    207|	int rv;
 1925|       |
 1926|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1927|       |
 1928|    207|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|    207|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1928:6): [True: 0, False: 207]
  ------------------
 1929|    207|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1930|       |
 1931|    207|	memset(&info, 0, sizeof(info));
 1932|    207|	info.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  425|    207|#define SC_PIN_CMD_GET_INFO	3
  ------------------
 1933|    207|	info.pin_type = data->pin_type;
 1934|    207|	info.pin_reference = data->pin_reference;
 1935|       |
 1936|    207|	rv = iso_ops->pin_cmd(card, &info, tries_left);
 1937|    207|	LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
  ------------------
  |  |  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: 7, False: 200]
  |  |  |  |  ------------------
  |  |  |  |  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|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1938|       |
 1939|    200|	data->pin1.max_tries = info.pin1.max_tries;
 1940|    200|	data->pin1.tries_left = info.pin1.tries_left;
 1941|    200|	data->pin1.logged_in = info.pin1.logged_in;
 1942|       |
 1943|    200|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    200|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    200|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    200|	int _ret = r; \
  |  |  |  |  155|    200|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 200]
  |  |  |  |  ------------------
  |  |  |  |  157|    200|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    200|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    200|	return _ret; \
  |  |  |  |  163|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1944|    200|}
card-iasecc.c:iasecc_pin_get_policy:
 2041|    200|{
 2042|    200|	struct iasecc_private_data *prv = (struct iasecc_private_data *)card->drv_data;
 2043|    200|	struct sc_context *ctx = card->ctx;
 2044|    200|	struct sc_file *save_current_df = NULL, *save_current_ef = NULL;
 2045|    200|	struct iasecc_sdo sdo;
 2046|    200|	struct sc_path path;
 2047|    200|	int rv;
 2048|       |
 2049|    200|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    200|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    200|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    200|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    200|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2050|    200|	sc_log(ctx, "iasecc_pin_get_policy(card:%p)", card);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2051|       |
 2052|    200|	if (data->pin_type != SC_AC_CHV)   {
  ------------------
  |  |  151|    200|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2052:6): [True: 0, False: 200]
  ------------------
 2053|      0|		sc_log(ctx, "PIN policy only available for CHV type");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2054|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2055|      0|	}
 2056|       |
 2057|    200|	if (prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  Branch (2057:6): [True: 200, False: 0]
  |  Branch (2057:26): [True: 7, False: 193]
  ------------------
 2058|      7|		sc_file_dup(&save_current_df, prv->cache.current_df);
 2059|      7|		if (save_current_df == NULL) {
  ------------------
  |  Branch (2059:7): [True: 0, False: 7]
  ------------------
 2060|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2061|      0|			sc_log(ctx, "Cannot duplicate current DF file");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2062|      0|			goto err;
 2063|      0|		}
 2064|      7|	}
 2065|       |
 2066|    200|	if (prv->cache.valid && prv->cache.current_ef) {
  ------------------
  |  Branch (2066:6): [True: 200, False: 0]
  |  Branch (2066:26): [True: 4, False: 196]
  ------------------
 2067|      4|		sc_file_dup(&save_current_ef, prv->cache.current_ef);
 2068|      4|		if (save_current_ef == NULL) {
  ------------------
  |  Branch (2068:7): [True: 0, False: 4]
  ------------------
 2069|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2070|      0|			sc_log(ctx, "Cannot duplicate current EF file");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2071|      0|			goto err;
 2072|      0|		}
 2073|      4|	}
 2074|       |
 2075|    200|	if (!(data->pin_reference & IASECC_OBJECT_REF_LOCAL) && prv->cache.valid && prv->cache.current_df) {
  ------------------
  |  |   59|    200|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
  |  Branch (2075:6): [True: 200, False: 0]
  |  Branch (2075:58): [True: 200, False: 0]
  |  Branch (2075:78): [True: 7, False: 193]
  ------------------
 2076|      7|		sc_format_path("3F00", &path);
 2077|      7|		path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      7|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 2078|      7|		rv = iasecc_select_file(card, &path, NULL);
 2079|      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: 3, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  179|      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
  |  |  |  |  ------------------
  |  |  |  |  180|      3|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      3|		goto err; \
  |  |  |  |  182|      3|	} \
  |  |  |  |  183|      7|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2080|      7|	}
 2081|       |
 2082|    197|	memset(&sdo, 0, sizeof(sdo));
 2083|    197|	sdo.sdo_class = IASECC_SDO_CLASS_CHV;
  ------------------
  |  |   98|    197|#define IASECC_SDO_CLASS_CHV		0x01
  ------------------
 2084|       |
 2085|    197|	sdo.sdo_ref = data->pin_reference & ~IASECC_OBJECT_REF_LOCAL;
  ------------------
  |  |   59|    197|#define IASECC_OBJECT_REF_LOCAL		0x80
  ------------------
 2086|       |
 2087|    197|	sc_log(ctx, "iasecc_pin_get_policy() reference %i", sdo.sdo_ref);
  ------------------
  |  |   71|    197|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2088|       |
 2089|    197|	rv = iasecc_sdo_get_data(card, &sdo);
 2090|    197|	LOG_TEST_GOTO_ERR(ctx, rv, "Cannot get SDO PIN data");
  ------------------
  |  |  184|    197|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    197|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    197|	int _ret = (r); \
  |  |  |  |  178|    197|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 197, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    197|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    197|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    197|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    197|		goto err; \
  |  |  |  |  182|    197|	} \
  |  |  |  |  183|    197|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2091|       |
 2092|      0|	if (sdo.docp.acls_contact.size == 0) {
  ------------------
  |  Branch (2092:6): [True: 0, False: 0]
  ------------------
 2093|      0|		rv = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2094|      0|		sc_log(ctx, "Extremely strange ... there is no ACLs");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2095|      0|		goto err;
 2096|      0|	}
 2097|       |
 2098|      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__
  |  |  ------------------
  ------------------
 2099|      0|	       "iasecc_pin_get_policy() sdo.docp.size.size %"SC_FORMAT_LEN_SIZE_T"u",
 2100|      0|	       sdo.docp.size.size);
 2101|       |
 2102|      0|	memcpy(pin->scbs, sdo.docp.scbs, sizeof(pin->scbs));
 2103|       |
 2104|      0|	pin->min_length = (sdo.data.chv.size_min.value ? *sdo.data.chv.size_min.value : -1);
  ------------------
  |  Branch (2104:21): [True: 0, False: 0]
  ------------------
 2105|      0|	pin->max_length = (sdo.data.chv.size_max.value ? *sdo.data.chv.size_max.value : -1);
  ------------------
  |  Branch (2105:21): [True: 0, False: 0]
  ------------------
 2106|      0|	pin->tries_maximum = (sdo.docp.tries_maximum.value ? *sdo.docp.tries_maximum.value : -1);
  ------------------
  |  Branch (2106:24): [True: 0, False: 0]
  ------------------
 2107|      0|	pin->tries_remaining = (sdo.docp.tries_remaining.value ? *sdo.docp.tries_remaining.value : -1);
  ------------------
  |  Branch (2107:26): [True: 0, False: 0]
  ------------------
 2108|      0|	if (sdo.docp.size.value && sdo.docp.size.size <= sizeof(int)) {
  ------------------
  |  Branch (2108:6): [True: 0, False: 0]
  |  Branch (2108:29): [True: 0, False: 0]
  ------------------
 2109|      0|		unsigned int n = 0;
 2110|      0|		unsigned int i;
 2111|      0|		for (i=0; i<sdo.docp.size.size; i++)
  ------------------
  |  Branch (2111:13): [True: 0, False: 0]
  ------------------
 2112|      0|			n = (n << 8) + *(sdo.docp.size.value + i);
 2113|      0|		pin->stored_length = n;
 2114|      0|	} else {
 2115|      0|		pin->stored_length = -1;
 2116|      0|	}
 2117|       |
 2118|      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__
  |  |  ------------------
  ------------------
 2119|      0|	       pin->max_length, pin->min_length, pin->tries_maximum, pin->tries_remaining);
 2120|      0|	iasecc_sdo_free_fields(card, &sdo);
 2121|       |
 2122|      0|	if (save_current_df)   {
  ------------------
  |  Branch (2122:6): [True: 0, False: 0]
  ------------------
 2123|      0|		sc_log(ctx, "iasecc_pin_get_policy() restore current DF");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2124|      0|		rv = iasecc_select_file(card, &save_current_df->path, NULL);
 2125|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2126|      0|	}
 2127|       |
 2128|      0|	if (save_current_ef)   {
  ------------------
  |  Branch (2128:6): [True: 0, False: 0]
  ------------------
 2129|      0|		sc_log(ctx, "iasecc_pin_get_policy() restore current EF");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2130|      0|		rv = iasecc_select_file(card, &save_current_ef->path, NULL);
 2131|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2132|      0|	}
 2133|       |
 2134|    200|err:
 2135|    200|	sc_file_free(save_current_df);
 2136|    200|	sc_file_free(save_current_ef);
 2137|       |
 2138|    200|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    200|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    200|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    200|	int _ret = r; \
  |  |  |  |  155|    200|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    200|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    200|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    200|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    200|	return _ret; \
  |  |  |  |  163|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2139|    200|}
card-iasecc.c:iasecc_pin_get_info:
 2144|    207|{
 2145|    207|	struct sc_context *ctx = card->ctx;
 2146|    207|	struct iasecc_pin_policy policy;
 2147|    207|	int rv;
 2148|       |
 2149|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2150|    207|	sc_log(ctx, "iasecc_pin_get_info(card:%p)", card);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2151|       |
 2152|       |	/*
 2153|       |	 * Get PIN status first and thereafter update with info from PIN policy, when available.
 2154|       |	 * The first one is typically used for the PIN verification status and number of remaining
 2155|       |	 * tries, and the second one for the maximum tries. If a field is present in both, the
 2156|       |	 * policy takes precedence.
 2157|       |	 */
 2158|    207|	rv = iasecc_pin_get_status(card, data, tries_left);
 2159|    207|	LOG_TEST_RET(ctx, rv, "Failed to get PIN status");
  ------------------
  |  |  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: 7, False: 200]
  |  |  |  |  ------------------
  |  |  |  |  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|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2160|       |
 2161|    200|	rv = iasecc_pin_get_policy(card, data, &policy);
 2162|    200|	LOG_TEST_RET(ctx, rv, "Failed to get PIN policy");
  ------------------
  |  |  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: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    200|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    200|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    200|		return _ret; \
  |  |  |  |  172|    200|	} \
  |  |  |  |  173|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2163|       |
 2164|       |	/*
 2165|       |	 * We only care about the tries_xxx fields in the PIN policy, since the other ones are not
 2166|       |	 * commonly expected or used in a SC_PIN_CMD_GET_INFO response.	Note that max_tries is
 2167|       |	 * always taken from the policy, since it is never expected to be available in status (it
 2168|       |	 * is set to -1 when not available in policy).
 2169|       |	 */
 2170|      0|	data->pin1.max_tries = policy.tries_maximum;
 2171|      0|	if (policy.tries_remaining >= 0)
  ------------------
  |  Branch (2171:6): [True: 0, False: 0]
  ------------------
 2172|      0|		data->pin1.tries_left = policy.tries_remaining;
 2173|       |
 2174|      0|	if (tries_left)
  ------------------
  |  Branch (2174:6): [True: 0, False: 0]
  ------------------
 2175|      0|		*tries_left = data->pin1.tries_left;
 2176|       |
 2177|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2178|      0|}

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

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

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

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

sc_get_lteid_driver:
  563|  15.3k|{
  564|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  565|       |
  566|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (566:6): [True: 1, False: 15.3k]
  ------------------
  567|      1|		iso_ops = iso_drv->ops;
  568|       |
  569|  15.3k|	lteid_ops = *iso_ops;
  570|  15.3k|	lteid_ops.init = lteid_init;
  571|  15.3k|	lteid_ops.finish = lteid_finish;
  572|  15.3k|	lteid_ops.set_security_env = lteid_set_security_env;
  573|  15.3k|	lteid_ops.compute_signature = lteid_compute_signature;
  574|  15.3k|	lteid_ops.pin_cmd = lteid_pin_cmd;
  575|  15.3k|	lteid_ops.logout = lteid_logout;
  576|  15.3k|	lteid_ops.process_fci = lteid_process_fci;
  577|       |
  578|  15.3k|	return &lteid_drv;
  579|  15.3k|}

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

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

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

sc_get_myeid_driver:
 2146|  15.3k|{
 2147|  15.3k|	return sc_get_driver();
 2148|  15.3k|}
card-myeid.c:sc_get_driver:
 2111|  15.3k|{
 2112|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 2113|       |
 2114|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2114:6): [True: 1, False: 15.3k]
  ------------------
 2115|      1|		iso_ops = iso_drv->ops;
 2116|       |
 2117|  15.3k|	myeid_ops			= *iso_drv->ops;
 2118|  15.3k|	myeid_ops.match_card		= myeid_match_card;
 2119|  15.3k|	myeid_ops.init			= myeid_init;
 2120|  15.3k|	myeid_ops.finish		= myeid_finish;
 2121|       |	/* no record oriented file services */
 2122|  15.3k|	myeid_ops.read_record		= NULL;
 2123|  15.3k|	myeid_ops.write_record		= NULL;
 2124|  15.3k|	myeid_ops.append_record		= NULL;
 2125|       |	myeid_ops.update_record		= NULL;
 2126|  15.3k|	myeid_ops.select_file		= myeid_select_file;
 2127|  15.3k|	myeid_ops.get_response		= iso_ops->get_response;
 2128|  15.3k|	myeid_ops.logout		= myeid_logout;
 2129|  15.3k|	myeid_ops.create_file		= myeid_create_file;
 2130|  15.3k|	myeid_ops.delete_file		= myeid_delete_file;
 2131|  15.3k|	myeid_ops.list_files		= myeid_list_files;
 2132|  15.3k|	myeid_ops.set_security_env	= myeid_set_security_env;
 2133|  15.3k|	myeid_ops.compute_signature	= myeid_compute_signature;
 2134|  15.3k|	myeid_ops.decipher		= myeid_decipher;
 2135|  15.3k|	myeid_ops.process_fci		= myeid_process_fci;
 2136|  15.3k|	myeid_ops.card_ctl		= myeid_card_ctl;
 2137|  15.3k|	myeid_ops.pin_cmd		= myeid_pin_cmd;
 2138|  15.3k|	myeid_ops.wrap			= myeid_wrap_key;
 2139|  15.3k|	myeid_ops.unwrap		= myeid_unwrap_key;
 2140|  15.3k|	myeid_ops.encrypt_sym		= myeid_encrypt_sym;
 2141|  15.3k|	myeid_ops.decrypt_sym		= myeid_decrypt_sym;
 2142|  15.3k|	return &myeid_drv;
 2143|  15.3k|}
card-myeid.c:myeid_match_card:
  122|  8.19k|{
  123|  8.19k|	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.19k|	if (len >= 5) {
  ------------------
  |  Branch (126:6): [True: 3.83k, False: 4.36k]
  ------------------
  127|  3.83k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "MyEID", 5)) {
  ------------------
  |  Branch (127:7): [True: 303, False: 3.53k]
  ------------------
  128|    303|			sc_log(card->ctx, "Matched MyEID card");
  ------------------
  |  |   71|    303|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  129|    303|			card->type = SC_CARD_TYPE_MYEID_GENERIC;
  130|    303|			return 1;
  131|    303|		}
  132|       |		/* The software implementation of MyEID is identified by OsEID bytes */
  133|  3.53k|		if (!memcmp(&card->reader->atr_info.hist_bytes[len - 5], "OsEID", 5)) {
  ------------------
  |  Branch (133:7): [True: 9, False: 3.52k]
  ------------------
  134|      9|			sc_log(card->ctx, "Matched OsEID card");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  135|      9|			card->type = SC_CARD_TYPE_MYEID_OSEID;
  136|      9|			return 1;
  137|      9|		}
  138|  3.53k|	}
  139|  7.88k|	return 0;
  140|  8.19k|}
card-myeid.c:myeid_init:
  171|    312|{
  172|    312|	unsigned long flags = 0, ext_flags = 0;
  173|    312|	myeid_private_data_t *priv;
  174|    312|	u8 appletInfo[20];
  175|    312|	size_t appletInfoLen;
  176|    312|	myeid_card_caps_t card_caps;
  177|    312|	static struct sc_aid myeid_aid = { "\xA0\x00\x00\x00\x63\x50\x4B\x43\x53\x2D\x31\x35", 0x0C };
  178|    312|	int rv = 0;
  179|    312|	void *old_drv_data = card->drv_data;
  180|       |
  181|    312|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    312|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    312|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    312|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    312|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 312]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  182|       |
  183|    312|	switch (card->type) {
  184|      9|	case SC_CARD_TYPE_MYEID_OSEID:
  ------------------
  |  Branch (184:2): [True: 9, False: 303]
  ------------------
  185|      9|		card->name = oseid_card_name;
  186|      9|		break;
  187|    303|	case SC_CARD_TYPE_MYEID_GENERIC:
  ------------------
  |  Branch (187:2): [True: 303, False: 9]
  ------------------
  188|    303|		card->name = myeid_card_name;
  189|    303|		break;
  190|      0|	default:
  ------------------
  |  Branch (190:2): [True: 0, False: 312]
  ------------------
  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|    312|	}
  193|       |
  194|    312|	priv = calloc(1, sizeof(myeid_private_data_t));
  195|       |
  196|    312|	if (!priv)
  ------------------
  |  Branch (196:6): [True: 0, False: 312]
  ------------------
  197|    312|		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|    312|	rv = myeid_load_options (card->ctx, priv);
  200|    312|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Unable to read options from opensc.conf");
  ------------------
  |  |  184|    312|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    312|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    312|	int _ret = (r); \
  |  |  |  |  178|    312|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 312]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    312|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 312]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  201|       |
  202|    312|	priv->card_state = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|    312|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  203|    312|	card->drv_data = priv;
  204|       |
  205|       |	/* Ensure that the MyEID applet is selected. */
  206|    312|	rv = iso7816_select_aid(card, myeid_aid.value, myeid_aid.len, NULL, NULL);
  207|    312|	LOG_TEST_GOTO_ERR(card->ctx, rv, "Failed to select MyEID applet.");
  ------------------
  |  |  184|    312|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    312|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    312|	int _ret = (r); \
  |  |  |  |  178|    312|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 10, False: 302]
  |  |  |  |  ------------------
  |  |  |  |  179|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     10|		goto err; \
  |  |  |  |  182|     10|	} \
  |  |  |  |  183|    312|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 302]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  208|       |
  209|       |	/* find out MyEID version */
  210|       |
  211|    302|	appletInfoLen = 20;
  212|       |
  213|    302|	if (0 > myeid_get_info(card, appletInfo, appletInfoLen))
  ------------------
  |  Branch (213:6): [True: 66, False: 236]
  ------------------
  214|    302|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to get MyEID applet information.");
  ------------------
  |  |  184|     66|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     66|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     66|	int _ret = (r); \
  |  |  |  |  178|     66|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 66, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     66|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     66|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     66|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     66|		goto err; \
  |  |  |  |  182|     66|	} \
  |  |  |  |  183|     66|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  215|       |
  216|    236|	priv->change_counter = appletInfo[19] | appletInfo[18] << 8;
  217|       |
  218|    236|	memset(&card_caps, 0, sizeof(myeid_card_caps_t));
  219|    236|	card_caps.max_ecc_key_length = 256;
  220|    236|	card_caps.max_rsa_key_length = 2048;
  221|       |
  222|    236|	if (card->version.fw_major >= 40) {
  ------------------
  |  Branch (222:6): [True: 207, False: 29]
  ------------------
  223|       |	    /* Since 4.0, we can query available algorithms and key sizes.
  224|       |	     * Since 3.5.0 RSA up to 2048 and ECC up to 256 are always supported, so we check only max ECC key length. */
  225|    207|	    if (myeid_get_card_caps(card, &card_caps) != SC_SUCCESS) {
  ------------------
  |  |   28|    207|#define SC_SUCCESS				0
  ------------------
  |  Branch (225:10): [True: 164, False: 43]
  ------------------
  226|    164|			sc_log(card->ctx, "Failed to get card capabilities. Using default max ECC key length 256.");
  ------------------
  |  |   71|    164|#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|    164|	    }
  228|    207|	}
  229|       |
  230|    236|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  111|    236|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    236|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  231|    236|	if (priv->disable_hw_pkcs1_padding == 0)
  ------------------
  |  Branch (231:6): [True: 236, False: 0]
  ------------------
  232|    236|		flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|    236|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    236|#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) */
  |  |  ------------------
  |  |  |  |  119|    236|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  233|    236|	flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|    236|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  234|       |
  235|    236|	_sc_card_add_rsa_alg(card,  512, flags, 0);
  236|    236|	_sc_card_add_rsa_alg(card,  768, flags, 0);
  237|    236|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  238|    236|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
  239|    236|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  240|       |
  241|    236|	if (card_caps.card_supported_features & MYEID_CARD_CAP_RSA) {
  ------------------
  |  |   50|    236|#define MYEID_CARD_CAP_RSA		0x01
  ------------------
  |  Branch (241:6): [True: 35, False: 201]
  ------------------
  242|     35|		if (card_caps.max_rsa_key_length >= 3072)
  ------------------
  |  Branch (242:7): [True: 23, False: 12]
  ------------------
  243|     23|			_sc_card_add_rsa_alg(card, 3072, flags, 0);
  244|     35|		if (card_caps.max_rsa_key_length >= 4096)
  ------------------
  |  Branch (244:7): [True: 20, False: 15]
  ------------------
  245|     20|			_sc_card_add_rsa_alg(card, 4096, flags, 0);
  246|     35|	}
  247|       |
  248|       |	/* show ECC algorithms if the applet version of the inserted card supports them */
  249|    236|	if (card->version.fw_major >= 35) {
  ------------------
  |  Branch (249:6): [True: 208, False: 28]
  ------------------
  250|    208|		int i;
  251|       |
  252|    208|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  183|    208|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  182|    208|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    208|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  253|    208|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    208|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    208|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  254|    208|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    208|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    208|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
  255|       |
  256|  1.04k|		for (i=0; ec_curves[i].curve_name != NULL; i++) {
  ------------------
  |  Branch (256:13): [True: 832, False: 208]
  ------------------
  257|    832|			if (card_caps.max_ecc_key_length >= ec_curves[i].size)
  ------------------
  |  Branch (257:8): [True: 460, False: 372]
  ------------------
  258|    460|				_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].curve_oid);
  259|    832|		}
  260|    208|	}
  261|       |
  262|       |	/* show supported symmetric algorithms */
  263|    236|	flags = 0;
  264|    236|	if (card_caps.card_supported_features & MYEID_CARD_CAP_3DES) {
  ------------------
  |  |   51|    236|#define MYEID_CARD_CAP_3DES		0x02
  ------------------
  |  Branch (264:6): [True: 34, False: 202]
  ------------------
  265|     34|		if (card_caps.max_des_key_length >= 64)
  ------------------
  |  Branch (265:7): [True: 28, False: 6]
  ------------------
  266|     28|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_DES, 64, flags);
  ------------------
  |  |   85|     28|#define SC_ALGORITHM_DES		64
  ------------------
  267|     34|		if (card_caps.max_des_key_length >= 128)
  ------------------
  |  Branch (267:7): [True: 24, False: 10]
  ------------------
  268|     24|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 128, flags);
  ------------------
  |  |   86|     24|#define SC_ALGORITHM_3DES		65
  ------------------
  269|     34|		if (card_caps.max_des_key_length >= 192)
  ------------------
  |  Branch (269:7): [True: 23, False: 11]
  ------------------
  270|     23|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_3DES, 192, flags);
  ------------------
  |  |   86|     23|#define SC_ALGORITHM_3DES		65
  ------------------
  271|     34|	}
  272|    236|	if (card_caps.card_supported_features & MYEID_CARD_CAP_AES) {
  ------------------
  |  |   52|    236|#define MYEID_CARD_CAP_AES		0x04
  ------------------
  |  Branch (272:6): [True: 38, False: 198]
  ------------------
  273|     38|		if (card_caps.max_aes_key_length >= 128)
  ------------------
  |  Branch (273:7): [True: 30, False: 8]
  ------------------
  274|     30|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 128, flags);
  ------------------
  |  |   88|     30|#define SC_ALGORITHM_AES		67
  ------------------
  275|     38|		if (card_caps.max_aes_key_length >= 256)
  ------------------
  |  Branch (275:7): [True: 25, False: 13]
  ------------------
  276|     25|			_sc_card_add_symmetric_alg(card, SC_ALGORITHM_AES, 256, flags);
  ------------------
  |  |   88|     25|#define SC_ALGORITHM_AES		67
  ------------------
  277|     38|	}
  278|       |
  279|       |	/* State that we have an RNG */
  280|    236|	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  557|    236|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    236|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  281|       |
  282|    236|	if ((card->version.fw_major == 40 && card->version.fw_minor >= 10 )
  ------------------
  |  Branch (282:7): [True: 13, False: 223]
  |  Branch (282:39): [True: 9, False: 4]
  ------------------
  283|    227|		|| card->version.fw_major >= 41)
  ------------------
  |  Branch (283:6): [True: 194, False: 33]
  ------------------
  284|    203|		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  579|    203|#define SC_CARD_CAP_WRAP_KEY			0x00000800
  ------------------
              		card->caps |= SC_CARD_CAP_WRAP_KEY | SC_CARD_CAP_UNWRAP_KEY
  ------------------
  |  |  581|    203|#define SC_CARD_CAP_UNWRAP_KEY			0x00001000
  ------------------
  285|    203|			   | SC_CARD_CAP_ONCARD_SESSION_OBJECTS;
  ------------------
  |  |  576|    203|#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS	0x00000400
  ------------------
  286|       |
  287|    236|	if (card->version.fw_major >= 45)
  ------------------
  |  Branch (287:6): [True: 122, False: 114]
  ------------------
  288|    122|		priv->cap_chaining = 1;
  289|    236|	if (card->version.fw_major >= 40)
  ------------------
  |  Branch (289:6): [True: 207, False: 29]
  ------------------
  290|    207|		card->max_recv_size = 256;
  291|     29|	else
  292|     29|		card->max_recv_size = 255;
  293|    236|	card->max_send_size = 255;
  294|       |
  295|    236|	rv = SC_SUCCESS;
  ------------------
  |  |   28|    236|#define SC_SUCCESS				0
  ------------------
  296|       |
  297|    312|err:
  298|    312|	if (rv < 0) {
  ------------------
  |  Branch (298:6): [True: 10, False: 302]
  ------------------
  299|     10|		free(priv);
  300|     10|		card->drv_data = old_drv_data;
  301|     10|	}
  302|       |
  303|    312|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    312|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    312|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    312|	int _ret = r; \
  |  |  |  |  155|    312|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 312, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    312|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 302]
  |  |  |  |  ------------------
  |  |  |  |  157|    312|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    312|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    312|	return _ret; \
  |  |  |  |  163|    312|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  304|    312|}
card-myeid.c:myeid_load_options:
  143|    312|{
  144|    312|	int r;
  145|    312|	size_t i, j;
  146|    312|	scconf_block **found_blocks, *block;
  147|       |
  148|    312|	if (!ctx || !priv) {
  ------------------
  |  Branch (148:6): [True: 0, False: 312]
  |  Branch (148:14): [True: 0, False: 312]
  ------------------
  149|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  150|      0|		goto err;
  151|      0|	}
  152|    312|	priv->disable_hw_pkcs1_padding = 0;
  153|    624|	for (i = 0; ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (153:14): [True: 312, False: 312]
  ------------------
  154|    312|		found_blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i],
  155|    312|				"card_driver", "myeid");
  156|    312|		if (!found_blocks)
  ------------------
  |  Branch (156:7): [True: 0, False: 312]
  ------------------
  157|      0|			continue;
  158|    312|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (158:40): [True: 0, False: 312]
  ------------------
  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|    312|		free(found_blocks);
  163|    312|	}
  164|    312|	r = SC_SUCCESS;
  ------------------
  |  |   28|    312|#define SC_SUCCESS				0
  ------------------
  165|       |
  166|    312|err:
  167|    312|	return r;
  168|    312|}
card-myeid.c:myeid_get_info:
 1703|    476|{
 1704|    476|	sc_apdu_t apdu;
 1705|    476|	int r;
 1706|       |
 1707|    476|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    476|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    476|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    476|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    476|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 476]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1708|       |
 1709|    476|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xA0);
  ------------------
  |  |  292|    476|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1710|    476|	apdu.resp    = rbuf;
 1711|    476|	apdu.resplen = buflen;
 1712|    476|	apdu.le      = buflen;
 1713|       |
 1714|    476|	r = sc_transmit_apdu(card, &apdu);
 1715|    476|	LOG_TEST_RET(card->ctx, r,  "APDU transmit failed");
  ------------------
  |  |  174|    476|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    476|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    476|	int _ret = (r); \
  |  |  |  |  168|    476|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 467]
  |  |  |  |  ------------------
  |  |  |  |  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|    476|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 467]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1716|       |
 1717|    467|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1717:6): [True: 135, False: 332]
  |  Branch (1717:26): [True: 9, False: 323]
  ------------------
 1718|    144|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    144|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1719|       |
 1720|    323|	if (apdu.resplen != 20)
  ------------------
  |  Branch (1720:6): [True: 85, False: 238]
  ------------------
 1721|     85|	{
 1722|     85|		sc_log(card->ctx, "Unexpected response to GET DATA (applet info)");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1723|     85|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     85|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1724|     85|	}
 1725|       |
 1726|       |	/* store the applet version */
 1727|    238|	card->version.fw_major = rbuf[5] * 10 + rbuf[6];
 1728|    238|	card->version.fw_minor = rbuf[7];
 1729|       |	/* add version to name */
 1730|    238|	snprintf(card_name_buf, sizeof(card_name_buf),
 1731|    238|			"%s %d.%d.%d", card->name, rbuf[5], rbuf[6], rbuf[7]);
 1732|    238|	card->name = card_name_buf;
 1733|       |
 1734|    238|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    238|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    238|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    238|	int _ret = r; \
  |  |  |  |  155|    238|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 238, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    238|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 238]
  |  |  |  |  ------------------
  |  |  |  |  157|    238|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    238|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    238|	return _ret; \
  |  |  |  |  163|    238|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1735|    238|}
card-myeid.c:myeid_get_card_caps:
 1786|    207|{
 1787|    207|	sc_apdu_t apdu;
 1788|    207|	int r;
 1789|    207|	unsigned char rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1790|       |
 1791|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1792|       |
 1793|    207|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xca, 0x01, 0xAA);
  ------------------
  |  |  292|    207|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1794|    207|	apdu.resp    = rbuf;
 1795|    207|	apdu.resplen = sizeof(myeid_card_caps_t);
 1796|    207|	apdu.le      = sizeof(myeid_card_caps_t);
 1797|       |
 1798|    207|	r = sc_transmit_apdu(card, &apdu);
 1799|    207|	LOG_TEST_RET(card->ctx, r,  "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: 3, False: 204]
  |  |  |  |  ------------------
  |  |  |  |  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|    207|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 204]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1800|       |
 1801|    204|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (1801:6): [True: 55, False: 149]
  |  Branch (1801:26): [True: 13, False: 136]
  ------------------
 1802|     68|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     68|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1803|       |
 1804|    136|	if (apdu.resplen < 11) {
  ------------------
  |  Branch (1804:6): [True: 93, False: 43]
  ------------------
 1805|     93|		sc_log(card->ctx, "Unexpected response to GET DATA (MyEIC card capabilities)");
  ------------------
  |  |   71|     93|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1806|     93|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     93|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1807|     93|	}
 1808|       |
 1809|     43|	card_caps->card_caps_ver = rbuf[0];
 1810|       |	/* the card returns big endian values */
 1811|     43|	card_caps->card_supported_features = (unsigned short) rbuf[1] << 8 | rbuf[2];
 1812|     43|	card_caps->max_rsa_key_length = (unsigned short) rbuf[3] << 8 | rbuf[4];
 1813|     43|	card_caps->max_des_key_length = (unsigned short) rbuf[5] << 8 | rbuf[6];
 1814|     43|	card_caps->max_aes_key_length = (unsigned short) rbuf[7] << 8 | rbuf[8];
 1815|     43|	card_caps->max_ecc_key_length = (unsigned short) rbuf[9] << 8 | rbuf[10];
 1816|       |
 1817|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1818|     43|}
card-myeid.c:myeid_finish:
 1856|    302|{
 1857|    302|	struct myeid_private_data *priv = (struct myeid_private_data *) card->drv_data;
 1858|    302|	free(priv);
 1859|    302|	return SC_SUCCESS;
  ------------------
  |  |   28|    302|#define SC_SUCCESS				0
  ------------------
 1860|    302|}
card-myeid.c:myeid_select_file:
  392|  2.14k|{
  393|  2.14k|	int r;
  394|       |
  395|  2.14k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.14k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  396|  2.14k|	r = iso_ops->select_file(card, in_path, file);
  397|       |
  398|  2.14k|	if (r == 0 && file != NULL && *file != NULL)
  ------------------
  |  Branch (398:6): [True: 702, False: 1.44k]
  |  Branch (398:16): [True: 75, False: 627]
  |  Branch (398:32): [True: 75, False: 0]
  ------------------
  399|     75|		parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  400|       |
  401|  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.44k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.44k, False: 702]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  402|  2.14k|}
card-myeid.c:parse_sec_attr:
  350|     75|{
  351|     75|	int i;
  352|     75|	const int df_ops[4] =
  353|     75|		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|     75|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  169|     75|#define SC_AC_OP_CREATE			3
  ------------------
              		{ SC_AC_OP_CREATE, SC_AC_OP_CREATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|     75|#define SC_AC_OP_DELETE			2
  ------------------
  354|     75|	const int ef_ops[4] =
  355|     75|		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  188|     75|#define SC_AC_OP_READ			22
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  189|     75|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, -1 };
  ------------------
  |  |  168|     75|#define SC_AC_OP_DELETE			2
  ------------------
  356|     75|	const int key_ops[4] =
  357|     75|		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  173|     75|#define SC_AC_OP_CRYPTO			7
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  189|     75|#define SC_AC_OP_UPDATE			23
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  168|     75|#define SC_AC_OP_DELETE			2
  ------------------
              		{ SC_AC_OP_CRYPTO, SC_AC_OP_UPDATE, SC_AC_OP_DELETE, SC_AC_OP_GENERATE };
  ------------------
  |  |  192|     75|#define SC_AC_OP_GENERATE		26
  ------------------
  358|       |
  359|     75|	const int *ops;
  360|       |
  361|     75|	if (len < 2)
  ------------------
  |  Branch (361:6): [True: 41, False: 34]
  ------------------
  362|     41|		return;
  363|       |
  364|     34|	switch (file->type) {
  365|      7|	case SC_FILE_TYPE_WORKING_EF:
  ------------------
  |  |  216|      7|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (365:2): [True: 7, False: 27]
  ------------------
  366|      7|		ops = ef_ops;
  367|      7|		break;
  368|      3|	case SC_FILE_TYPE_INTERNAL_EF:
  ------------------
  |  |  215|      3|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (368:2): [True: 3, False: 31]
  ------------------
  369|      3|		ops = key_ops;
  370|      3|		break;
  371|      3|	case SC_FILE_TYPE_DF:
  ------------------
  |  |  214|      3|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (371:2): [True: 3, False: 31]
  ------------------
  372|      3|		ops = df_ops;
  373|      3|		break;
  374|     21|	default:
  ------------------
  |  Branch (374:2): [True: 21, False: 13]
  ------------------
  375|     21|		ops = key_ops;
  376|     21|		break;
  377|     34|	}
  378|       |
  379|    170|	for (i = 0; i < 4; i++)
  ------------------
  |  Branch (379:14): [True: 136, False: 34]
  ------------------
  380|    136|	{
  381|    136|		if (ops[i] == -1)
  ------------------
  |  Branch (381:7): [True: 10, False: 126]
  ------------------
  382|     10|			continue;
  383|    126|		if ((i & 1) == 0)
  ------------------
  |  Branch (383:7): [True: 68, False: 58]
  ------------------
  384|     68|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] >> 4));
  385|     58|		else
  386|     58|			add_acl_entry(file, ops[i], (u8)(buf[i / 2] & 0x0F));
  387|    126|	}
  388|     34|}
card-myeid.c:add_acl_entry:
  330|    126|{
  331|    126|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    126|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  332|       |
  333|    126|	switch (byte)
  334|    126|	{
  335|     22|	case 0:
  ------------------
  |  Branch (335:2): [True: 22, False: 104]
  ------------------
  336|     22|		method = SC_AC_NONE;
  ------------------
  |  |  150|     22|#define SC_AC_NONE			0x00000000
  ------------------
  337|     22|		break;
  338|     39|	case 15:
  ------------------
  |  Branch (338:2): [True: 39, False: 87]
  ------------------
  339|     39|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     39|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  340|     39|		break;
  341|     65|	default:
  ------------------
  |  Branch (341:2): [True: 65, False: 61]
  ------------------
  342|     65|		method = SC_AC_CHV;
  ------------------
  |  |  151|     65|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  343|     65|		key_ref = byte;
  344|     65|		break;
  345|    126|	}
  346|    126|	sc_file_add_acl_entry(file, op, method, key_ref);
  347|    126|}
card-myeid.c:myeid_set_security_env:
  936|    891|{
  937|    891|	struct sc_context *ctx = card->ctx;
  938|    891|	myeid_private_data_t* priv;
  939|       |
  940|    891|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    891|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    891|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    891|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    891|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 891]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  941|       |
  942|    891|	priv = (myeid_private_data_t*) card->drv_data;
  943|       |	/* store security environment to differentiate between ECDH and RSA in decipher - Hannu*/
  944|    891|	priv->sec_env = env;
  945|       |
  946|       |	/* for symmetric operation save algo and algo flags */
  947|    891|	priv->algorithm_flags = env->algorithm_flags;
  948|    891|	priv->algorithm = env->algorithm;
  949|       |
  950|    891|	if (env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   69|    891|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (950:6): [True: 891, False: 0]
  ------------------
  951|    891|	{
  952|    891|		sc_security_env_t tmp;
  953|       |
  954|    891|		tmp = *env;
  955|    891|		tmp.flags &= ~SC_SEC_ENV_ALG_PRESENT;
  ------------------
  |  |   69|    891|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  956|    891|		tmp.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   65|    891|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  957|       |
  958|    891|		if (tmp.algorithm == SC_ALGORITHM_RSA)
  ------------------
  |  |   78|    891|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (958:7): [True: 891, False: 0]
  ------------------
  959|    891|		{
  960|    891|			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   61|  1.78k|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
              			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   60|    891|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (960:8): [True: 0, False: 891]
  |  Branch (960:52): [True: 0, False: 891]
  ------------------
  961|      0|			{
  962|      0|			    tmp.algorithm_ref = 0x0A;
  963|      0|			}
  964|    891|			else
  965|    891|			{
  966|    891|				tmp.algorithm_ref = 0x00;
  967|       |				/* potential FIXME: return an error, if an unsupported
  968|       |				* pad or hash was requested, although this shouldn't happen */
  969|    891|				if ((env->operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |   57|  1.78k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
              				if ((env->operation == SC_SEC_OPERATION_SIGN && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  118|    580|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (969:10): [True: 580, False: 311]
  |  Branch (969:53): [True: 282, False: 298]
  ------------------
  970|    609|					|| (env->operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02))
  ------------------
  |  |   56|  1.21k|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
              					|| (env->operation == SC_SEC_OPERATION_DECIPHER && env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02))
  ------------------
  |  |  119|    311|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (970:10): [True: 311, False: 298]
  |  Branch (970:57): [True: 0, False: 311]
  ------------------
  971|    282|					tmp.algorithm_ref = 0x02;
  972|    891|				if (tmp.algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1)
  ------------------
  |  |  143|    891|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (972:9): [True: 0, False: 891]
  ------------------
  973|      0|					tmp.algorithm_ref |= 0x10;
  974|    891|			}
  975|       |
  976|    891|			return myeid_set_security_env_rsa(card, &tmp, se_num);
  977|    891|		}
  978|      0|		else if (tmp.algorithm == SC_ALGORITHM_EC)
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (978:12): [True: 0, False: 0]
  ------------------
  979|      0|		{
  980|      0|			tmp.algorithm_ref = 0x04;
  981|      0|			tmp.algorithm_flags = 0;
  982|      0|			return myeid_set_security_env_ec(card, &tmp, se_num);
  983|      0|		}
  984|      0|		else if (tmp.algorithm == SC_ALGORITHM_AES)
  ------------------
  |  |   88|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (984:12): [True: 0, False: 0]
  ------------------
  985|      0|		{
  986|      0|			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   61|      0|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
              			if (tmp.operation == SC_SEC_OPERATION_UNWRAP || tmp.operation == SC_SEC_OPERATION_WRAP)
  ------------------
  |  |   60|      0|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (986:8): [True: 0, False: 0]
  |  Branch (986:52): [True: 0, False: 0]
  ------------------
  987|      0|			{
  988|      0|				tmp.algorithm_ref = 0x0A;
  989|      0|			}
  990|      0|			else
  991|      0|			{
  992|      0|				tmp.algorithm_ref = 0x00;
  993|      0|			}
  994|       |
  995|      0|			if ((tmp.algorithm_flags & SC_ALGORITHM_AES_CBC_PAD) == SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  217|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
              			if ((tmp.algorithm_flags & SC_ALGORITHM_AES_CBC_PAD) == SC_ALGORITHM_AES_CBC_PAD)
  ------------------
  |  |  217|      0|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
  |  Branch (995:8): [True: 0, False: 0]
  ------------------
  996|      0|				tmp.algorithm_ref |= 0x80;		/* set PKCS#7 padding */
  997|       |			/* Tag 0x80 algorithm_ref - value 0x80 or 0x8A is working only for UNWRAP/WRAP
  998|       |			 * AES is supported from version 4.0 but without pkcs#7 padding.
  999|       |			 * For SC_SEC_OPERATION_ENCRYPT_SYM and SC_SEC_OPERATION_DECRYPT_SYM we running
 1000|       |			 * PKCS#7 in software, here we fix the algorithm_ref variable.
 1001|       |			 */
 1002|      0|			if (IS_SYMETRIC_CRYPT(env->operation))
  ------------------
  |  |  690|      0|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   62|      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)
  |  |  ------------------
  |  |  |  |   63|      0|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (690:31): [True: 0, False: 0]
  |  |  |  Branch (690:70): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1003|      0|				tmp.algorithm_ref &= ~0x80; /* do not handle padding in card */
 1004|       |
 1005|       |			/* from this point, there's no difference to RSA SE */
 1006|      0|			return myeid_set_security_env_rsa(card, &tmp, se_num);
 1007|      0|		}
 1008|      0|		else
 1009|      0|		{
 1010|       |
 1011|      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__
  |  |  ------------------
  ------------------
 1012|      0|			return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1013|      0|		}
 1014|    891|	}
 1015|      0|	return myeid_set_security_env_rsa(card, env, se_num);
 1016|    891|}
card-myeid.c:myeid_set_security_env_rsa:
  694|    988|{
  695|    988|	sc_apdu_t apdu;
  696|    988|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  697|    988|	u8 *p;
  698|    988|	int r;
  699|    988|	size_t i, sz;
  700|    988|	sc_path_t *target_file;
  701|       |
  702|    988|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (702:6): [True: 0, False: 988]
  |  Branch (702:22): [True: 0, False: 988]
  ------------------
  703|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  704|    988|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    988|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    988|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    988|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    988|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 988]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  705|       |
  706|    988|	if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   68|    988|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (706:6): [True: 0, False: 988]
  ------------------
  707|      0|	{
  708|      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__
  |  |  ------------------
  ------------------
  709|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  710|      0|	}
  711|    988|	if (se_num > 0)
  ------------------
  |  Branch (711:6): [True: 0, False: 988]
  ------------------
  712|      0|	{
  713|      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__
  |  |  ------------------
  ------------------
  714|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  715|      0|	}
  716|       |
  717|    988|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0, 0);
  ------------------
  |  |  293|    988|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  718|    988|	switch (env->operation)
  719|    988|	{
  720|    408|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|    408|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (720:2): [True: 408, False: 580]
  ------------------
  721|    408|		apdu.p1 = 0x41;
  722|    408|		apdu.p2 = 0xB8;
  723|    408|		break;
  724|    580|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|    580|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (724:2): [True: 580, False: 408]
  ------------------
  725|    580|		apdu.p1 = 0x41;
  726|    580|		apdu.p2 = 0xB6;
  727|    580|		break;
  728|      0|	case SC_SEC_OPERATION_UNWRAP:
  ------------------
  |  |   61|      0|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  |  Branch (728:2): [True: 0, False: 988]
  ------------------
  729|      0|		apdu.p1 = 0x41;
  730|      0|		apdu.p2 = 0xB8;
  731|      0|		break;
  732|      0|	case SC_SEC_OPERATION_WRAP:
  ------------------
  |  |   60|      0|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (732:2): [True: 0, False: 988]
  ------------------
  733|      0|		apdu.p1 = 0x81;
  734|      0|		apdu.p2 = 0xB8;
  735|      0|		break;
  736|      0|	case SC_SEC_OPERATION_ENCRYPT_SYM:
  ------------------
  |  |   62|      0|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  ------------------
  |  Branch (736:2): [True: 0, False: 988]
  ------------------
  737|      0|		apdu.p1 = 0x81;
  738|      0|		apdu.p2 = 0xB8;
  739|      0|		break;
  740|      0|	case SC_SEC_OPERATION_DECRYPT_SYM:
  ------------------
  |  |   63|      0|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  ------------------
  |  Branch (740:2): [True: 0, False: 988]
  ------------------
  741|      0|		apdu.p1 = 0x41;
  742|      0|		apdu.p2 = 0xB8;
  743|      0|		break;
  744|      0|	default:
  ------------------
  |  Branch (744:2): [True: 0, False: 988]
  ------------------
  745|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  746|    988|	}
  747|    988|	apdu.le = 0;
  748|    988|	p = sbuf;
  749|    988|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT)
  ------------------
  |  |   65|    988|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (749:6): [True: 988, False: 0]
  ------------------
  750|    988|	{
  751|    988|		*p++ = 0x80;	/* algorithm reference */
  752|    988|		*p++ = 0x01;
  753|    988|		*p++ = env->algorithm_ref & 0xFF;
  754|    988|	}
  755|    988|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   66|    988|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (755:6): [True: 97, False: 891]
  ------------------
  756|     97|	{
  757|     97|		*p++ = 0x81;
  758|     97|		*p++ = 2;
  759|     97|		memcpy(p, env->file_ref.value, 2);
  760|     97|		p += 2;
  761|     97|	}
  762|       |	/* symmetric operations: we need to set the key reference */
  763|    988|	if (IS_SYMETRIC_CRYPT(env->operation)) {
  ------------------
  |  |  690|    988|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   62|  1.97k|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   63|    988|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (690:31): [True: 0, False: 988]
  |  |  |  Branch (690:70): [True: 0, False: 988]
  |  |  ------------------
  ------------------
  764|      0|		*p++ = 0x83;
  765|      0|		*p++ = 1;
  766|      0|		*p++ = 0;
  767|      0|	}
  768|    988|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT && env->operation != SC_SEC_OPERATION_UNWRAP &&
  ------------------
  |  |   67|  1.97k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
              	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT && env->operation != SC_SEC_OPERATION_UNWRAP &&
  ------------------
  |  |   61|  1.97k|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  |  Branch (768:6): [True: 988, False: 0]
  |  Branch (768:49): [True: 988, False: 0]
  ------------------
  769|    988|			env->operation != SC_SEC_OPERATION_WRAP &&
  ------------------
  |  |   60|  1.97k|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (769:4): [True: 988, False: 0]
  ------------------
  770|    988|			env->operation != SC_SEC_OPERATION_ENCRYPT_SYM &&
  ------------------
  |  |   62|  1.97k|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  ------------------
  |  Branch (770:4): [True: 988, False: 0]
  ------------------
  771|    988|			env->operation != SC_SEC_OPERATION_DECRYPT_SYM) {
  ------------------
  |  |   63|    988|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  ------------------
  |  Branch (771:4): [True: 988, False: 0]
  ------------------
  772|    988|		*p++ = 0x84;
  773|    988|		*p++ = 1;
  774|    988|		*p++ = 0;
  775|    988|	}
  776|  10.8k|	for (i = 0; i < SC_SEC_ENV_MAX_PARAMS; i++)
  ------------------
  |  |   73|  10.8k|#define SC_SEC_ENV_MAX_PARAMS		10
  ------------------
  |  Branch (776:14): [True: 9.88k, False: 988]
  ------------------
  777|  9.88k|	    if (env->params[i].param_type == SC_SEC_ENV_PARAM_TARGET_FILE) {
  ------------------
  |  |   75|  9.88k|#define SC_SEC_ENV_PARAM_TARGET_FILE	2
  ------------------
  |  Branch (777:10): [True: 0, False: 9.88k]
  ------------------
  778|      0|			target_file = (sc_path_t*) env->params[i].value;
  779|      0|			if (env->params[i].value_len < sizeof(sc_path_t) || target_file->len != 2) {
  ------------------
  |  Branch (779:8): [True: 0, False: 0]
  |  Branch (779:56): [True: 0, False: 0]
  ------------------
  780|      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__
  |  |  ------------------
  ------------------
  781|      0|				return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  782|      0|			}
  783|      0|			*p++ = 0x83;
  784|      0|			*p++ = 2;
  785|      0|			memcpy(p, target_file->value, 2);
  786|      0|			p+= 2;
  787|      0|			break;
  788|      0|	    }
  789|       |
  790|    988|	r = 0;
  791|    988|	if (env->operation == SC_SEC_OPERATION_UNWRAP || env->operation == SC_SEC_OPERATION_WRAP ||
  ------------------
  |  |   61|  1.97k|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
              	if (env->operation == SC_SEC_OPERATION_UNWRAP || env->operation == SC_SEC_OPERATION_WRAP ||
  ------------------
  |  |   60|  1.97k|#define SC_SEC_OPERATION_WRAP		0x0005
  ------------------
  |  Branch (791:6): [True: 0, False: 988]
  |  Branch (791:51): [True: 0, False: 988]
  ------------------
  792|    988|			IS_SYMETRIC_CRYPT(env->operation)) {
  ------------------
  |  |  690|    988|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   62|  1.97k|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   63|    988|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (690:31): [True: 0, False: 988]
  |  |  |  Branch (690:70): [True: 0, False: 988]
  |  |  ------------------
  ------------------
  793|       |		/* add IV if present */
  794|      0|		for (i = 0; i < SC_SEC_ENV_MAX_PARAMS; i++)
  ------------------
  |  |   73|      0|#define SC_SEC_ENV_MAX_PARAMS		10
  ------------------
  |  Branch (794:15): [True: 0, False: 0]
  ------------------
  795|      0|			if (env->params[i].param_type == SC_SEC_ENV_PARAM_IV) {
  ------------------
  |  |   74|      0|#define SC_SEC_ENV_PARAM_IV		1
  ------------------
  |  Branch (795:8): [True: 0, False: 0]
  ------------------
  796|      0|				r = 1;
  797|      0|				*p++ = 0x87;
  798|      0|				*p++ = (unsigned char) env->params[i].value_len;
  799|      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 (799:9): [True: 0, False: 0]
  ------------------
  800|      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__
  |  |  ------------------
  ------------------
  801|      0|					return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  802|      0|				}
  803|      0|				memcpy(p, env->params[i].value, env->params[i].value_len);
  804|      0|				p+=(unsigned char) env->params[i].value_len;
  805|      0|				break;
  806|      0|			}
  807|      0|	}
  808|       |	/* for AES_ECB we need to reset the IV but we respect if the IV is already present */
  809|    988|	if (IS_SYMETRIC_CRYPT(env->operation) && env->algorithm == SC_ALGORITHM_AES &&
  ------------------
  |  |  690|  1.97k|#define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   62|  1.97k|#define SC_SEC_OPERATION_ENCRYPT_SYM	0x0007
  |  |  ------------------
  |  |               #define IS_SYMETRIC_CRYPT(x) ((x) == SC_SEC_OPERATION_ENCRYPT_SYM || (x) == SC_SEC_OPERATION_DECRYPT_SYM)
  |  |  ------------------
  |  |  |  |   63|    988|#define SC_SEC_OPERATION_DECRYPT_SYM	0x0008
  |  |  ------------------
  |  |  |  Branch (690:31): [True: 0, False: 988]
  |  |  |  Branch (690:70): [True: 0, False: 988]
  |  |  ------------------
  ------------------
              	if (IS_SYMETRIC_CRYPT(env->operation) && env->algorithm == SC_ALGORITHM_AES &&
  ------------------
  |  |   88|    988|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (809:43): [True: 0, False: 0]
  ------------------
  810|      0|			env->algorithm_flags == SC_ALGORITHM_AES_ECB && r == 0) {
  ------------------
  |  |  215|    988|#define SC_ALGORITHM_AES_ECB		 0x01000000
  ------------------
  |  Branch (810:4): [True: 0, False: 0]
  |  Branch (810:52): [True: 0, False: 0]
  ------------------
  811|      0|		*p++ = 0x87;
  812|      0|		*p++ = 16;
  813|      0|		memset(p, 0, 16);
  814|      0|		p += 16;
  815|      0|	}
  816|       |
  817|    988|	sz = p - sbuf;
  818|    988|	apdu.lc = sz;
  819|    988|	apdu.datalen = sz;
  820|    988|	apdu.data = sbuf;
  821|    988|	apdu.resplen = 0;
  822|    988|	r = (int)sz;
  823|    988|	if (apdu.datalen != 0)
  ------------------
  |  Branch (823:6): [True: 988, False: 0]
  ------------------
  824|    988|	{
  825|    988|		r = sc_transmit_apdu(card, &apdu);
  826|    988|		if (r)
  ------------------
  |  Branch (826:7): [True: 17, False: 971]
  ------------------
  827|     17|		{
  828|     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__
  |  |  ------------------
  ------------------
  829|     17|				"%s: APDU transmit failed", sc_strerror(r));
  830|     17|			goto err;
  831|     17|		}
  832|    971|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  833|    971|		if (r)
  ------------------
  |  Branch (833:7): [True: 588, False: 383]
  ------------------
  834|    588|		{
  835|    588|			sc_log(card->ctx,
  ------------------
  |  |   71|    588|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  836|    588|				"%s: Card returned error", sc_strerror(r));
  837|    588|			goto err;
  838|    588|		}
  839|    971|	}
  840|    988|err:
  841|    988|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    988|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    988|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    988|	int _ret = r; \
  |  |  |  |  155|    988|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 988, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    988|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    605|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 605, False: 383]
  |  |  |  |  ------------------
  |  |  |  |  157|    988|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    988|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    988|	return _ret; \
  |  |  |  |  163|    988|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  842|    988|}
card-myeid.c:myeid_compute_signature:
 1149|    195|{
 1150|    195|	struct sc_context *ctx;
 1151|    195|	struct sc_apdu apdu;
 1152|    195|	u8 rbuf[MYEID_MAX_EXT_APDU_BUFFER_SIZE];
 1153|    195|	u8 sbuf[MYEID_MAX_EXT_APDU_BUFFER_SIZE];
 1154|    195|	struct myeid_private_data* priv;
 1155|    195|	int r;
 1156|    195|	size_t field_length = 0;
 1157|    195|	size_t pad_chars = 0;
 1158|       |
 1159|    195|	if (card == NULL || data == NULL || out == NULL)
  ------------------
  |  Branch (1159:6): [True: 0, False: 195]
  |  Branch (1159:22): [True: 0, False: 195]
  |  Branch (1159:38): [True: 0, False: 195]
  ------------------
 1160|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1161|    195|	ctx = card->ctx;
 1162|    195|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    195|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    195|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    195|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    195|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 195]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1163|       |
 1164|    195|	priv = (myeid_private_data_t*) card->drv_data;
 1165|    195|	sc_log(ctx, "key type %lu, key length %lu", priv->sec_env->algorithm, priv->sec_env->algorithm_ref);
  ------------------
  |  |   71|    195|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1166|       |
 1167|    195|	if (priv->sec_env->algorithm == SC_ALGORITHM_EC ) {
  ------------------
  |  |   79|    195|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1167:6): [True: 0, False: 195]
  ------------------
 1168|       |
 1169|      0|	    field_length = priv->sec_env->algorithm_ref;
 1170|       |
 1171|       |	    /* pad with zeros if needed */
 1172|      0|		if (datalen < BYTES4BITS(field_length)) {
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
  |  Branch (1172:7): [True: 0, False: 0]
  ------------------
 1173|      0|			pad_chars = BYTES4BITS(field_length) - datalen;
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 1174|       |
 1175|      0|			memset(sbuf, 0, pad_chars);
 1176|      0|		}
 1177|      0|	}
 1178|       |
 1179|    195|	if ((datalen + pad_chars) > sizeof(sbuf))
  ------------------
  |  Branch (1179:6): [True: 3, False: 192]
  ------------------
 1180|    195|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|       |
 1182|    192|	if (priv->sec_env->algorithm == SC_ALGORITHM_RSA && datalen == 256 && !priv->cap_chaining)
  ------------------
  |  |   78|    384|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1182:6): [True: 192, False: 0]
  |  Branch (1182:54): [True: 142, False: 50]
  |  Branch (1182:72): [True: 97, False: 45]
  ------------------
 1183|     97|		return myeid_compute_raw_2048_signature(card, data, datalen, out, outlen);
 1184|       |
 1185|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1186|       |		* P1:  0x9E  Resp: Digital Signature
 1187|       |		* P2:  0x9A  Cmd: Input for Digital Signature */
 1188|     95|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  294|     95|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1189|     95|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     95|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1190|     95|	apdu.resp = rbuf;
 1191|     95|	apdu.resplen = sizeof(rbuf);
 1192|     95|	apdu.le = 256;
 1193|     95|	memcpy(sbuf + pad_chars, data, datalen);
 1194|     95|	apdu.lc = datalen + pad_chars;
 1195|     95|	apdu.datalen = datalen + pad_chars;
 1196|       |
 1197|     95|	apdu.data = sbuf;
 1198|     95|	r = sc_transmit_apdu(card, &apdu);
 1199|     95|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     95|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     95|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     95|	int _ret = (r); \
  |  |  |  |  168|     95|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 41, False: 54]
  |  |  |  |  ------------------
  |  |  |  |  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|     95|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 54]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1200|     54|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1201|     54|	LOG_TEST_RET(ctx, r, "compute_signature failed");
  ------------------
  |  |  174|     54|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     54|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     54|	int _ret = (r); \
  |  |  |  |  168|     54|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 22, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  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|     54|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1202|       |
 1203|     32|	if (priv->sec_env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|     32|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1203:6): [True: 0, False: 32]
  ------------------
 1204|      0|		r = myeid_convert_ec_signature(ctx, priv->sec_env->algorithm_ref, apdu.resp, apdu.resplen);
 1205|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1206|      0|		apdu.resplen = r;
 1207|      0|	}
 1208|       |
 1209|     32|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (1209:6): [True: 0, False: 32]
  ------------------
 1210|     32|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1211|       |
 1212|     32|	memcpy(out, apdu.resp, apdu.resplen);
 1213|     32|	LOG_FUNC_RETURN(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: 13, False: 19]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     32|	return _ret; \
  |  |  |  |  163|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1214|     32|}
card-myeid.c:myeid_compute_raw_2048_signature:
 1086|     97|{
 1087|     97|	int r;
 1088|     97|	struct sc_context *ctx;
 1089|     97|	struct myeid_private_data *priv;
 1090|     97|	struct sc_apdu apdu;
 1091|     97|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 1092|     97|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1093|     97|	sc_security_env_t env;
 1094|       |
 1095|     97|	ctx = card->ctx;
 1096|     97|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|     97|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     97|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     97|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     97|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 97]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1097|       |
 1098|     97|	priv = (myeid_private_data_t *) card->drv_data;
 1099|       |
 1100|       |/* security env change - use DECIPHER operation */
 1101|     97|	memcpy(&env, priv->sec_env, sizeof(sc_security_env_t));
 1102|     97|	env.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
  ------------------
  |  |   65|     97|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
 1103|     97|	env.flags |= SC_SEC_ENV_FILE_REF_PRESENT;
  ------------------
  |  |   66|     97|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
 1104|     97|	env.flags |= SC_SEC_ENV_KEY_REF_PRESENT;
  ------------------
  |  |   67|     97|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
 1105|     97|	env.operation = SC_SEC_OPERATION_DECIPHER;
  ------------------
  |  |   56|     97|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
 1106|     97|	myeid_set_security_env_rsa(card, &env, 0);
 1107|       |
 1108|     97|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  293|     97|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1109|     97|	apdu.resp = rbuf;
 1110|     97|	apdu.resplen = sizeof(rbuf);
 1111|     97|	apdu.le = 0;	/* there is no response to 1st part of data */
 1112|       |
 1113|       |/* prepare 1st part of data */
 1114|     97|	sbuf[0] = 0x81;
 1115|     97|	memcpy(sbuf + 1, data, datalen / 2);
 1116|     97|	apdu.lc = datalen / 2 + 1;
 1117|     97|	apdu.datalen = apdu.lc;
 1118|     97|	apdu.data = sbuf;
 1119|       |
 1120|     97|	r = sc_transmit_apdu(card, &apdu);
 1121|     97|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     97|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     97|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     97|	int _ret = (r); \
  |  |  |  |  168|     97|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 91]
  |  |  |  |  ------------------
  |  |  |  |  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|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 91]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1122|     91|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1122:6): [True: 67, False: 24]
  |  Branch (1122:26): [True: 60, False: 7]
  ------------------
 1123|       |/* prepare 2nd part of data */
 1124|     60|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     60|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1125|     60|		apdu.resp = rbuf;
 1126|     60|		apdu.resplen = sizeof(rbuf);
 1127|     60|		apdu.le = datalen;
 1128|     60|		sbuf[0] = 0x82;
 1129|     60|		memcpy(sbuf + 1, data + datalen / 2, datalen / 2);
 1130|     60|		apdu.lc = datalen / 2 + 1;
 1131|     60|		apdu.datalen = apdu.lc;
 1132|     60|		apdu.data = sbuf;
 1133|       |
 1134|     60|		r = sc_transmit_apdu(card, &apdu);
 1135|     60|		LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     60|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     60|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     60|	int _ret = (r); \
  |  |  |  |  168|     60|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  169|     12|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     12|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     12|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     12|		return _ret; \
  |  |  |  |  172|     12|	} \
  |  |  |  |  173|     60|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1136|       |
 1137|     48|		if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1137:7): [True: 34, False: 14]
  |  Branch (1137:27): [True: 24, False: 10]
  ------------------
 1138|     24|			size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1138:17): [True: 0, False: 24]
  ------------------
 1139|     24|			memcpy(out, apdu.resp, len);
 1140|     24|			LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  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: 11, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  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|     13|	} 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|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|     24|		}
 1142|     48|	}
 1143|     55|	LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1144|     55|}
card-myeid.c:myeid_decipher:
 1383|    124|{
 1384|    124|	int r;
 1385|    124|	myeid_private_data_t* priv;
 1386|       |
 1387|    124|	if (card == NULL || crgram == NULL || out == NULL)
  ------------------
  |  Branch (1387:6): [True: 0, False: 124]
  |  Branch (1387:22): [True: 0, False: 124]
  |  Branch (1387:40): [True: 0, False: 124]
  ------------------
 1388|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1389|       |
 1390|    124|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    124|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    124|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    124|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    124|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 124]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1391|       |
 1392|    124|	priv = (myeid_private_data_t*)card->drv_data;
 1393|       |
 1394|    124|	if (priv->sec_env && priv->sec_env->algorithm == SC_ALGORITHM_EC
  ------------------
  |  |   79|    248|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1394:6): [True: 124, False: 0]
  |  Branch (1394:23): [True: 0, False: 124]
  ------------------
 1395|      0|		&& priv->sec_env->operation == SC_SEC_OPERATION_DERIVE
  ------------------
  |  |   59|    124|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1395:6): [True: 0, False: 0]
  ------------------
 1396|      0|		&& priv->sec_env->algorithm_flags & SC_ALGORITHM_ECDH_CDH_RAW)
  ------------------
  |  |  182|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  |  Branch (1396:6): [True: 0, False: 0]
  ------------------
 1397|      0|	{
 1398|      0|		r = myeid_ecdh_derive(card, crgram, crgram_len, out, outlen);
 1399|      0|		priv->sec_env = NULL; /* clear after operation */
 1400|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1401|      0|	}
 1402|       |
 1403|    124|	r = myeid_transmit_decipher(card, 0x80, 0x86, crgram, crgram_len, out, outlen);
 1404|    124|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    124|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    124|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    124|	int _ret = r; \
  |  |  |  |  155|    124|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 89, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  156|     89|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     76|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 76, False: 13]
  |  |  |  |  ------------------
  |  |  |  |  157|     89|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     89|	} else { \
  |  |  |  |  159|     35|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     35|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     35|	} \
  |  |  |  |  162|    124|	return _ret; \
  |  |  |  |  163|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1405|    124|}
card-myeid.c:myeid_transmit_decipher:
 1328|    124|{
 1329|    124|	myeid_private_data_t *priv = card->drv_data;
 1330|    124|	struct sc_apdu apdu;
 1331|    124|	u8 rbuf[SC_MAX_EXT_APDU_BUFFER_SIZE];
 1332|    124|	u8 sbuf[SC_MAX_EXT_APDU_BUFFER_SIZE];
 1333|    124|	int r;
 1334|       |
 1335|    124|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    124|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    124|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    124|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    124|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 124]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1336|       |
 1337|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1338|       |	 * P1:  0x00  Resp: No response (unwrapping)
 1339|       |	 * P1:  0x80  Resp: Plain value
 1340|       |	 * P2:  0x84  Cmd: Cryptogram (no padding byte)
 1341|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1342|    124|	sc_format_apdu(card, &apdu, p1 ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT, 0x2A, p1, p2);
  ------------------
  |  |  294|    124|#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 (1342:30): [True: 124, False: 0]
  ------------------
 1343|    124|	if (p2 == 0x86) {
  ------------------
  |  Branch (1343:6): [True: 124, False: 0]
  ------------------
 1344|    124|		if (crgram_len+1 > sizeof(sbuf))
  ------------------
  |  Branch (1344:7): [True: 0, False: 124]
  ------------------
 1345|    124|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1346|    124|		sbuf[0] = 0; /* Padding indicator: 0x00 = No further indication */
 1347|    124|		memcpy(sbuf + 1, crgram, crgram_len);
 1348|    124|		apdu.data = sbuf;
 1349|    124|		apdu.datalen = apdu.lc = crgram_len + 1;
 1350|    124|	} else {
 1351|      0|		apdu.data = crgram;
 1352|      0|		apdu.datalen = apdu.lc = crgram_len;
 1353|      0|	}
 1354|    124|	if (p1 != 0x00) {
  ------------------
  |  Branch (1354:6): [True: 124, False: 0]
  ------------------
 1355|    124|		apdu.resp = rbuf;
 1356|    124|		apdu.resplen = sizeof(rbuf);
 1357|    124|		apdu.le = MIN(card->max_recv_size, crgram_len);
  ------------------
  |  |   70|    124|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 15, False: 109]
  |  |  ------------------
  ------------------
 1358|    124|	}
 1359|       |
 1360|       |	/* 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. */
 1361|    124|	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))) {
  ------------------
  |  |   61|      3|#define SC_SEC_OPERATION_UNWRAP		0x0006
  ------------------
  |  Branch (1361:6): [True: 124, False: 0]
  |  Branch (1361:20): [True: 40, False: 84]
  |  Branch (1361:41): [True: 40, False: 0]
  |  Branch (1361:50): [True: 34, False: 6]
  |  Branch (1361:74): [True: 3, False: 3]
  |  Branch (1361:106): [True: 3, False: 0]
  |  Branch (1361:131): [True: 0, False: 3]
  ------------------
 1362|     34|		r = myeid_transmit_decipher_pi_split(card, &apdu, sbuf);
 1363|     90|	} else {
 1364|     90|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|     90|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1365|     90|		r = sc_transmit_apdu(card, &apdu);
 1366|     90|	}
 1367|    124|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    124|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    124|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    124|	int _ret = (r); \
  |  |  |  |  168|    124|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 38, False: 86]
  |  |  |  |  ------------------
  |  |  |  |  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|    124|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 86]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1368|       |
 1369|     86|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1370|     86|	LOG_TEST_RET(card->ctx, r, "DECIPHER returned error");
  ------------------
  |  |  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: 38, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  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|     86|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1371|       |
 1372|     48|	if (out && outlen) {
  ------------------
  |  Branch (1372:6): [True: 48, False: 0]
  |  Branch (1372:13): [True: 48, False: 0]
  ------------------
 1373|     48|		outlen = MIN(apdu.resplen, outlen);
  ------------------
  |  |   70|     48|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 47, False: 1]
  |  |  ------------------
  ------------------
 1374|     48|		memcpy(out, apdu.resp, outlen);
 1375|     48|	} else {
 1376|      0|		outlen = 0;
 1377|      0|	}
 1378|     48|	LOG_FUNC_RETURN(card->ctx, (int)outlen);
  ------------------
  |  |  164|     48|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     48|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     48|	int _ret = r; \
  |  |  |  |  155|     48|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 13, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  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|     35|	} else { \
  |  |  |  |  159|     35|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     35|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     35|	} \
  |  |  |  |  162|     48|	return _ret; \
  |  |  |  |  163|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1379|     48|}
card-myeid.c:myeid_transmit_decipher_pi_split:
 1287|     34|{
 1288|       |	/* MyEID before 4.5.x does not support APDU chaining. The payload
 1289|       |	 * is split to two regular APDUs and Padding Indicator field is used to
 1290|       |	 * describe which slice it is. */
 1291|     34|	size_t crgram_len = apdu->lc - 1;
 1292|     34|	size_t crgram_half = crgram_len / 2;
 1293|     34|	size_t resplen = apdu->resplen;
 1294|     34|	unsigned char *resp = apdu->resp;
 1295|     34|	int r;
 1296|       |
 1297|     34|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1298|       |
 1299|       |	/* Send 1st part, no response */
 1300|     34|	apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     34|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1301|     34|	apdu->data = &sbuf[0];
 1302|     34|	apdu->datalen = apdu->lc = crgram_half + 1;
 1303|     34|	apdu->resp = 0;
 1304|     34|	apdu->resplen = 0;
 1305|     34|	apdu->le = 0;
 1306|     34|	sbuf[0] = 0x81;			/* Padding Indicator, 0x81 = First half */
 1307|       |
 1308|     34|	r = sc_transmit_apdu(card, apdu);
 1309|     34|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  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: 4, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1310|     30|	if (apdu->sw1 != 0x90 || apdu->sw2 != 0x00)
  ------------------
  |  Branch (1310:6): [True: 7, False: 23]
  |  Branch (1310:27): [True: 3, False: 20]
  ------------------
 1311|     10|		return 0;
 1312|       |
 1313|       |	/* Send 2nd part, expect response */
 1314|     20|	apdu->cse = resplen ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  294|     20|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              	apdu->cse = resplen ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|     20|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1314:14): [True: 20, False: 0]
  ------------------
 1315|     20|	apdu->data = &sbuf[crgram_half];
 1316|     20|	apdu->datalen = apdu->lc = crgram_len - crgram_half + 1;
 1317|     20|	apdu->resp = resp;
 1318|     20|	apdu->resplen = resplen;
 1319|     20|	apdu->le = resplen ? MIN(card->max_recv_size, crgram_len) : 0;
  ------------------
  |  |   70|     20|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 3, False: 17]
  |  |  ------------------
  ------------------
  |  Branch (1319:13): [True: 20, False: 0]
  ------------------
 1320|     20|	sbuf[crgram_half] = 0x82;	/* Padding Indicator, 0x82 = Second half */
 1321|       |
 1322|     20|	r = sc_transmit_apdu(card, apdu);
 1323|     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|      2|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2, False: 18]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1324|     20|}
card-myeid.c:myeid_process_fci:
  442|     73|{
  443|     73|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  444|     73|	size_t taglen = 0;
  445|     73|	const u8 *tag = NULL;
  446|     73|	int r;
  447|       |
  448|     73|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     73|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     73|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     73|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     73|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 73]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  449|     73|	r = iso_ops->process_fci(card, file, buf, buflen);
  450|     73|	if (r < 0)
  ------------------
  |  Branch (450:6): [True: 0, False: 73]
  ------------------
  451|     73|	 LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  452|       |
  453|     73|	if(file->type == SC_FILE_EF_UNKNOWN)
  ------------------
  |  |  220|     73|#define SC_FILE_EF_UNKNOWN		0x00
  ------------------
  |  Branch (453:5): [True: 56, False: 17]
  ------------------
  454|     56|	{
  455|     56|		tag = sc_asn1_find_tag(NULL, buf, buflen, 0x82, &taglen);
  456|     56|		if (tag != NULL && taglen > 0 && *tag == 17)
  ------------------
  |  Branch (456:7): [True: 12, False: 44]
  |  Branch (456:22): [True: 9, False: 3]
  |  Branch (456:36): [True: 3, False: 6]
  ------------------
  457|      3|		{
  458|      3|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      3|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  459|      3|		}
  460|     56|	}
  461|     73|	if(file->sec_attr_len >= 3)
  ------------------
  |  Branch (461:5): [True: 26, False: 47]
  ------------------
  462|     26|	{
  463|     26|		sc_log(card->ctx, "id (%X) sec_attr (%X %X %X)", file->id,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  464|     26|			file->sec_attr[0],file->sec_attr[1],file->sec_attr[2]);
  465|     26|	}
  466|       |
  467|     73|	priv->card_state = file->status;
  468|     73|	switch (file->status) {
  469|      3|		case SC_FILE_STATUS_CREATION:
  ------------------
  |  |  240|      3|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (469:3): [True: 3, False: 70]
  ------------------
  470|      3|			file->acl_inactive = 1;
  471|      3|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_CREATION", file->id);
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  472|      3|			break;
  473|      1|		case SC_FILE_STATUS_ACTIVATED:
  ------------------
  |  |  236|      1|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  |  Branch (473:3): [True: 1, False: 72]
  ------------------
  474|      1|			sc_log(card->ctx, "File id (%X) status SC_FILE_STATUS_ACTIVATED", file->id);
  ------------------
  |  |   71|      1|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  475|      1|			break;
  476|     69|		default:
  ------------------
  |  Branch (476:3): [True: 69, False: 4]
  ------------------
  477|     69|			sc_log(card->ctx, "File id (%X) unusual status (0x%X)", file->id, file->status);
  ------------------
  |  |   71|     69|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  478|     73|	}
  479|       |
  480|     73|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|     73|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     73|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     73|	int _ret = r; \
  |  |  |  |  155|     73|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 73, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     73|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  157|     73|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     73|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     73|	return _ret; \
  |  |  |  |  163|     73|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  481|     73|}
card-myeid.c:myeid_card_ctl:
 1821|    174|{
 1822|    174|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    174|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1823|    174|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    174|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1824|       |
 1825|    174|	switch(cmd) {
  ------------------
  |  Branch (1825:9): [True: 174, False: 0]
  ------------------
 1826|      0|	case SC_CARDCTL_MYEID_PUTDATA:
  ------------------
  |  Branch (1826:2): [True: 0, False: 174]
  ------------------
 1827|      0|		r = myeid_putdata(card,
 1828|      0|			(struct sc_cardctl_myeid_data_obj*) ptr);
 1829|      0|		break;
 1830|      0|	case SC_CARDCTL_MYEID_GETDATA:
  ------------------
  |  Branch (1830:2): [True: 0, False: 174]
  ------------------
 1831|      0|		r = myeid_getdata(card,
 1832|      0|			(struct sc_cardctl_myeid_data_obj*) ptr);
 1833|      0|		break;
 1834|      0|	case SC_CARDCTL_MYEID_GENERATE_STORE_KEY:
  ------------------
  |  Branch (1834:2): [True: 0, False: 174]
  ------------------
 1835|      0|		r = myeid_generate_store_key(card,
 1836|      0|			(struct sc_cardctl_myeid_gen_store_key_info *) ptr);
 1837|      0|		break;
 1838|      0|	case SC_CARDCTL_MYEID_ACTIVATE_CARD:
  ------------------
  |  Branch (1838:2): [True: 0, False: 174]
  ------------------
 1839|      0|		r = myeid_activate_card(card);
 1840|      0|		break;
 1841|    174|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1841:2): [True: 174, False: 0]
  ------------------
 1842|    174|		r = myeid_get_serialnr(card, (sc_serial_number_t *)ptr);
 1843|    174|		break;
 1844|      0|	case SC_CARDCTL_GET_CHANGE_COUNTER:
  ------------------
  |  Branch (1844:2): [True: 0, False: 174]
  ------------------
 1845|      0|		r = myeid_get_change_counter(card, (size_t *)ptr);
 1846|      0|		break;
 1847|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1847:2): [True: 0, False: 174]
  ------------------
 1848|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1848:2): [True: 0, False: 174]
  ------------------
 1849|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1849:2): [True: 0, False: 174]
  ------------------
 1850|      0|		break;
 1851|    174|	}
 1852|    174|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    174|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    174|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    174|	int _ret = r; \
  |  |  |  |  155|    174|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 174, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    174|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    172|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 172, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|    174|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    174|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    174|	return _ret; \
  |  |  |  |  163|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1853|    174|}
card-myeid.c:myeid_get_serialnr:
 1738|    174|{
 1739|    174|	int r;
 1740|    174|	u8  rbuf[256];
 1741|       |
 1742|    174|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    174|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1743|       |
 1744|       |	/* if number cached, get it
 1745|       |	if(card->serialnr.value) {
 1746|       |		memcpy(serial, &card->serialnr, sizeof(*serial));
 1747|       |		LOG_FUNC_RETURN(card->ctx, r);
 1748|       |	}*/
 1749|       |
 1750|       |	/* get number from card */
 1751|    174|	r = myeid_get_info(card, rbuf, sizeof(rbuf));
 1752|    174|	LOG_TEST_RET(card->ctx, r,  "Get applet info failed");
  ------------------
  |  |  174|    174|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    174|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    174|	int _ret = (r); \
  |  |  |  |  168|    174|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 172, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  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|    174|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1753|       |
 1754|       |	/* cache serial number */
 1755|      2|	memcpy(card->serialnr.value, &rbuf[8], 10);
 1756|      2|	card->serialnr.len = 10;
 1757|       |
 1758|       |	/* copy and return serial number */
 1759|      2|	memcpy(serial, &card->serialnr, sizeof(*serial));
 1760|       |
 1761|      2|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      2|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      2|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      2|	int _ret = r; \
  |  |  |  |  155|      2|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      2|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2]
  |  |  |  |  ------------------
  |  |  |  |  157|      2|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      2|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      2|	return _ret; \
  |  |  |  |  163|      2|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1762|      2|}
card-myeid.c:myeid_pin_cmd:
  668|    621|{
  669|    621|	myeid_private_data_t *priv = (myeid_private_data_t *) card->drv_data;
  670|       |
  671|    621|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    621|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    621|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    621|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    621|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 621]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|       |
  673|    621|	sc_log(card->ctx, "ref (%d), pin1 len(%zu), pin2 len (%zu)\n",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  674|    621|			data->pin_reference, data->pin1.len, data->pin2.len);
  675|       |
  676|    621|	if(data->pin1.len > 8 || data->pin2.len > 8)
  ------------------
  |  Branch (676:5): [True: 0, False: 621]
  |  Branch (676:27): [True: 0, False: 621]
  ------------------
  677|    621|		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|    621|	data->pin1.pad_length = data->pin2.pad_length = 8;
  680|    621|	data->pin1.pad_char = data->pin2.pad_char = 0xFF;
  681|       |
  682|    621|	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  422|  1.24k|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && priv->card_state == SC_FILE_STATUS_CREATION) {
  ------------------
  |  |  240|    111|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  |  Branch (682:6): [True: 111, False: 510]
  |  Branch (682:40): [True: 89, False: 22]
  ------------------
  683|     89|		sc_log(card->ctx, "Card in creation state, no need to verify");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  684|     89|		return SC_SUCCESS;
  ------------------
  |  |   28|     89|#define SC_SUCCESS				0
  ------------------
  685|     89|	}
  686|       |
  687|    532|	LOG_FUNC_RETURN(card->ctx, iso_ops->pin_cmd(card, data, tries_left));
  ------------------
  |  |  164|    532|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (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|    250|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 250, False: 282]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  688|    532|}

sc_get_npa_driver:
  815|  15.3k|{
  816|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
  817|       |
  818|  15.3k|	npa_ops = *iso_drv->ops;
  819|  15.3k|	npa_ops.match_card = npa_match_card;
  820|  15.3k|	npa_ops.init = npa_init;
  821|  15.3k|	npa_ops.finish = npa_finish;
  822|  15.3k|	npa_ops.set_security_env = npa_set_security_env;
  823|  15.3k|	npa_ops.pin_cmd = npa_pin_cmd;
  824|  15.3k|	npa_ops.logout = npa_logout;
  825|       |
  826|  15.3k|	return &npa_drv;
  827|  15.3k|}
card-npa.c:npa_match_card:
  153|  2.43k|{
  154|  2.43k|	unsigned char dir_content[sizeof dir_content_ref];
  155|  2.43k|	unsigned char id[] = {0x2F, 0x00};
  156|  2.43k|	sc_apdu_t select_ef_dir;
  157|       |
  158|  2.43k|	sc_format_apdu_ex(&select_ef_dir, 0x00, 0xA4, 0x02, 0x0C, id, sizeof id, NULL, 0);
  159|       |
  160|  2.43k|	if (SC_SUCCESS == sc_select_file(card, sc_get_mf_path(), NULL)
  ------------------
  |  |   28|  2.43k|#define SC_SUCCESS				0
  ------------------
  |  Branch (160:6): [True: 38, False: 2.39k]
  ------------------
  161|     38|			&& SC_SUCCESS == sc_transmit_apdu(card, &select_ef_dir)
  ------------------
  |  |   28|     38|#define SC_SUCCESS				0
  ------------------
  |  Branch (161:7): [True: 35, False: 3]
  ------------------
  162|     35|			&& select_ef_dir.sw1 == 0x90 && select_ef_dir.sw2 == 0x00
  ------------------
  |  Branch (162:7): [True: 19, False: 16]
  |  Branch (162:36): [True: 16, False: 3]
  ------------------
  163|     16|			&& sizeof dir_content == sc_read_binary(card, 0, dir_content, sizeof dir_content, 0)
  ------------------
  |  Branch (163:7): [True: 9, False: 7]
  ------------------
  164|      9|			&& 0 == memcmp(dir_content_ref, dir_content, sizeof dir_content))
  ------------------
  |  Branch (164:7): [True: 0, False: 9]
  ------------------
  165|      0|		return 1;
  166|       |
  167|  2.43k|	return 0;
  168|  2.43k|}

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

sc_get_oberthur_driver:
 2335|  15.3k|{
 2336|  15.3k|	return sc_get_driver();
 2337|  15.3k|}
card-oberthur.c:sc_get_driver:
 2304|  15.3k|{
 2305|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (2305:6): [True: 1, False: 15.3k]
  ------------------
 2306|      1|		iso_ops = sc_get_iso7816_driver()->ops;
 2307|       |
 2308|  15.3k|	auth_ops = *iso_ops;
 2309|  15.3k|	auth_ops.match_card = auth_match_card;
 2310|  15.3k|	auth_ops.init = auth_init;
 2311|  15.3k|	auth_ops.finish = auth_finish;
 2312|  15.3k|	auth_ops.select_file = auth_select_file;
 2313|  15.3k|	auth_ops.list_files = auth_list_files;
 2314|  15.3k|	auth_ops.delete_file = auth_delete_file;
 2315|  15.3k|	auth_ops.create_file = auth_create_file;
 2316|  15.3k|	auth_ops.read_binary = auth_read_binary;
 2317|  15.3k|	auth_ops.update_binary = auth_update_binary;
 2318|  15.3k|	auth_ops.read_record = auth_read_record;
 2319|  15.3k|	auth_ops.delete_record = auth_delete_record;
 2320|  15.3k|	auth_ops.card_ctl = auth_card_ctl;
 2321|  15.3k|	auth_ops.set_security_env = auth_set_security_env;
 2322|  15.3k|	auth_ops.restore_security_env = auth_restore_security_env;
 2323|  15.3k|	auth_ops.compute_signature = auth_compute_signature;
 2324|  15.3k|	auth_ops.decipher = auth_decipher;
 2325|  15.3k|	auth_ops.process_fci = auth_process_fci;
 2326|  15.3k|	auth_ops.pin_cmd = auth_pin_cmd;
 2327|  15.3k|	auth_ops.logout = auth_logout;
 2328|  15.3k|	auth_ops.check_sw = auth_check_sw;
 2329|  15.3k|	return &auth_drv;
 2330|  15.3k|}
card-oberthur.c:auth_match_card:
  204|  11.0k|{
  205|  11.0k|	if (_sc_match_atr(card, oberthur_atrs, &card->type) < 0)
  ------------------
  |  Branch (205:6): [True: 10.1k, False: 894]
  ------------------
  206|  10.1k|		return 0;
  207|    894|	else
  208|    894|		return 1;
  209|  11.0k|}
card-oberthur.c:auth_init:
  214|    894|{
  215|    894|	struct auth_private_data *data;
  216|    894|	struct sc_path path;
  217|    894|	unsigned long flags;
  218|    894|	int rv = 0;
  219|       |
  220|    894|	data = calloc(1, sizeof(struct auth_private_data));
  221|    894|	if (!data)
  ------------------
  |  Branch (221:6): [True: 0, False: 894]
  ------------------
  222|    894|		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|    894|	card->cla = 0x00;
  225|    894|	card->drv_data = data;
  226|       |
  227|    894|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    894|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  228|    894|	card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  564|    894|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  229|       |
  230|    894|	if (auth_select_aid(card)) {
  ------------------
  |  Branch (230:6): [True: 57, False: 837]
  ------------------
  231|     57|		sc_log(card->ctx, "Failed to initialize %s", card->name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  232|     57|		rv = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|     57|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  233|     57|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_CARD, "Failed to initialize");
  ------------------
  |  |  184|     57|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     57|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     57|	int _ret = (r); \
  |  |  |  |  178|     57|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     57|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     57|		goto err; \
  |  |  |  |  182|     57|	} \
  |  |  |  |  183|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  234|     57|	}
  235|       |
  236|    837|	sc_format_path("3F00", &path);
  237|    837|	rv = auth_select_file(card, &path, NULL);
  238|       |
  239|    894|err:
  240|    894|	if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|    894|#define SC_SUCCESS				0
  ------------------
  |  Branch (240:6): [True: 837, False: 57]
  ------------------
  241|    837|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  120|    837|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    837|#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) */
  |  |  ------------------
  |  |  |  |  119|    837|#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;
  ------------------
  |  |  115|    837|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  242|    837|		flags |= SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|    837|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  243|    837|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    837|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  244|       |
  245|    837|		_sc_card_add_rsa_alg(card, 512, flags, 0);
  246|    837|		_sc_card_add_rsa_alg(card, 1024, flags, 0);
  247|    837|		_sc_card_add_rsa_alg(card, 2048, flags, 0);
  248|    837|	} else {
  249|     57|		free(card->drv_data);
  250|     57|		card->drv_data = NULL;
  251|     57|	}
  252|       |
  253|    894|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|    894|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    894|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    894|	int _ret = r; \
  |  |  |  |  155|    894|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 894, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    894|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 837]
  |  |  |  |  ------------------
  |  |  |  |  157|    894|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    894|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    894|	return _ret; \
  |  |  |  |  163|    894|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|    894|}
card-oberthur.c:auth_select_aid:
  145|    894|{
  146|    894|	struct sc_apdu apdu;
  147|    894|	unsigned char apdu_resp[SC_MAX_APDU_BUFFER_SIZE];
  148|    894|	struct auth_private_data *data = (struct auth_private_data *)card->drv_data;
  149|    894|	int rv, ii;
  150|    894|	struct sc_path tmp_path;
  151|       |
  152|       |	/* Select Card Manager (to deselect previously selected application) */
  153|    894|	rv = gp_select_card_manager(card);
  154|    894|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    894|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    894|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    894|	int _ret = (r); \
  |  |  |  |  168|    894|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 39, False: 855]
  |  |  |  |  ------------------
  |  |  |  |  169|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     39|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     39|		return _ret; \
  |  |  |  |  172|     39|	} \
  |  |  |  |  173|    894|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 855]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|       |
  156|       |	/* Get smart card serial number */
  157|    855|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x9F, 0x7F);
  ------------------
  |  |  292|    855|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  158|    855|	apdu.cla = 0x80;
  159|    855|	apdu.le = 0x2D;
  160|    855|	apdu.resplen = 0x30;
  161|    855|	apdu.resp = apdu_resp;
  162|       |
  163|    855|	rv = sc_transmit_apdu(card, &apdu);
  164|    855|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    855|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    855|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    855|	int _ret = (r); \
  |  |  |  |  168|    855|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 854]
  |  |  |  |  ------------------
  |  |  |  |  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|    855|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 854]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|    854|	if (apdu.resplen < 20) {
  ------------------
  |  Branch (165:6): [True: 4, False: 850]
  ------------------
  166|      4|		LOG_TEST_RET(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED, "Serial number has incorrect 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|      4|	}
  168|    850|	card->serialnr.len = 4;
  169|    850|	memcpy(card->serialnr.value, apdu.resp+15, 4);
  170|       |
  171|  4.25k|	for (ii=0, data->sn = 0; ii < 4; ii++)
  ------------------
  |  Branch (171:27): [True: 3.40k, False: 850]
  ------------------
  172|  3.40k|		data->sn += (long int)(*(apdu.resp + 15 + ii)) << (3-ii)*8;
  173|       |
  174|    850|	sc_log(card->ctx, "serial number %li/0x%lX", data->sn, data->sn);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  175|       |
  176|    850|	memset(&tmp_path, 0, sizeof(struct sc_path));
  177|    850|	tmp_path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    850|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  178|    850|	memcpy(tmp_path.value, aidAuthentIC_V5, lenAidAuthentIC_V5);
  179|    850|	tmp_path.len = lenAidAuthentIC_V5;
  180|       |
  181|    850|	rv = iso_ops->select_file(card, &tmp_path, NULL);
  182|    850|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  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: 8, False: 842]
  |  |  |  |  ------------------
  |  |  |  |  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|    850|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 842]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  183|       |
  184|    842|	sc_format_path("3F00", &tmp_path);
  185|    842|	sc_file_free(auth_current_df);
  186|    842|	auth_current_df = NULL;
  187|    842|	rv = iso_ops->select_file(card, &tmp_path, &auth_current_df);
  188|    842|	LOG_TEST_RET(card->ctx, rv, "select parent failed");
  ------------------
  |  |  174|    842|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    842|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    842|	int _ret = (r); \
  |  |  |  |  168|    842|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 837]
  |  |  |  |  ------------------
  |  |  |  |  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|    842|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 837]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  189|       |
  190|    837|	sc_file_free(auth_current_ef);
  191|    837|	auth_current_ef = NULL;
  192|    837|	sc_file_dup(&auth_current_ef, auth_current_df);
  193|       |
  194|    837|	memcpy(data->aid, aidAuthentIC_V5, lenAidAuthentIC_V5);
  195|    837|	data->aid_len = lenAidAuthentIC_V5;
  196|    837|	card->name = nameAidAuthentIC_V5;
  197|       |
  198|    837|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  199|    837|}
card-oberthur.c:auth_finish:
  137|    837|{
  138|    837|	free(card->drv_data);
  139|    837|	return SC_SUCCESS;
  ------------------
  |  |   28|    837|#define SC_SUCCESS				0
  ------------------
  140|    837|}
card-oberthur.c:auth_select_file:
  445|  17.9k|{
  446|  17.9k|	struct sc_path path;
  447|  17.9k|	struct sc_file *tmp_file = NULL;
  448|  17.9k|	size_t offs, ii;
  449|  17.9k|	int rv;
  450|       |
  451|  17.9k|	if (card == NULL || in_path == NULL)
  ------------------
  |  Branch (451:6): [True: 0, False: 17.9k]
  |  Branch (451:22): [True: 0, False: 17.9k]
  ------------------
  452|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  453|       |
  454|  17.9k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  17.9k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  17.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  17.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  17.9k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 17.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  455|       |
  456|  17.9k|	memcpy(&path, in_path, sizeof(struct sc_path));
  457|       |
  458|  17.9k|	if (!auth_current_df)
  ------------------
  |  Branch (458:6): [True: 0, False: 17.9k]
  ------------------
  459|      0|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  460|       |
  461|  17.9k|	sc_log(card->ctx, "in_path; type=%d, path=%s, out %p",
  ------------------
  |  |   71|  17.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  462|  17.9k|			in_path->type, sc_print_path(in_path), file_out);
  463|  17.9k|	sc_log(card->ctx, "current path; type=%d, path=%s",
  ------------------
  |  |   71|  17.9k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  464|  17.9k|			auth_current_df->path.type, sc_print_path(&auth_current_df->path));
  465|  17.9k|	if (auth_current_ef)
  ------------------
  |  Branch (465:6): [True: 11.4k, False: 6.51k]
  ------------------
  466|  11.4k|		sc_log(card->ctx, "current file; type=%d, path=%s",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  467|  17.9k|				auth_current_ef->path.type, sc_print_path(&auth_current_ef->path));
  468|       |
  469|  17.9k|	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  123|  35.8k|#define SC_PATH_TYPE_PARENT		5
  ------------------
              	if (path.type == SC_PATH_TYPE_PARENT || path.type == SC_PATH_TYPE_FILE_ID) {
  ------------------
  |  |  117|  17.7k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (469:6): [True: 125, False: 17.7k]
  |  Branch (469:42): [True: 9.12k, False: 8.67k]
  ------------------
  470|  9.24k|		sc_file_free(auth_current_ef);
  471|  9.24k|		auth_current_ef = NULL;
  472|       |
  473|  9.24k|		rv = iso_ops->select_file(card, &path, &tmp_file);
  474|  9.24k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  9.24k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  9.24k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  9.24k|	int _ret = (r); \
  |  |  |  |  168|  9.24k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.93k, False: 6.31k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.93k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.93k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.93k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.93k|		return _ret; \
  |  |  |  |  172|  2.93k|	} \
  |  |  |  |  173|  9.24k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.31k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  475|  6.31k|		if (!tmp_file)
  ------------------
  |  Branch (475:7): [True: 0, False: 6.31k]
  ------------------
  476|      0|			return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|      0|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
  477|       |
  478|  6.31k|		if (path.type == SC_PATH_TYPE_PARENT) {
  ------------------
  |  |  123|  6.31k|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (478:7): [True: 57, False: 6.25k]
  ------------------
  479|     57|			memcpy(&tmp_file->path, &auth_current_df->path, sizeof(struct sc_path));
  480|     57|			if (tmp_file->path.len > 2)
  ------------------
  |  Branch (480:8): [True: 57, False: 0]
  ------------------
  481|     57|				tmp_file->path.len -= 2;
  482|       |
  483|     57|			sc_file_free(auth_current_df);
  484|     57|			auth_current_df = NULL;
  485|     57|			sc_file_dup(&auth_current_df, tmp_file);
  486|  6.25k|		} else {
  487|  6.25k|			if (tmp_file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  6.25k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (487:8): [True: 208, False: 6.04k]
  ------------------
  488|    208|				sc_concatenate_path(&tmp_file->path, &auth_current_df->path, &path);
  489|       |
  490|    208|				sc_file_free(auth_current_df);
  491|    208|				auth_current_df = NULL;
  492|    208|				sc_file_dup(&auth_current_df, tmp_file);
  493|  6.04k|			} else {
  494|  6.04k|				sc_file_free(auth_current_ef);
  495|  6.04k|				auth_current_ef = NULL;
  496|       |
  497|  6.04k|				sc_file_dup(&auth_current_ef, tmp_file);
  498|  6.04k|				sc_concatenate_path(&auth_current_ef->path, &auth_current_df->path, &path);
  499|  6.04k|			}
  500|  6.25k|		}
  501|  6.31k|		if (file_out) {
  ------------------
  |  Branch (501:7): [True: 4.96k, False: 1.35k]
  ------------------
  502|  4.96k|			sc_file_free(*file_out);
  503|  4.96k|			sc_file_dup(file_out, tmp_file);
  504|  4.96k|		}
  505|       |
  506|  6.31k|		sc_file_free(tmp_file);
  507|  8.67k|	} else if (path.type == SC_PATH_TYPE_DF_NAME) {
  ------------------
  |  |  118|  8.67k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (507:13): [True: 1.35k, False: 7.32k]
  ------------------
  508|  1.35k|		rv = iso_ops->select_file(card, &path, NULL);
  509|  1.35k|		if (rv) {
  ------------------
  |  Branch (509:7): [True: 1.28k, False: 73]
  ------------------
  510|  1.28k|			sc_file_free(auth_current_ef);
  511|  1.28k|			auth_current_ef = NULL;
  512|  1.28k|		}
  513|  1.35k|		LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|  1.35k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.35k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.35k|	int _ret = (r); \
  |  |  |  |  168|  1.35k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.28k, False: 73]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.28k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.28k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.28k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.28k|		return _ret; \
  |  |  |  |  172|  1.28k|	} \
  |  |  |  |  173|  1.35k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 73]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  514|  7.32k|	} else {
  515|  15.4k|		for (offs = 0; offs < path.len && offs < auth_current_df->path.len; offs += 2)
  ------------------
  |  Branch (515:18): [True: 14.3k, False: 1.07k]
  |  Branch (515:37): [True: 8.26k, False: 6.05k]
  ------------------
  516|  8.26k|			if (path.value[offs] != auth_current_df->path.value[offs] ||
  ------------------
  |  Branch (516:8): [True: 155, False: 8.11k]
  ------------------
  517|  8.11k|					path.value[offs + 1] != auth_current_df->path.value[offs + 1])
  ------------------
  |  Branch (517:6): [True: 29, False: 8.08k]
  ------------------
  518|    184|				break;
  519|       |
  520|  7.32k|		sc_log(card->ctx, "offs %"SC_FORMAT_LEN_SIZE_T"u", offs);
  ------------------
  |  |   71|  7.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__
  |  |  ------------------
  ------------------
  521|  7.32k|		if (offs && offs < auth_current_df->path.len) {
  ------------------
  |  Branch (521:7): [True: 7.25k, False: 69]
  |  Branch (521:15): [True: 115, False: 7.13k]
  ------------------
  522|    115|			size_t deep = auth_current_df->path.len - offs;
  523|       |
  524|    115|			sc_log(card->ctx, "deep %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  525|    115|			       deep);
  526|    172|			for (ii = 0; ii < deep; ii += 2) {
  ------------------
  |  Branch (526:17): [True: 125, False: 47]
  ------------------
  527|    125|				struct sc_path tmp_path;
  528|       |
  529|    125|				memcpy(&tmp_path, &auth_current_df->path,  sizeof(struct sc_path));
  530|    125|				tmp_path.type = SC_PATH_TYPE_PARENT;
  ------------------
  |  |  123|    125|#define SC_PATH_TYPE_PARENT		5
  ------------------
  531|       |
  532|    125|				if (file_out) {
  ------------------
  |  Branch (532:9): [True: 15, False: 110]
  ------------------
  533|     15|					sc_file_free(*file_out);
  534|     15|					*file_out = NULL;
  535|     15|				}
  536|       |
  537|    125|				rv = auth_select_file (card, &tmp_path, file_out);
  538|    125|				LOG_TEST_RET(card->ctx, rv, "select file failed");
  ------------------
  |  |  174|    125|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    125|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    125|	int _ret = (r); \
  |  |  |  |  168|    125|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 68, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  169|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     68|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     68|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     68|		return _ret; \
  |  |  |  |  172|     68|	} \
  |  |  |  |  173|    125|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  539|    125|			}
  540|    115|		}
  541|       |
  542|  7.25k|		if (path.len > offs) {
  ------------------
  |  Branch (542:7): [True: 6.17k, False: 1.07k]
  ------------------
  543|  6.17k|			struct sc_path tmp_path;
  544|       |
  545|  6.17k|			memset(&tmp_path, 0, sizeof(struct sc_path));
  546|  6.17k|			tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|  6.17k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  547|  6.17k|			tmp_path.len = 2;
  548|       |
  549|  12.4k|			for (ii = 0; ii < path.len - offs; ii += 2) {
  ------------------
  |  Branch (549:17): [True: 9.12k, False: 3.31k]
  ------------------
  550|  9.12k|				memcpy(tmp_path.value, path.value + offs + ii, 2);
  551|       |
  552|  9.12k|				if (file_out) {
  ------------------
  |  Branch (552:9): [True: 6.44k, False: 2.67k]
  ------------------
  553|  6.44k|					sc_file_free(*file_out);
  554|  6.44k|					*file_out = NULL;
  555|  6.44k|				}
  556|       |
  557|  9.12k|				rv = auth_select_file(card, &tmp_path, file_out);
  558|  9.12k|				LOG_TEST_RET(card->ctx, rv, "select file 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: 2.86k, False: 6.25k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.86k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.86k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.86k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.86k|		return _ret; \
  |  |  |  |  172|  2.86k|	} \
  |  |  |  |  173|  9.12k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6.25k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  559|  9.12k|			}
  560|  6.17k|		} else if (path.len - offs == 0 && file_out) {
  ------------------
  |  Branch (560:14): [True: 1.07k, False: 0]
  |  Branch (560:38): [True: 0, False: 1.07k]
  ------------------
  561|      0|			if (sc_compare_path(&path, &auth_current_df->path) && file_out) {
  ------------------
  |  Branch (561:8): [True: 0, False: 0]
  |  Branch (561:58): [True: 0, False: 0]
  ------------------
  562|      0|				sc_file_free(*file_out);
  563|      0|				sc_file_dup(file_out, auth_current_df);
  564|      0|			} else  if (auth_current_ef && file_out) {
  ------------------
  |  Branch (564:16): [True: 0, False: 0]
  |  Branch (564:35): [True: 0, False: 0]
  ------------------
  565|      0|				sc_file_free(*file_out);
  566|      0|				sc_file_dup(file_out, auth_current_ef);
  567|      0|			} else {
  568|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  569|      0|			}
  570|      0|		}
  571|  7.25k|	}
  572|       |
  573|  10.7k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  10.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  10.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  10.7k|	int _ret = r; \
  |  |  |  |  155|  10.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.7k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.7k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 10.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.7k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.7k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  10.7k|	return _ret; \
  |  |  |  |  163|  10.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  574|  10.7k|}
card-oberthur.c:auth_read_binary:
 2114|  11.6k|{
 2115|  11.6k|	int rv;
 2116|  11.6k|	size_t sz;
 2117|  11.6k|	struct sc_pkcs15_bignum bn[2];
 2118|  11.6k|	unsigned char *out = NULL;
 2119|  11.6k|	bn[0].data = NULL;
 2120|  11.6k|	bn[1].data = NULL;
 2121|       |
 2122|  11.6k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  11.6k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.6k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2123|       |
 2124|  11.6k|	if (!auth_current_ef)
  ------------------
  |  Branch (2124:6): [True: 20, False: 11.6k]
  ------------------
 2125|  11.6k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid auth_current_ef");
  ------------------
  |  |  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: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2126|       |
 2127|  11.6k|	sc_log(card->ctx,
  ------------------
  |  |   71|  23.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__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 0, False: 11.6k]
  |  |  ------------------
  ------------------
 2128|  11.6k|	       "offset %i; size %"SC_FORMAT_LEN_SIZE_T"u; flags 0x%lX",
 2129|  11.6k|	       offset, count, flags ? *flags : 0);
 2130|  11.6k|	sc_log(card->ctx,"last selected : magic %X; ef %X",
  ------------------
  |  |   71|  11.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__
  |  |  ------------------
  ------------------
 2131|  11.6k|			auth_current_ef->magic, auth_current_ef->ef_structure);
 2132|       |
 2133|  11.6k|	if (offset & ~0x7FFF)
  ------------------
  |  Branch (2133:6): [True: 1, False: 11.6k]
  ------------------
 2134|  11.6k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid file offset");
  ------------------
  |  |  174|      1|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      1|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      1|	int _ret = (r); \
  |  |  |  |  168|      1|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2135|       |
 2136|  11.6k|	if (auth_current_ef->magic == SC_FILE_MAGIC &&
  ------------------
  |  |   57|  23.2k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  |  Branch (2136:6): [True: 11.6k, False: 0]
  ------------------
 2137|  11.6k|			auth_current_ef->ef_structure == SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC) {
  ------------------
  |  Branch (2137:4): [True: 109, False: 11.5k]
  ------------------
 2138|    109|		int jj;
 2139|    109|		unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 2140|    109|		size_t resp_len, out_len;
 2141|    109|		struct sc_pkcs15_pubkey_rsa key;
 2142|       |
 2143|    109|		resp_len = sizeof(resp);
 2144|    109|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2145|    109|				2, resp, resp_len);
 2146|    109|		LOG_TEST_RET(card->ctx, rv, "read component failed");
  ------------------
  |  |  174|    109|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    109|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    109|	int _ret = (r); \
  |  |  |  |  168|    109|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 26, False: 83]
  |  |  |  |  ------------------
  |  |  |  |  169|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     26|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     26|		return _ret; \
  |  |  |  |  172|     26|	} \
  |  |  |  |  173|    109|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 83]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2147|       |
 2148|    299|		for (jj=0; jj<rv && *(resp+jj)==0; jj++)
  ------------------
  |  Branch (2148:14): [True: 296, False: 3]
  |  Branch (2148:23): [True: 216, False: 80]
  ------------------
 2149|    216|			;
 2150|       |
 2151|     83|		if (rv - jj == 0)
  ------------------
  |  Branch (2151:7): [True: 3, False: 80]
  ------------------
 2152|      3|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      3|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 2153|     80|		bn[0].data = calloc(1, rv - jj);
 2154|     80|		if (!bn[0].data) {
  ------------------
  |  Branch (2154:7): [True: 0, False: 80]
  ------------------
 2155|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2156|      0|			goto err;
 2157|      0|		}
 2158|     80|		bn[0].len = rv - jj;
 2159|     80|		memcpy(bn[0].data, resp + jj, rv - jj);
 2160|       |
 2161|     80|		rv = auth_read_component(card, SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC,
 2162|     80|				1, resp, resp_len);
 2163|     80|		LOG_TEST_GOTO_ERR(card->ctx, rv, "Cannot read RSA public key component");
  ------------------
  |  |  184|     80|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     80|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     80|	int _ret = (r); \
  |  |  |  |  178|     80|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 17, False: 63]
  |  |  |  |  ------------------
  |  |  |  |  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|     80|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 63]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2164|       |
 2165|     63|		bn[1].data = calloc(1, rv);
 2166|     63|		if (!bn[1].data) {
  ------------------
  |  Branch (2166:7): [True: 0, False: 63]
  ------------------
 2167|      0|			rv = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2168|      0|			goto err;
 2169|      0|		}
 2170|     63|		bn[1].len = rv;
 2171|     63|		memcpy(bn[1].data, resp, rv);
 2172|       |
 2173|     63|		key.exponent = bn[0];
 2174|     63|		key.modulus = bn[1];
 2175|       |
 2176|     63|		if (sc_pkcs15_encode_pubkey_rsa(card->ctx, &key, &out, &out_len) != SC_SUCCESS) {
  ------------------
  |  |   28|     63|#define SC_SUCCESS				0
  ------------------
  |  Branch (2176:7): [True: 6, False: 57]
  ------------------
 2177|      6|			rv = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      6|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2178|      6|			LOG_TEST_GOTO_ERR(card->ctx, rv, "cannot encode RSA public key");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2179|      6|		}
 2180|     57|		else {
 2181|     57|			if (out_len < offset) {
  ------------------
  |  Branch (2181:8): [True: 2, False: 55]
  ------------------
 2182|      2|				rv = SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|      2|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
 2183|      2|				goto err;
 2184|      2|			}
 2185|     55|			sz = MIN(out_len - offset, count);
  ------------------
  |  |   70|     55|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 33, False: 22]
  |  |  ------------------
  ------------------
 2186|     55|			memcpy(buf, out + offset, sz);
 2187|       |
 2188|     55|			sc_log_hex(card->ctx, "write_publickey", buf, sz);
  ------------------
  |  |  129|     55|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|     55|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2189|     55|			rv = (int)sz;
 2190|     55|		}
 2191|  11.5k|	} else {
 2192|  11.5k|		rv = iso_ops->read_binary(card, offset, buf, count, 0);
 2193|  11.5k|	}
 2194|       |
 2195|  11.6k|err:
 2196|  11.6k|	free(bn[0].data);
 2197|  11.6k|	free(bn[1].data);
 2198|  11.6k|	free(out);
 2199|       |
 2200|  11.6k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|  11.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.6k|	int _ret = r; \
  |  |  |  |  155|  11.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 183, False: 11.4k]
  |  |  |  |  ------------------
  |  |  |  |  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|    150|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 150, False: 33]
  |  |  |  |  ------------------
  |  |  |  |  157|    183|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.4k|	} else { \
  |  |  |  |  159|  11.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  11.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  11.4k|	} \
  |  |  |  |  162|  11.6k|	return _ret; \
  |  |  |  |  163|  11.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2201|  11.6k|}
card-oberthur.c:auth_read_component:
 1481|    189|{
 1482|    189|	struct sc_apdu apdu;
 1483|    189|	int rv;
 1484|    189|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
 1485|       |
 1486|    189|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    189|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    189|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    189|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    189|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 189]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1487|    189|	sc_log(card->ctx, "num %i, outlen %"SC_FORMAT_LEN_SIZE_T"u, type %i",
  ------------------
  |  |   71|    189|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1488|    189|	       num, outlen, type);
 1489|       |
 1490|    189|	if (!outlen || type!=SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC)
  ------------------
  |  Branch (1490:6): [True: 0, False: 189]
  |  Branch (1490:17): [True: 0, False: 189]
  ------------------
 1491|    189|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1492|       |
 1493|    189|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB4,	num, 0x00);
  ------------------
  |  |  292|    189|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 1494|    189|	apdu.cla |= 0x80;
 1495|    189|	apdu.le = outlen;
 1496|    189|	apdu.resp = resp;
 1497|    189|	apdu.resplen = sizeof(resp);
 1498|    189|	rv = sc_transmit_apdu(card, &apdu);
 1499|    189|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    189|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    189|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    189|	int _ret = (r); \
  |  |  |  |  168|    189|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 188]
  |  |  |  |  ------------------
  |  |  |  |  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|    189|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 188]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1500|       |
 1501|    188|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1502|    188|	LOG_TEST_RET(card->ctx, rv, "Card returned 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: 42, False: 146]
  |  |  |  |  ------------------
  |  |  |  |  169|     42|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     42|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     42|		return _ret; \
  |  |  |  |  172|     42|	} \
  |  |  |  |  173|    188|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 146]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1503|       |
 1504|    146|	if (outlen < apdu.resplen)
  ------------------
  |  Branch (1504:6): [True: 0, False: 146]
  ------------------
 1505|    146|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1506|       |
 1507|    146|	memcpy(out, apdu.resp, apdu.resplen);
 1508|    146|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 8, False: 138]
  |  |  |  |  ------------------
  |  |  |  |  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|    138|	} else { \
  |  |  |  |  159|    138|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    138|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    138|	} \
  |  |  |  |  162|    146|	return _ret; \
  |  |  |  |  163|    146|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1509|    146|}
card-oberthur.c:auth_read_record:
 2207|  4.55k|{
 2208|  4.55k|	struct sc_apdu apdu;
 2209|  4.55k|	int rv = 0;
 2210|  4.55k|	unsigned char recvbuf[SC_MAX_APDU_BUFFER_SIZE];
 2211|       |
 2212|  4.55k|	sc_log(card->ctx,
  ------------------
  |  |   71|  4.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__
  |  |  ------------------
  ------------------
 2213|  4.55k|	       "auth_read_record(): nr_rec %i; count %"SC_FORMAT_LEN_SIZE_T"u",
 2214|  4.55k|	       nr_rec, count);
 2215|       |
 2216|  4.55k|	if (nr_rec > 0xFF || idx != 0)
  ------------------
  |  Branch (2216:6): [True: 0, False: 4.55k]
  |  Branch (2216:23): [True: 1.04k, False: 3.51k]
  ------------------
 2217|  4.55k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|  1.04k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.04k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.04k|	int _ret = r; \
  |  |  |  |  155|  1.04k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.04k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.04k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.04k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.04k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.04k|	return _ret; \
  |  |  |  |  163|  1.04k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2218|       |
 2219|  3.51k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xB2, nr_rec, 0);
  ------------------
  |  |  292|  3.51k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 2220|  3.51k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1301|  3.51k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
 2221|  3.51k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1306|  3.51k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (2221:6): [True: 3.51k, False: 0]
  ------------------
 2222|  3.51k|		apdu.p2 |= 0x04;
 2223|       |
 2224|  3.51k|	apdu.le = MIN(count, SC_MAX_APDU_BUFFER_SIZE);
  ------------------
  |  |   70|  3.51k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 3.51k, False: 0]
  |  |  ------------------
  ------------------
 2225|  3.51k|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|  3.51k|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 2226|  3.51k|	apdu.resp = recvbuf;
 2227|       |
 2228|  3.51k|	rv = sc_transmit_apdu(card, &apdu);
 2229|  3.51k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  3.51k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  3.51k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  3.51k|	int _ret = (r); \
  |  |  |  |  168|  3.51k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 3.51k]
  |  |  |  |  ------------------
  |  |  |  |  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.51k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 3.51k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2230|  3.51k|	if (apdu.resplen == 0)
  ------------------
  |  Branch (2230:6): [True: 1.41k, False: 2.09k]
  ------------------
 2231|  3.51k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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|     41|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 41, False: 1.37k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2232|  2.09k|	if (count < apdu.resplen)
  ------------------
  |  Branch (2232:6): [True: 3, False: 2.09k]
  ------------------
 2233|  2.09k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2234|  2.09k|	memcpy(buf, recvbuf, apdu.resplen);
 2235|       |
 2236|  2.09k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2237|  2.09k|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|  2.09k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  2.09k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  2.09k|	int _ret = (r); \
  |  |  |  |  168|  2.09k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 2.08k]
  |  |  |  |  ------------------
  |  |  |  |  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|  2.09k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2238|       |
 2239|  2.08k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 0, False: 2.08k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.08k|	} else { \
  |  |  |  |  159|  2.08k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.08k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.08k|	} \
  |  |  |  |  162|  2.08k|	return _ret; \
  |  |  |  |  163|  2.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2240|  2.08k|}
card-oberthur.c:auth_card_ctl:
 1453|      4|{
 1454|      4|	switch (cmd) {
 1455|      0|	case SC_CARDCTL_GET_DEFAULT_KEY:
  ------------------
  |  Branch (1455:2): [True: 0, False: 4]
  ------------------
 1456|      0|		return auth_get_default_key(card,
 1457|      0|				(struct sc_cardctl_default_key *) ptr);
 1458|      0|	case SC_CARDCTL_OBERTHUR_GENERATE_KEY:
  ------------------
  |  Branch (1458:2): [True: 0, False: 4]
  ------------------
 1459|      0|		return auth_generate_key(card, 0,
 1460|      0|				(struct sc_cardctl_oberthur_genkey_info *) ptr);
 1461|      0|	case SC_CARDCTL_OBERTHUR_UPDATE_KEY:
  ------------------
  |  Branch (1461:2): [True: 0, False: 4]
  ------------------
 1462|      0|		return auth_update_key(card,
 1463|      0|				(struct sc_cardctl_oberthur_updatekey_info *) ptr);
 1464|      0|	case SC_CARDCTL_OBERTHUR_CREATE_PIN:
  ------------------
  |  Branch (1464:2): [True: 0, False: 4]
  ------------------
 1465|      0|		return auth_create_reference_data(card,
 1466|      0|				(struct sc_cardctl_oberthur_createpin_info *) ptr);
 1467|      4|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1467:2): [True: 4, False: 0]
  ------------------
 1468|      4|		return auth_get_serialnr(card, (struct sc_serial_number *)ptr);
 1469|      0|	case SC_CARDCTL_LIFECYCLE_GET:
  ------------------
  |  Branch (1469:2): [True: 0, False: 4]
  ------------------
 1470|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (1470:2): [True: 0, False: 4]
  ------------------
 1471|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1472|      0|	default:
  ------------------
  |  Branch (1472:2): [True: 0, False: 4]
  ------------------
 1473|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1474|      4|	}
 1475|      4|}
card-oberthur.c:auth_init_pin_info:
 1540|  1.19k|{
 1541|  1.19k|	pin->offset = 0;
 1542|  1.19k|	pin->pad_char   = 0xFF;
 1543|  1.19k|	pin->encoding   = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|  1.19k|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1544|       |
 1545|  1.19k|	if (type == OBERTHUR_AUTH_TYPE_PIN) {
  ------------------
  |  |   92|  1.19k|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
  |  Branch (1545:6): [True: 1.19k, False: 0]
  ------------------
 1546|  1.19k|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|  1.19k|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1547|  1.19k|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|  1.19k|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1548|  1.19k|	} else {
 1549|      0|		pin->max_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1550|      0|		pin->pad_length = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1551|      0|	}
 1552|  1.19k|}
card-oberthur.c:auth_get_serialnr:
 2265|      4|{
 2266|      4|	if (!serial)
  ------------------
  |  Branch (2266:6): [True: 0, False: 4]
  ------------------
 2267|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2268|       |
 2269|      4|	if (card->serialnr.len==0)
  ------------------
  |  Branch (2269:6): [True: 0, False: 4]
  ------------------
 2270|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2271|       |
 2272|      4|	memcpy(serial, &card->serialnr, sizeof(*serial));
 2273|       |
 2274|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2275|      4|}
card-oberthur.c:auth_set_security_env:
  987|    420|{
  988|    420|	struct auth_senv *auth_senv = &((struct auth_private_data *) card->drv_data)->senv;
  989|    420|	struct sc_apdu apdu;
  990|    420|	long unsigned pads = env->algorithm_flags & SC_ALGORITHM_RSA_PADS;
  ------------------
  |  |  112|    420|#define SC_ALGORITHM_RSA_PADS		0x000000FF
  ------------------
  991|    420|	long unsigned supported_pads = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_PAD_ISO9796;
  ------------------
  |  |  120|    420|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    420|#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) */
  |  |  ------------------
  |  |  |  |  119|    420|#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;
  ------------------
  |  |  115|    420|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  992|    420|	int rv;
  993|    420|	unsigned char rsa_sbuf[3] = {
  994|    420|		0x80, 0x01, 0xFF
  995|    420|	};
  996|    420|	unsigned char des_sbuf[13] = {
  997|    420|		0x80, 0x01, 0x01,
  998|    420|		0x87, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  999|    420|	};
 1000|       |
 1001|    420|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    420|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    420|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    420|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    420|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 420]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1002|    420|	sc_log(card->ctx,
  ------------------
  |  |   71|    420|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1003|    420|	       "op %i; path %s; key_ref 0x%X; algos 0x%lX; flags 0x%lX",
 1004|    420|	       env->operation, sc_print_path(&env->file_ref), env->key_ref[0],
 1005|    420|	       env->algorithm_flags, env->flags);
 1006|       |
 1007|    420|	memset(auth_senv, 0, sizeof(struct auth_senv));
 1008|       |
 1009|    420|	if (!(env->flags & SC_SEC_ENV_FILE_REF_PRESENT))
  ------------------
  |  |   66|    420|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1009:6): [True: 0, False: 420]
  ------------------
 1010|    420|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1011|       |
 1012|    420|	switch (env->algorithm) {
 1013|      0|	case SC_ALGORITHM_DES:
  ------------------
  |  |   85|      0|#define SC_ALGORITHM_DES		64
  ------------------
  |  Branch (1013:2): [True: 0, False: 420]
  ------------------
 1014|      0|	case SC_ALGORITHM_3DES:
  ------------------
  |  |   86|      0|#define SC_ALGORITHM_3DES		65
  ------------------
  |  Branch (1014:2): [True: 0, False: 420]
  ------------------
 1015|      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__
  |  |  ------------------
  ------------------
 1016|      0|		       "algo SC_ALGORITHM_xDES: ref %lX, flags %lX",
 1017|      0|		       env->algorithm_ref, env->flags);
 1018|       |
 1019|      0|		if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   56|      0|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1019:7): [True: 0, False: 0]
  ------------------
 1020|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB8);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1021|      0|			apdu.lc = 3;
 1022|      0|			apdu.data = des_sbuf;
 1023|      0|			apdu.datalen = 3;
 1024|      0|		} else {
 1025|      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__
  |  |  ------------------
  ------------------
 1026|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1027|      0|		}
 1028|       |
 1029|      0|		break;
 1030|    420|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|    420|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1030:2): [True: 420, False: 0]
  ------------------
 1031|    420|		sc_log(card->ctx, "algo SC_ALGORITHM_RSA");
  ------------------
  |  |   71|    420|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1032|    420|		if (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES) {
  ------------------
  |  |  151|    420|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1032:7): [True: 0, False: 420]
  ------------------
 1033|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1034|      0|		}
 1035|       |
 1036|    420|		if (pads & (~supported_pads)) {
  ------------------
  |  Branch (1036:7): [True: 0, False: 420]
  ------------------
 1037|      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__
  |  |  ------------------
  ------------------
 1038|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1039|      0|		}
 1040|       |
 1041|    420|		if (env->operation == SC_SEC_OPERATION_SIGN) {
  ------------------
  |  |   57|    420|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1041:7): [True: 245, False: 175]
  ------------------
 1042|    245|			rsa_sbuf[2] = 0x11;
 1043|       |
 1044|    245|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB6);
  ------------------
  |  |  293|    245|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1045|    245|			apdu.lc = sizeof(rsa_sbuf);
 1046|    245|			apdu.datalen = sizeof(rsa_sbuf);
 1047|    245|			apdu.data = rsa_sbuf;
 1048|    245|		} else if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   56|    175|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1048:14): [True: 175, False: 0]
  ------------------
 1049|    175|			rsa_sbuf[2] = 0x11;
 1050|       |
 1051|    175|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0xB8);
  ------------------
  |  |  293|    175|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1052|    175|			apdu.lc = sizeof(rsa_sbuf);
 1053|    175|			apdu.datalen = sizeof(rsa_sbuf);
 1054|    175|			apdu.data = rsa_sbuf;
 1055|    175|		} else {
 1056|      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__
  |  |  ------------------
  ------------------
 1057|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1058|      0|		}
 1059|       |
 1060|    420|		break;
 1061|    420|	default:
  ------------------
  |  Branch (1061:2): [True: 0, False: 420]
  ------------------
 1062|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1063|    420|	}
 1064|       |
 1065|    420|	rv = sc_transmit_apdu(card, &apdu);
 1066|    420|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|    420|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    420|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    420|	int _ret = (r); \
  |  |  |  |  168|    420|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 409]
  |  |  |  |  ------------------
  |  |  |  |  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|    420|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 409]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1067|    409|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1068|    409|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|    409|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    409|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    409|	int _ret = (r); \
  |  |  |  |  168|    409|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 114, False: 295]
  |  |  |  |  ------------------
  |  |  |  |  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|    409|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 295]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1069|       |
 1070|    295|	auth_senv->algorithm = env->algorithm;
 1071|       |
 1072|    295|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 295]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1073|    295|}
card-oberthur.c:auth_compute_signature:
 1086|    154|{
 1087|    154|	struct sc_apdu apdu;
 1088|    154|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1089|    154|	int rv;
 1090|       |
 1091|    154|	if (!card || !in || !out) {
  ------------------
  |  Branch (1091:6): [True: 0, False: 154]
  |  Branch (1091:15): [True: 0, False: 154]
  |  Branch (1091:22): [True: 0, False: 154]
  ------------------
 1092|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1093|    154|	} else if (ilen > 96) {
  ------------------
  |  Branch (1093:13): [True: 62, False: 92]
  ------------------
 1094|     62|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1095|     62|		       "Illegal input length %"SC_FORMAT_LEN_SIZE_T"u",
 1096|     62|		       ilen);
 1097|     62|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Illegal input length");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1098|     62|	}
 1099|       |
 1100|     92|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     92|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     92|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     92|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     92|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 92]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|     92|	sc_log(card->ctx,
  ------------------
  |  |   71|     92|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1102|     92|	       "inlen %"SC_FORMAT_LEN_SIZE_T"u, outlen %"SC_FORMAT_LEN_SIZE_T"u",
 1103|     92|	       ilen, olen);
 1104|       |
 1105|     92|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  294|     92|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1106|     92|	apdu.datalen = ilen;
 1107|     92|	apdu.data = in;
 1108|     92|	apdu.lc = ilen;
 1109|     92|	apdu.le = MIN(olen, SC_MAX_APDU_RESP_SIZE);
  ------------------
  |  |   70|     92|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, False: 92]
  |  |  ------------------
  ------------------
 1110|     92|	apdu.resp = resp;
 1111|     92|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     92|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1112|       |
 1113|     92|	rv = sc_transmit_apdu(card, &apdu);
 1114|     92|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     92|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     92|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     92|	int _ret = (r); \
  |  |  |  |  168|     92|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 20, False: 72]
  |  |  |  |  ------------------
  |  |  |  |  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|     92|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 72]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|     72|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1116|     72|	LOG_TEST_RET(card->ctx, rv, "Compute signature failed");
  ------------------
  |  |  174|     72|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     72|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     72|	int _ret = (r); \
  |  |  |  |  168|     72|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 56]
  |  |  |  |  ------------------
  |  |  |  |  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|     72|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 56]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1117|       |
 1118|     56|	if (apdu.resplen > olen) {
  ------------------
  |  Branch (1118:6): [True: 0, False: 56]
  ------------------
 1119|      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__
  |  |  ------------------
  ------------------
 1120|      0|		       "Compute signature failed: invalid response length %"SC_FORMAT_LEN_SIZE_T"u",
 1121|      0|		       apdu.resplen);
 1122|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1123|      0|	}
 1124|       |
 1125|     56|	memcpy(out, apdu.resp, apdu.resplen);
 1126|       |
 1127|     56|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 21, False: 35]
  |  |  |  |  ------------------
  |  |  |  |  156|     21|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  157|     21|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     35|	} else { \
  |  |  |  |  159|     35|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     35|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     35|	} \
  |  |  |  |  162|     56|	return _ret; \
  |  |  |  |  163|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1128|     56|}
card-oberthur.c:auth_decipher:
 1134|    141|{
 1135|    141|	struct sc_apdu apdu;
 1136|    141|	unsigned char resp[SC_MAX_APDU_BUFFER_SIZE];
 1137|    141|	int rv;
 1138|    141|	size_t _inlen = inlen;
 1139|       |
 1140|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1141|    141|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1142|    141|	       "crgram_len %"SC_FORMAT_LEN_SIZE_T"u;  outlen %"SC_FORMAT_LEN_SIZE_T"u",
 1143|    141|	       inlen, outlen);
 1144|    141|	if (!out || !outlen || inlen > SC_MAX_APDU_BUFFER_SIZE)
  ------------------
  |  |   34|    141|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
  |  Branch (1144:6): [True: 0, False: 141]
  |  Branch (1144:14): [True: 0, False: 141]
  |  Branch (1144:25): [True: 10, False: 131]
  ------------------
 1145|    141|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|       |
 1147|    131|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|    131|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
 1148|       |
 1149|    131|	sc_log(card->ctx, "algorithm SC_ALGORITHM_RSA");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1150|    131|	if (inlen % 64) {
  ------------------
  |  Branch (1150:6): [True: 48, False: 83]
  ------------------
 1151|     48|		rv = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     48|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1152|     48|		goto done;
 1153|     48|	}
 1154|       |
 1155|     83|	_inlen = inlen;
 1156|     83|	if (_inlen == SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|     83|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (1156:6): [True: 44, False: 39]
  ------------------
 1157|     44|		apdu.cla |= 0x10;
 1158|     44|		apdu.data = in;
 1159|     44|		apdu.datalen = 8;
 1160|     44|		apdu.resp = resp;
 1161|     44|		apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     44|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1162|     44|		apdu.lc = 8;
 1163|     44|		apdu.le = SC_MAX_APDU_RESP_SIZE;
  ------------------
  |  |   36|     44|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
 1164|       |
 1165|     44|		rv = sc_transmit_apdu(card, &apdu);
 1166|     44|		sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   71|     44|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1167|     44|		LOG_TEST_RET(card->ctx, rv, "APDU transmit 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: 14, False: 30]
  |  |  |  |  ------------------
  |  |  |  |  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|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 30]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1168|     30|		rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1169|     30|		LOG_TEST_RET(card->ctx, rv, "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: 8, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  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|     30|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1170|       |
 1171|     22|		_inlen -= 8;
 1172|     22|		in += 8;
 1173|       |
 1174|     22|		apdu.cla &= ~0x10;
 1175|     22|	}
 1176|       |
 1177|     61|	apdu.data = in;
 1178|     61|	apdu.datalen = _inlen;
 1179|     61|	apdu.resp = resp;
 1180|     61|	apdu.resplen = SC_MAX_APDU_BUFFER_SIZE;
  ------------------
  |  |   34|     61|#define SC_MAX_APDU_BUFFER_SIZE		261 /* takes account of: CLA INS P1 P2 Lc [255 byte of data] Le */
  ------------------
 1181|     61|	apdu.lc = _inlen;
 1182|     61|	apdu.le = _inlen;
 1183|       |
 1184|     61|	rv = sc_transmit_apdu(card, &apdu);
 1185|     61|	sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1186|     61|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|     61|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     61|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     61|	int _ret = (r); \
  |  |  |  |  168|     61|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1187|     43|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1188|     43|	sc_log(card->ctx, "rv %i", rv);
  ------------------
  |  |   71|     43|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1189|     43|	LOG_TEST_RET(card->ctx, rv, "Card returned error");
  ------------------
  |  |  174|     43|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     43|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     43|	int _ret = (r); \
  |  |  |  |  168|     43|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 11, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  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|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1190|       |
 1191|     32|	if (outlen > apdu.resplen)
  ------------------
  |  Branch (1191:6): [True: 32, False: 0]
  ------------------
 1192|     32|		outlen = apdu.resplen;
 1193|       |
 1194|     32|	memcpy(out, apdu.resp, outlen);
 1195|     32|	rv = (int)outlen;
 1196|       |
 1197|     80|done:
 1198|     80|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|     80|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     80|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     80|	int _ret = r; \
  |  |  |  |  155|     80|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 59, False: 21]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 48, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  157|     59|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     59|	} 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|     80|	return _ret; \
  |  |  |  |  163|     80|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1199|     80|}
card-oberthur.c:auth_process_fci:
  297|  6.45k|{
  298|  6.45k|	unsigned char type;
  299|  6.45k|	const unsigned char *attr;
  300|  6.45k|	size_t attr_len = 0;
  301|       |
  302|  6.45k|	LOG_FUNC_CALLED(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  303|  6.45k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  304|  6.45k|	if (!attr || attr_len < 1)
  ------------------
  |  Branch (304:6): [True: 3.46k, False: 2.99k]
  |  Branch (304:15): [True: 16, False: 2.98k]
  ------------------
  305|  6.45k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  3.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.47k|	int _ret = r; \
  |  |  |  |  155|  3.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.47k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.47k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.47k|	return _ret; \
  |  |  |  |  163|  3.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  306|  2.98k|	type = attr[0];
  307|       |
  308|  2.98k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x83, &attr_len);
  309|  2.98k|	if (!attr || attr_len < 2)
  ------------------
  |  Branch (309:6): [True: 144, False: 2.83k]
  |  Branch (309:15): [True: 10, False: 2.82k]
  ------------------
  310|  2.98k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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|    154|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 154, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  311|  2.82k|	file->id = attr[0]*0x100 + attr[1];
  312|       |
  313|  2.82k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, type==0x01 ? 0x80 : 0x85, &attr_len);
  ------------------
  |  Branch (313:50): [True: 267, False: 2.55k]
  ------------------
  314|  2.82k|	switch (type) {
  315|    267|	case 0x01:
  ------------------
  |  Branch (315:2): [True: 267, False: 2.55k]
  ------------------
  316|    267|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (316:7): [True: 47, False: 220]
  |  Branch (316:16): [True: 10, False: 210]
  ------------------
  317|    267|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     57|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     57|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     57|	int _ret = r; \
  |  |  |  |  155|     57|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     57|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     57|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 57, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     57|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     57|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     57|	return _ret; \
  |  |  |  |  163|     57|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  318|    210|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    210|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  319|    210|		file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|    210|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  320|    210|		file->size = attr[0]*0x100 + attr[1];
  321|    210|		break;
  322|  1.94k|	case 0x04:
  ------------------
  |  Branch (322:2): [True: 1.94k, False: 884]
  ------------------
  323|  1.94k|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (323:7): [True: 325, False: 1.61k]
  |  Branch (323:16): [True: 10, False: 1.60k]
  ------------------
  324|  1.94k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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: 335, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    335|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    335|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 335, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    335|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    335|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    335|	return _ret; \
  |  |  |  |  163|    335|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  325|  1.60k|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.60k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  326|  1.60k|		file->ef_structure = SC_FILE_EF_LINEAR_VARIABLE;
  ------------------
  |  |  224|  1.60k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  327|  1.60k|		file->size = attr[0];
  328|  1.60k|		attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &attr_len);
  329|  1.60k|		if (!attr || attr_len < 5)
  ------------------
  |  Branch (329:7): [True: 0, False: 1.60k]
  |  Branch (329:16): [True: 10, False: 1.59k]
  ------------------
  330|  1.60k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  331|  1.59k|		file->record_length = attr[2]*0x100+attr[3];
  332|  1.59k|		file->record_count = attr[4];
  333|  1.59k|		break;
  334|     58|	case 0x11:
  ------------------
  |  Branch (334:2): [True: 58, False: 2.76k]
  ------------------
  335|     58|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (335:7): [True: 16, False: 42]
  |  Branch (335:16): [True: 10, False: 32]
  ------------------
  336|     58|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     26|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     26|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     26|	int _ret = r; \
  |  |  |  |  155|     26|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     26|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     26|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 26, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     26|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     26|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  337|     32|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     32|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  338|     32|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_DES;
  339|     32|		file->size = attr[0]*0x100 + attr[1];
  340|     32|		file->size /= 8;
  341|     32|		break;
  342|    145|	case 0x12:
  ------------------
  |  Branch (342:2): [True: 145, False: 2.68k]
  ------------------
  343|    145|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (343:7): [True: 10, False: 135]
  |  Branch (343:16): [True: 6, False: 129]
  ------------------
  344|    145|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  345|    129|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    129|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  346|    129|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC;
  347|       |
  348|    129|		file->size = attr[0]*0x100 + attr[1];
  349|    129|		if (file->size==512)
  ------------------
  |  Branch (349:7): [True: 10, False: 119]
  ------------------
  350|     10|			file->size = PUBKEY_512_ASN1_SIZE;
  ------------------
  |  |  100|     10|#define PUBKEY_512_ASN1_SIZE	0x4A
  ------------------
  351|    119|		else if (file->size==1024)
  ------------------
  |  Branch (351:12): [True: 32, False: 87]
  ------------------
  352|     32|			file->size = PUBKEY_1024_ASN1_SIZE;
  ------------------
  |  |  101|     32|#define PUBKEY_1024_ASN1_SIZE	0x8C
  ------------------
  353|     87|		else if (file->size==2048)
  ------------------
  |  Branch (353:12): [True: 0, False: 87]
  ------------------
  354|      0|			file->size = PUBKEY_2048_ASN1_SIZE;
  ------------------
  |  |  102|      0|#define PUBKEY_2048_ASN1_SIZE	0x10E
  ------------------
  355|     87|		else {
  356|     87|			sc_log(card->ctx,
  ------------------
  |  |   71|     87|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  357|     87|			       "Not supported public key size: %"SC_FORMAT_LEN_SIZE_T"u",
  358|     87|			       file->size);
  359|     87|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     87|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     87|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     87|	int _ret = r; \
  |  |  |  |  155|     87|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 87, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     87|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  360|     87|		}
  361|     42|		break;
  362|     42|	case 0x14:
  ------------------
  |  Branch (362:2): [True: 30, False: 2.79k]
  ------------------
  363|     30|		if (!attr || attr_len < 2)
  ------------------
  |  Branch (363:7): [True: 10, False: 20]
  |  Branch (363:16): [True: 10, False: 10]
  ------------------
  364|     30|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     20|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     20|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     20|	int _ret = r; \
  |  |  |  |  155|     20|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     20|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     20|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 20, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     20|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     20|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     20|	return _ret; \
  |  |  |  |  163|     20|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  365|     10|		file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|     10|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  366|     10|		file->ef_structure = SC_CARDCTL_OBERTHUR_KEY_RSA_CRT;
  367|     10|		file->size = attr[0]*0x100 + attr[1];
  368|     10|		break;
  369|    307|	case 0x38:
  ------------------
  |  Branch (369:2): [True: 307, False: 2.51k]
  ------------------
  370|    307|		if (!attr || attr_len < 1)
  ------------------
  |  Branch (370:7): [True: 11, False: 296]
  |  Branch (370:16): [True: 10, False: 286]
  ------------------
  371|    307|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  372|    286|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    286|#define SC_FILE_TYPE_DF			0x04
  ------------------
  373|    286|		file->size = attr[0];
  374|    286|		if (SC_SUCCESS != sc_file_set_type_attr(file,attr,attr_len))
  ------------------
  |  |   28|    286|#define SC_SUCCESS				0
  ------------------
  |  Branch (374:7): [True: 0, False: 286]
  ------------------
  375|    286|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|    286|		break;
  377|    286|	default:
  ------------------
  |  Branch (377:2): [True: 77, False: 2.74k]
  ------------------
  378|     77|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|     77|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     77|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     77|	int _ret = r; \
  |  |  |  |  155|     77|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 77, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     77|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     77|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 77, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     77|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     77|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     77|	return _ret; \
  |  |  |  |  163|     77|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  379|  2.82k|	}
  380|       |
  381|  2.17k|	attr = sc_asn1_find_tag(card->ctx, buf, buflen, 0x86, &attr_len);
  382|  2.17k|	if (!attr || attr_len < 8)
  ------------------
  |  Branch (382:6): [True: 1.77k, False: 404]
  |  Branch (382:15): [True: 20, False: 384]
  ------------------
  383|  2.17k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|  1.79k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.79k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.79k|	int _ret = r; \
  |  |  |  |  155|  1.79k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.79k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.79k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.79k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.79k|	return _ret; \
  |  |  |  |  163|  1.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  384|       |
  385|    384|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|    384|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (385:6): [True: 255, False: 129]
  ------------------
  386|    255|		add_acl_entry(card, file, SC_AC_OP_CREATE, attr[0]);
  ------------------
  |  |  169|    255|#define SC_AC_OP_CREATE			3
  ------------------
  387|    255|		add_acl_entry(card, file, SC_AC_OP_CRYPTO, attr[1]);
  ------------------
  |  |  173|    255|#define SC_AC_OP_CRYPTO			7
  ------------------
  388|    255|		add_acl_entry(card, file, SC_AC_OP_LIST_FILES, attr[2]);
  ------------------
  |  |  172|    255|#define SC_AC_OP_LIST_FILES		6
  ------------------
  389|    255|		add_acl_entry(card, file, SC_AC_OP_DELETE, attr[3]);
  ------------------
  |  |  168|    255|#define SC_AC_OP_DELETE			2
  ------------------
  390|    255|		add_acl_entry(card, file, SC_AC_OP_PIN_DEFINE, attr[4]);
  ------------------
  |  |  183|    255|#define SC_AC_OP_PIN_DEFINE		17
  ------------------
  391|    255|		add_acl_entry(card, file, SC_AC_OP_PIN_CHANGE, attr[5]);
  ------------------
  |  |  184|    255|#define SC_AC_OP_PIN_CHANGE		18
  ------------------
  392|    255|		add_acl_entry(card, file, SC_AC_OP_PIN_RESET, attr[6]);
  ------------------
  |  |  185|    255|#define SC_AC_OP_PIN_RESET		19
  ------------------
  393|    255|		sc_log(card->ctx, "SC_FILE_TYPE_DF:CRYPTO %X", attr[1]);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  394|    255|	} else if (file->type == SC_FILE_TYPE_INTERNAL_EF) { /* EF */
  ------------------
  |  |  215|    129|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (394:13): [True: 70, False: 59]
  ------------------
  395|     70|		switch (file->ef_structure) {
  ------------------
  |  Branch (395:11): [True: 70, False: 0]
  ------------------
  396|     32|		case SC_CARDCTL_OBERTHUR_KEY_DES:
  ------------------
  |  Branch (396:3): [True: 32, False: 38]
  ------------------
  397|     32|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     32|#define SC_AC_OP_UPDATE			23
  ------------------
  398|     32|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     32|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  399|     32|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     32|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  400|     32|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_CHECKSUM, attr[3]);
  ------------------
  |  |  179|     32|#define SC_AC_OP_PSO_COMPUTE_CHECKSUM	13
  ------------------
  401|     32|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_CHECKSUM, attr[4]);
  ------------------
  |  |  180|     32|#define SC_AC_OP_PSO_VERIFY_CHECKSUM	14
  ------------------
  402|     32|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     32|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  403|     32|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     32|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  404|     32|			break;
  405|     28|		case SC_CARDCTL_OBERTHUR_KEY_RSA_PUBLIC:
  ------------------
  |  Branch (405:3): [True: 28, False: 42]
  ------------------
  406|     28|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     28|#define SC_AC_OP_UPDATE			23
  ------------------
  407|     28|			add_acl_entry(card, file, SC_AC_OP_PSO_ENCRYPT, attr[2]);
  ------------------
  |  |  176|     28|#define SC_AC_OP_PSO_ENCRYPT		10
  ------------------
  408|     28|			add_acl_entry(card, file, SC_AC_OP_PSO_VERIFY_SIGNATURE, attr[4]);
  ------------------
  |  |  178|     28|#define SC_AC_OP_PSO_VERIFY_SIGNATURE	12
  ------------------
  409|     28|			add_acl_entry(card, file, SC_AC_OP_EXTERNAL_AUTHENTICATE, attr[6]);
  ------------------
  |  |  182|     28|#define SC_AC_OP_EXTERNAL_AUTHENTICATE	16
  ------------------
  410|     28|			break;
  411|     10|		case SC_CARDCTL_OBERTHUR_KEY_RSA_CRT:
  ------------------
  |  Branch (411:3): [True: 10, False: 60]
  ------------------
  412|     10|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[0]);
  ------------------
  |  |  189|     10|#define SC_AC_OP_UPDATE			23
  ------------------
  413|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_DECRYPT, attr[1]);
  ------------------
  |  |  175|     10|#define SC_AC_OP_PSO_DECRYPT		9
  ------------------
  414|     10|			add_acl_entry(card, file, SC_AC_OP_PSO_COMPUTE_SIGNATURE, attr[3]);
  ------------------
  |  |  177|     10|#define SC_AC_OP_PSO_COMPUTE_SIGNATURE	11
  ------------------
  415|     10|			add_acl_entry(card, file, SC_AC_OP_INTERNAL_AUTHENTICATE, attr[5]);
  ------------------
  |  |  181|     10|#define SC_AC_OP_INTERNAL_AUTHENTICATE	15
  ------------------
  416|     10|			break;
  417|     70|		}
  418|     70|	} else {
  419|     59|		switch (file->ef_structure) {
  ------------------
  |  Branch (419:11): [True: 59, False: 0]
  ------------------
  420|     46|		case SC_FILE_EF_TRANSPARENT:
  ------------------
  |  |  221|     46|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
  |  Branch (420:3): [True: 46, False: 13]
  ------------------
  421|     46|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     46|#define SC_AC_OP_WRITE			24
  ------------------
  422|     46|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     46|#define SC_AC_OP_UPDATE			23
  ------------------
  423|     46|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     46|#define SC_AC_OP_READ			22
  ------------------
  424|     46|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     46|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     46|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  425|     46|			break;
  426|     13|		case SC_FILE_EF_LINEAR_VARIABLE:
  ------------------
  |  |  224|     13|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (426:3): [True: 13, False: 46]
  ------------------
  427|     13|			add_acl_entry(card, file, SC_AC_OP_WRITE, attr[0]);
  ------------------
  |  |  190|     13|#define SC_AC_OP_WRITE			24
  ------------------
  428|     13|			add_acl_entry(card, file, SC_AC_OP_UPDATE, attr[1]);
  ------------------
  |  |  189|     13|#define SC_AC_OP_UPDATE			23
  ------------------
  429|     13|			add_acl_entry(card, file, SC_AC_OP_READ, attr[2]);
  ------------------
  |  |  188|     13|#define SC_AC_OP_READ			22
  ------------------
  430|     13|			add_acl_entry(card, file, SC_AC_OP_ERASE, attr[3]);
  ------------------
  |  |  202|     13|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     13|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  431|     13|			break;
  432|     59|		}
  433|     59|	}
  434|       |
  435|    384|	file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    384|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  436|    384|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|    384|#define SC_FILE_MAGIC			0x14426950
  ------------------
  437|       |
  438|    384|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    384|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    384|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    384|	int _ret = r; \
  |  |  |  |  155|    384|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 384, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    384|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 384]
  |  |  |  |  ------------------
  |  |  |  |  157|    384|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    384|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    384|	return _ret; \
  |  |  |  |  163|    384|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  439|    384|}
card-oberthur.c:add_acl_entry:
  260|  2.39k|{
  261|  2.39k|	if ((acl_byte & 0xE0) == 0x60) {
  ------------------
  |  Branch (261:6): [True: 692, False: 1.70k]
  ------------------
  262|    692|		sc_log(card->ctx, "called; op 0x%X; SC_AC_PRO; ref 0x%X", op, acl_byte);
  ------------------
  |  |   71|    692|#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|    692|		sc_file_add_acl_entry(file, op, SC_AC_PRO, acl_byte);
  ------------------
  |  |  153|    692|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  264|    692|		return;
  265|    692|	}
  266|       |
  267|  1.70k|	switch (acl_byte) {
  268|    431|	case 0x00:
  ------------------
  |  Branch (268:2): [True: 431, False: 1.27k]
  ------------------
  269|    431|		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|    431|#define SC_AC_NONE			0x00000000
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    431|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  270|    431|		break;
  271|       |	/* User and OneTime PINs are locals */
  272|     44|	case 0x21:
  ------------------
  |  Branch (272:2): [True: 44, False: 1.66k]
  ------------------
  273|     83|	case 0x22:
  ------------------
  |  Branch (273:2): [True: 39, False: 1.66k]
  ------------------
  274|     83|		sc_file_add_acl_entry(file, op, SC_AC_CHV, (acl_byte & 0x0F) | OBERTHUR_PIN_LOCAL);
  ------------------
  |  |  151|     83|#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|     83|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
  275|     83|		break;
  276|       |	/* Local SOPIN is only for the unblocking. */
  277|    200|	case 0x24:
  ------------------
  |  Branch (277:2): [True: 200, False: 1.50k]
  ------------------
  278|    302|	case 0x25:
  ------------------
  |  Branch (278:2): [True: 102, False: 1.60k]
  ------------------
  279|    302|		if (op == SC_AC_OP_PIN_RESET)
  ------------------
  |  |  185|    302|#define SC_AC_OP_PIN_RESET		19
  ------------------
  |  Branch (279:7): [True: 43, False: 259]
  ------------------
  280|     43|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x84);
  ------------------
  |  |  151|     43|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  281|    259|		else
  282|    259|			sc_file_add_acl_entry(file, op, SC_AC_CHV, 0x04);
  ------------------
  |  |  151|    259|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  283|    302|		break;
  284|    250|	case 0xFF:
  ------------------
  |  Branch (284:2): [True: 250, False: 1.45k]
  ------------------
  285|    250|		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  163|    250|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_NEVER, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    250|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  286|    250|		break;
  287|    639|	default:
  ------------------
  |  Branch (287:2): [True: 639, False: 1.06k]
  ------------------
  288|    639|		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  162|    639|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		sc_file_add_acl_entry(file, op, SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|    639|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  289|    639|		break;
  290|  1.70k|	}
  291|  1.70k|}
card-oberthur.c:auth_pin_cmd:
 1895|  1.32k|{
 1896|  1.32k|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.32k|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1897|       |
 1898|  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1899|  1.32k|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|  1.32k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1899:6): [True: 0, False: 1.32k]
  ------------------
 1900|  1.32k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1901|       |
 1902|  1.32k|	sc_log(card->ctx, "PIN CMD:%i; reference:%i; pin1:%p/%zu, pin2:%p/%zu", data->cmd,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1903|  1.32k|			data->pin_reference, data->pin1.data, data->pin1.len,
 1904|  1.32k|			data->pin2.data, data->pin2.len);
 1905|  1.32k|	switch (data->cmd) {
 1906|  1.17k|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|  1.17k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1906:2): [True: 1.17k, False: 151]
  ------------------
 1907|  1.17k|		rv = auth_pin_verify(card, SC_AC_CHV, data, tries_left);
  ------------------
  |  |  151|  1.17k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1908|  1.17k|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN VERIFY' failed");
  ------------------
  |  |  174|  1.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.17k|	int _ret = (r); \
  |  |  |  |  168|  1.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 88, False: 1.08k]
  |  |  |  |  ------------------
  |  |  |  |  169|     88|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     88|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     88|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     88|		return _ret; \
  |  |  |  |  172|     88|	} \
  |  |  |  |  173|  1.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.08k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1909|  1.08k|		break;
 1910|  1.08k|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|     10|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1910:2): [True: 10, False: 1.31k]
  ------------------
 1911|     10|		rv = auth_pin_change(card, SC_AC_CHV, data, tries_left);
  ------------------
  |  |  151|     10|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1912|     10|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN 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: 6, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1913|      4|		break;
 1914|     10|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|     10|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1914:2): [True: 10, False: 1.31k]
  ------------------
 1915|     10|		rv = auth_pin_reset(card, SC_AC_CHV, data, tries_left);
  ------------------
  |  |  151|     10|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1916|     10|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN 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: 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1917|      0|		break;
 1918|    131|	default:
  ------------------
  |  Branch (1918:2): [True: 131, False: 1.19k]
  ------------------
 1919|    131|		LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "Unsupported PIN operation");
  ------------------
  |  |  174|    131|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    131|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    131|	int _ret = (r); \
  |  |  |  |  168|    131|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 131, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    131|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    131|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    131|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    131|		return _ret; \
  |  |  |  |  172|    131|	} \
  |  |  |  |  173|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1920|  1.32k|	}
 1921|       |
 1922|  1.09k|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1923|  1.09k|}
card-oberthur.c:auth_pin_verify:
 1614|  1.17k|{
 1615|  1.17k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1616|  1.17k|	int rv;
 1617|       |
 1618|  1.17k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.17k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.17k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.17k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.17k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|  1.17k|	if (type != SC_AC_CHV)
  ------------------
  |  |  151|  1.17k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1620:6): [True: 0, False: 1.17k]
  ------------------
 1621|  1.17k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  1.17k|	data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|  1.17k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1624|       |
 1625|  1.17k|	auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|  1.17k|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1626|       |
 1627|       |	/* User PIN is always local. */
 1628|  1.17k|	if (data->pin_reference == OBERTHUR_PIN_REFERENCE_USER
  ------------------
  |  |   42|  2.35k|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1628:6): [True: 530, False: 647]
  ------------------
 1629|    647|			|| data->pin_reference == OBERTHUR_PIN_REFERENCE_ONETIME)
  ------------------
  |  |   43|    647|#define OBERTHUR_PIN_REFERENCE_ONETIME	0x82
  ------------------
  |  Branch (1629:7): [True: 0, False: 647]
  ------------------
 1630|    530|		data->pin_reference  |= OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|    530|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1631|       |
 1632|  1.17k|        rv = auth_pin_is_verified(card, data->pin_reference, tries_left);
 1633|  1.17k|    	sc_log(card->ctx, "auth_pin_is_verified returned rv %i", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1634|       |
 1635|       |	/* Return if only PIN status has been asked. */
 1636|  1.17k|	if (data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1636:6): [True: 1.17k, False: 0]
  |  Branch (1636:25): [True: 1.10k, False: 69]
  ------------------
 1637|  1.17k|		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|     65|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 65, False: 1.04k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1638|       |
 1639|       |	/* Return SUCCESS without verifying if
 1640|       |	 * PIN has been already verified and PIN pad has to be used. */
 1641|     69|	if (!rv && !data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1641:6): [True: 41, False: 28]
  |  Branch (1641:13): [True: 0, False: 41]
  |  Branch (1641:33): [True: 0, False: 0]
  ------------------
 1642|     69|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1643|       |
 1644|     69|	if (!data->pin1.data && !data->pin1.len)
  ------------------
  |  Branch (1644:6): [True: 0, False: 69]
  |  Branch (1644:26): [True: 0, False: 0]
  ------------------
 1645|      0|		rv = auth_pin_verify_pinpad(card, data->pin_reference, tries_left);
 1646|     69|	else
 1647|     69|		rv = iso_drv->ops->pin_cmd(card, data, tries_left);
 1648|       |
 1649|     69|	LOG_FUNC_RETURN(card->ctx, rv);
  ------------------
  |  |  164|     69|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     69|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     69|	int _ret = r; \
  |  |  |  |  155|     69|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 69, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     69|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     23|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 23, False: 46]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1650|     69|}
card-oberthur.c:auth_pin_is_verified:
 1655|  1.17k|{
 1656|  1.17k|	struct sc_apdu apdu;
 1657|  1.17k|	int rv;
 1658|       |
 1659|  1.17k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, pin_reference);
  ------------------
  |  |  291|  1.17k|#define SC_APDU_CASE_1			0x01
  ------------------
 1660|       |
 1661|  1.17k|	rv = sc_transmit_apdu(card, &apdu);
 1662|  1.17k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  1.17k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.17k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.17k|	int _ret = (r); \
  |  |  |  |  168|  1.17k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 1.17k]
  |  |  |  |  ------------------
  |  |  |  |  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.17k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.17k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1663|       |
 1664|  1.17k|	if (tries_left && apdu.sw1 == 0x63 && (apdu.sw2 & 0xF0) == 0xC0)
  ------------------
  |  Branch (1664:6): [True: 1.17k, False: 0]
  |  Branch (1664:20): [True: 16, False: 1.15k]
  |  Branch (1664:40): [True: 8, False: 8]
  ------------------
 1665|      8|		*tries_left = apdu.sw2 & 0x0F;
 1666|       |
 1667|       |	/* Replace 'no tries left' with 'auth method blocked' */
 1668|  1.17k|	if (apdu.sw1 == 0x63 && apdu.sw2 == 0xC0) {
  ------------------
  |  Branch (1668:6): [True: 16, False: 1.15k]
  |  Branch (1668:26): [True: 1, False: 15]
  ------------------
 1669|      1|		apdu.sw1 = 0x69;
 1670|      1|		apdu.sw2 = 0x83;
 1671|      1|	}
 1672|       |
 1673|  1.17k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1674|       |
 1675|  1.17k|	return rv;
 1676|  1.17k|}
card-oberthur.c:auth_pin_change:
 1739|     10|{
 1740|     10|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1741|     10|	int rv = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     10|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1742|       |
 1743|     10|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     10|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     10|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     10|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     10|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1744|       |
 1745|     10|	if (data->pin1.len && data->pin2.len) {
  ------------------
  |  Branch (1745:6): [True: 10, False: 0]
  |  Branch (1745:24): [True: 10, False: 0]
  ------------------
 1746|       |		/* Direct unblock style */
 1747|     10|		data->flags |= SC_PIN_CMD_NEED_PADDING;
  ------------------
  |  |  429|     10|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
 1748|     10|		data->flags &= ~SC_PIN_CMD_USE_PINPAD;
  ------------------
  |  |  428|     10|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
 1749|     10|		data->apdu = NULL;
 1750|       |
 1751|     10|		data->pin_reference &= ~OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|     10|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1752|       |
 1753|     10|		auth_init_pin_info(card, &data->pin1, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|     10|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1754|     10|		auth_init_pin_info(card, &data->pin2, OBERTHUR_AUTH_TYPE_PIN);
  ------------------
  |  |   92|     10|#define OBERTHUR_AUTH_TYPE_PIN		1
  ------------------
 1755|       |
 1756|     10|		rv = iso_drv->ops->pin_cmd(card, data, tries_left);
 1757|     10|		LOG_TEST_RET(card->ctx, rv, "CMD 'PIN CHANGE' failed");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 6, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  169|      6|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      6|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      6|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      6|		return _ret; \
  |  |  |  |  172|      6|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 4]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1758|     10|	} else if (!data->pin1.len && !data->pin2.len) {
  ------------------
  |  Branch (1758:13): [True: 0, False: 0]
  |  Branch (1758:32): [True: 0, False: 0]
  ------------------
 1759|       |		/* Oberthur unblock style with PIN pad. */
 1760|      0|		rv = auth_pin_change_pinpad(card, data, tries_left);
 1761|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1762|      0|	} else {
 1763|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1764|      0|	}
 1765|       |
 1766|      4|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1767|      4|}
card-oberthur.c:auth_pin_reset:
 1880|     10|{
 1881|     10|	int rv;
 1882|       |
 1883|     10|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     10|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     10|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     10|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     10|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1884|       |
 1885|       |	/* Oberthur unblock style: PUK value is a SOPIN */
 1886|     10|	rv = auth_pin_reset_oberthur_style(card, SC_AC_CHV, data, tries_left);
  ------------------
  |  |  151|     10|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1887|     10|	LOG_TEST_RET(card->ctx, rv, "Oberthur style 'PIN RESET' failed");
  ------------------
  |  |  174|     10|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     10|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     10|	int _ret = (r); \
  |  |  |  |  168|     10|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     10|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     10|		return _ret; \
  |  |  |  |  172|     10|	} \
  |  |  |  |  173|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1888|       |
 1889|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1890|      0|}
card-oberthur.c:auth_pin_reset_oberthur_style:
 1773|     10|{
 1774|     10|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1775|     10|	struct sc_pin_cmd_data pin_cmd;
 1776|     10|	struct sc_path tmp_path;
 1777|     10|	struct sc_file *tmp_file = NULL;
 1778|     10|	struct sc_apdu apdu;
 1779|     10|	unsigned char puk[OBERTHUR_AUTH_MAX_LENGTH_PUK];
 1780|     10|	unsigned char ffs1[0x100];
 1781|     10|	int rv, rvv, local_pin_reference;
 1782|       |
 1783|     10|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     10|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     10|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     10|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     10|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1784|       |
 1785|     10|	local_pin_reference = data->pin_reference & ~OBERTHUR_PIN_LOCAL;
  ------------------
  |  |   41|     10|#define OBERTHUR_PIN_LOCAL	0x80
  ------------------
 1786|       |
 1787|     10|	if (data->pin_reference !=  OBERTHUR_PIN_REFERENCE_USER)
  ------------------
  |  |   42|     10|#define OBERTHUR_PIN_REFERENCE_USER	0x81
  ------------------
  |  Branch (1787:6): [True: 10, False: 0]
  ------------------
 1788|     10|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Oberthur style 'PIN RESET' failed: invalid PIN reference");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1789|       |
 1790|      0|	memset(&pin_cmd, 0, sizeof(pin_cmd));
 1791|      0|	memset(&tmp_path, 0, sizeof(struct sc_path));
 1792|       |
 1793|      0|	pin_cmd.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1794|      0|	pin_cmd.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
 1795|      0|	pin_cmd.pin_reference = OBERTHUR_PIN_REFERENCE_PUK;
  ------------------
  |  |   45|      0|#define OBERTHUR_PIN_REFERENCE_PUK	0x84
  ------------------
 1796|      0|	memcpy(&pin_cmd.pin1, &data->pin1, sizeof(pin_cmd.pin1));
 1797|       |
 1798|      0|	rv = auth_pin_verify(card, SC_AC_CHV, &pin_cmd, tries_left);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1799|      0|	LOG_TEST_RET(card->ctx, rv, "Oberthur style 'PIN RESET' failed: SOPIN verify 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1800|       |
 1801|      0|	sc_format_path("2000", &tmp_path);
 1802|      0|	tmp_path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
 1803|      0|	rv = iso_ops->select_file(card, &tmp_path, &tmp_file);
 1804|      0|	LOG_TEST_RET(card->ctx, rv, "select PUK 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1805|       |
 1806|      0|	if (!tmp_file || tmp_file->size < OBERTHUR_AUTH_MAX_LENGTH_PUK) {
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
  |  Branch (1806:6): [True: 0, False: 0]
  |  Branch (1806:19): [True: 0, False: 0]
  ------------------
 1807|      0|		sc_file_free(tmp_file);
 1808|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_FILE_TOO_SMALL, "Oberthur style 'PIN RESET' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1809|      0|	}
 1810|      0|	sc_file_free(tmp_file);
 1811|       |
 1812|      0|	rv = iso_ops->read_binary(card, 0, puk, OBERTHUR_AUTH_MAX_LENGTH_PUK, 0);
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1813|      0|	LOG_TEST_RET(card->ctx, rv, "read PUK file error");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1814|      0|	if (rv != OBERTHUR_AUTH_MAX_LENGTH_PUK)
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
  |  Branch (1814:6): [True: 0, False: 0]
  ------------------
 1815|      0|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_DATA, "Oberthur style 'PIN RESET' 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1816|       |
 1817|      0|	memset(ffs1, 0xFF, sizeof(ffs1));
 1818|      0|	memcpy(ffs1, puk, rv);
 1819|       |
 1820|      0|	memset(&pin_cmd, 0, sizeof(pin_cmd));
 1821|      0|	pin_cmd.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1822|      0|        pin_cmd.cmd = SC_PIN_CMD_UNBLOCK;
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
 1823|      0|	pin_cmd.pin_reference = local_pin_reference;
 1824|      0|	auth_init_pin_info(card, &pin_cmd.pin1, OBERTHUR_AUTH_TYPE_PUK);
  ------------------
  |  |   93|      0|#define OBERTHUR_AUTH_TYPE_PUK		2
  ------------------
 1825|      0|	pin_cmd.pin1.data = ffs1;
 1826|      0|	pin_cmd.pin1.len = OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1827|       |
 1828|      0|	if (data->pin2.data) {
  ------------------
  |  Branch (1828:6): [True: 0, False: 0]
  ------------------
 1829|      0|		memcpy(&pin_cmd.pin2, &data->pin2, sizeof(pin_cmd.pin2));
 1830|      0|		rv = auth_pin_reset(card, SC_AC_CHV, &pin_cmd, tries_left);
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1831|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1832|      0|	}
 1833|       |
 1834|      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
  ------------------
 1835|      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
  ------------------
 1836|      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
  ------------------
 1837|      0|	apdu.data = ffs1;
 1838|       |
 1839|      0|	pin_cmd.apdu = &apdu;
 1840|      0|	pin_cmd.flags |= SC_PIN_CMD_USE_PINPAD | SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
              	pin_cmd.flags |= SC_PIN_CMD_USE_PINPAD | SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1841|       |
 1842|      0|	pin_cmd.pin1.min_length = 4;
 1843|      0|	pin_cmd.pin1.max_length = 8;
 1844|      0|	pin_cmd.pin1.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1845|      0|	pin_cmd.pin1.offset = 5;
 1846|       |
 1847|      0|	pin_cmd.pin2.data = &ffs1[OBERTHUR_AUTH_MAX_LENGTH_PUK];
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1848|      0|	pin_cmd.pin2.len = OBERTHUR_AUTH_MAX_LENGTH_PIN;
  ------------------
  |  |   95|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PIN	64
  ------------------
 1849|      0|	pin_cmd.pin2.offset = 5 + OBERTHUR_AUTH_MAX_LENGTH_PUK;
  ------------------
  |  |   96|      0|#define OBERTHUR_AUTH_MAX_LENGTH_PUK	16
  ------------------
 1850|      0|	pin_cmd.pin2.min_length = 4;
 1851|      0|	pin_cmd.pin2.max_length = 8;
 1852|      0|	pin_cmd.pin2.encoding = SC_PIN_ENCODING_ASCII;
  ------------------
  |  |  432|      0|#define SC_PIN_ENCODING_ASCII	0
  ------------------
 1853|       |
 1854|      0|	rvv = iso_drv->ops->pin_cmd(card, &pin_cmd, tries_left);
 1855|      0|	if (rvv)
  ------------------
  |  Branch (1855:6): [True: 0, False: 0]
  ------------------
 1856|      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__
  |  |  ------------------
  ------------------
 1857|      0|				"%s: PIN CMD 'VERIFY' with pinpad failed",
 1858|      0|				sc_strerror(rvv));
 1859|       |
 1860|      0|	if (auth_current_ef) {
  ------------------
  |  Branch (1860:6): [True: 0, False: 0]
  ------------------
 1861|      0|		struct sc_file *ef = NULL;
 1862|      0|		rv = iso_ops->select_file(card, &auth_current_ef->path, &ef);
 1863|      0|		if (rv == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1863:7): [True: 0, False: 0]
  ------------------
 1864|      0|			sc_file_free(auth_current_ef);
 1865|      0|			auth_current_ef = ef;
 1866|      0|		} else
 1867|      0|			sc_file_free(ef);
 1868|      0|	}
 1869|       |
 1870|      0|	if (rv > 0)
  ------------------
  |  Branch (1870:6): [True: 0, False: 0]
  ------------------
 1871|      0|		rv = 0;
 1872|       |
 1873|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1874|      0|}
card-oberthur.c:auth_check_sw:
 2288|  30.4k|{
 2289|  30.4k|	int ii;
 2290|       |
 2291|  60.6k|	for (ii = 0; auth_warnings[ii].SWs; ii++) {
  ------------------
  |  Branch (2291:15): [True: 30.4k, False: 30.1k]
  ------------------
 2292|  30.4k|		if (auth_warnings[ii].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (2292:7): [True: 256, False: 30.1k]
  ------------------
 2293|    256|			sc_log(card->ctx, "%s", auth_warnings[ii].errorstr);
  ------------------
  |  |   71|    256|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2294|    256|			return auth_warnings[ii].errorno;
 2295|    256|		}
 2296|  30.4k|	}
 2297|       |
 2298|  30.1k|	return iso_ops->check_sw(card, sw1, sw2);
 2299|  30.4k|}

populate_blobs_to_mf:
  381|    690|{
  382|    690|	pgp_do_info_t	*info;
  383|  40.7k|	for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (383:33): [True: 40.7k, False: 0]
  |  Branch (383:51): [True: 40.0k, False: 690]
  ------------------
  384|  40.0k|		if (((info->access & READ_MASK) != READ_NEVER) && (info->get_fn != NULL)) {
  ------------------
  |  Branch (384:7): [True: 29.3k, False: 10.7k]
  |  Branch (384:53): [True: 13.1k, False: 16.1k]
  ------------------
  385|  13.1k|			pgp_blob_t *child = NULL;
  386|  13.1k|			sc_file_t *file = sc_file_new();
  387|       |
  388|  13.1k|			child = pgp_new_blob(card, priv->mf, info->id, file);
  389|       |
  390|       |			/* catch out of memory condition */
  391|  13.1k|			if (child == NULL) {
  ------------------
  |  Branch (391:8): [True: 0, False: 13.1k]
  ------------------
  392|      0|				sc_file_free(file);
  393|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|      0|			}
  395|  13.1k|		}
  396|  40.0k|	}
  397|    690|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    690|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    690|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    690|	int _ret = r; \
  |  |  |  |  155|    690|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 690, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    690|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 690]
  |  |  |  |  ------------------
  |  |  |  |  157|    690|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    690|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    690|	return _ret; \
  |  |  |  |  163|    690|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  398|    690|}
_pgp_add_algo:
  736|  1.01k|{
  737|  1.01k|	unsigned long flags = 0, ext_flags = 0;
  738|       |
  739|  1.01k|	if (!card || !key_info)
  ------------------
  |  Branch (739:6): [True: 0, False: 1.01k]
  |  Branch (739:15): [True: 0, False: 1.01k]
  ------------------
  740|      0|		return 0;
  741|       |
  742|       |	/* [RFC 4880], [draft-ietf-openpgp-crypto-refresh] */
  743|  1.01k|	switch (key_info->algorithm) {
  744|  1.01k|	case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  869|  1.01k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (744:2): [True: 1.01k, False: 0]
  ------------------
  745|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 /
  746|       |		 * v3.x section 7.2.11 & 7.2.12 */
  747|  1.01k|		flags = SC_ALGORITHM_RSA_PAD_PKCS1 |
  ------------------
  |  |  120|  1.01k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  1.01k|#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) */
  |  |  ------------------
  |  |  |  |  119|  1.01k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  748|  1.01k|			SC_ALGORITHM_RSA_HASH_NONE |
  ------------------
  |  |  142|  1.01k|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  749|  1.01k|			SC_ALGORITHM_ONBOARD_KEY_GEN;	/* key gen on card */
  ------------------
  |  |  102|  1.01k|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  750|       |
  751|  1.01k|		_sc_card_add_rsa_alg(card, key_info->u.rsa.modulus_len, flags, 0);
  752|  1.01k|		sc_log(card->ctx, "DO %uX: Added RSA algorithm, mod_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__
  |  |  ------------------
  ------------------
  753|  1.01k|			SC_FORMAT_LEN_SIZE_T"u",
  754|  1.01k|			do_num, key_info->u.rsa.modulus_len);
  755|  1.01k|		break;
  756|      0|	case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  870|      0|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (756:2): [True: 0, False: 1.01k]
  ------------------
  757|       |		/* The montgomery curve (curve25519) needs to go through
  758|       |		 * different paths, otherwise we handle it as a normal EC key */
  759|      0|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (759:7): [True: 0, False: 0]
  ------------------
  760|      0|			break;
  761|       |		/* fall through */
  762|      0|	case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  871|      0|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (762:2): [True: 0, False: 1.01k]
  ------------------
  763|       |		/* v3.0+: ECC [RFC 4880 & 6637] */
  764|       |
  765|       |		/* Allow curve to be used by both ECDH and ECDSA.
  766|       |		 * pgp_init set these flags the same way */
  767|      0|		flags = SC_ALGORITHM_ECDH_CDH_RAW;
  ------------------
  |  |  182|      0|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  768|      0|		flags |= SC_ALGORITHM_ECDSA_RAW;
  ------------------
  |  |  183|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  769|      0|		flags |= SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|      0|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  770|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  771|      0|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  210|      0|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  772|       |
  773|      0|		_sc_card_add_ec_alg(card, key_info->u.ec.key_length, flags, ext_flags,
  774|      0|			&key_info->u.ec.oid);
  775|      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__
  |  |  ------------------
  ------------------
  776|      0|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  777|      0|		break;
  778|      0|	case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  872|      0|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (778:2): [True: 0, False: 1.01k]
  ------------------
  779|       |		/* EdDSA from draft-ietf-openpgp-rfc4880bis-08 */
  780|       |		/* Handle Yubikey bug, that in DO FA curve25519 has EDDSA algo */
  781|      0|		if (_pgp_handle_curve25519(card, key_info, do_num))
  ------------------
  |  Branch (781:7): [True: 0, False: 0]
  ------------------
  782|      0|			break;
  783|      0|		_sc_card_add_eddsa_alg(card, key_info->u.ec.key_length,
  784|      0|				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  197|      0|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
              				SC_ALGORITHM_EDDSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN, 0, &key_info->u.ec.oid);
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  785|       |
  786|      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__
  |  |  ------------------
  ------------------
  787|      0|			do_num, key_info->algorithm, key_info->u.ec.key_length);
  788|      0|		break;
  789|      0|	default:
  ------------------
  |  Branch (789:2): [True: 0, False: 1.01k]
  ------------------
  790|      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__
  |  |  ------------------
  ------------------
  791|      0|			do_num, key_info->algorithm);
  792|       |		/* return "false" if we do not understand algo */
  793|      0|		return 0;
  794|  1.01k|	}
  795|       |	/* return true */
  796|  1.01k|	return 1;
  797|  1.01k|}
sc_get_openpgp_driver:
 4213|  15.3k|{
 4214|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 4215|       |
 4216|  15.3k|	iso_ops = iso_drv->ops;
 4217|       |
 4218|  15.3k|	pgp_ops = *iso_ops;
 4219|  15.3k|	pgp_ops.match_card	= pgp_match_card;
 4220|  15.3k|	pgp_ops.init		= pgp_init;
 4221|  15.3k|	pgp_ops.finish		= pgp_finish;
 4222|  15.3k|	pgp_ops.select_file	= pgp_select_file;
 4223|  15.3k|	pgp_ops.list_files	= pgp_list_files;
 4224|  15.3k|	pgp_ops.get_challenge	= pgp_get_challenge;
 4225|  15.3k|	pgp_ops.read_binary	= pgp_read_binary;
 4226|  15.3k|	pgp_ops.write_binary	= NULL;
 4227|  15.3k|	pgp_ops.pin_cmd		= pgp_pin_cmd;
 4228|  15.3k|	pgp_ops.logout		= pgp_logout;
 4229|  15.3k|	pgp_ops.get_data	= pgp_get_data;
 4230|  15.3k|	pgp_ops.put_data	= pgp_put_data;
 4231|  15.3k|	pgp_ops.set_security_env= pgp_set_security_env;
 4232|  15.3k|	pgp_ops.compute_signature= pgp_compute_signature;
 4233|  15.3k|	pgp_ops.decipher	= pgp_decipher;
 4234|  15.3k|	pgp_ops.card_ctl	= pgp_card_ctl;
 4235|  15.3k|	pgp_ops.delete_file	= pgp_delete_file;
 4236|  15.3k|	pgp_ops.update_binary	= pgp_update_binary;
 4237|  15.3k|	pgp_ops.card_reader_lock_obtained = pgp_card_reader_lock_obtained;
 4238|       |
 4239|  15.3k|	return &pgp_drv;
 4240|  15.3k|}
card-openpgp.c:pgp_new_blob:
 1237|  43.1k|{
 1238|  43.1k|	pgp_blob_t *blob = NULL;
 1239|       |
 1240|  43.1k|	if (file == NULL)
  ------------------
  |  Branch (1240:6): [True: 0, False: 43.1k]
  ------------------
 1241|      0|		return NULL;
 1242|       |
 1243|  43.1k|	if ((blob = calloc(1, sizeof(pgp_blob_t))) != NULL) {
  ------------------
  |  Branch (1243:6): [True: 43.1k, False: 0]
  ------------------
 1244|  43.1k|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  43.1k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1245|  43.1k|		pgp_do_info_t *info;
 1246|       |
 1247|  43.1k|		blob->file = file;
 1248|       |
 1249|  43.1k|		blob->file->type         = SC_FILE_TYPE_WORKING_EF; /* default */
  ------------------
  |  |  216|  43.1k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
 1250|  43.1k|		blob->file->ef_structure = SC_FILE_EF_TRANSPARENT;
  ------------------
  |  |  221|  43.1k|#define SC_FILE_EF_TRANSPARENT		0x01
  ------------------
 1251|  43.1k|		blob->file->id           = file_id;
 1252|       |
 1253|  43.1k|		blob->id     = file_id;
 1254|  43.1k|		blob->parent = parent;
 1255|       |
 1256|  43.1k|		if (parent != NULL) {
  ------------------
  |  Branch (1256:7): [True: 42.4k, False: 690]
  ------------------
 1257|  42.4k|			pgp_blob_t **p;
 1258|       |
 1259|       |			/* set file's path = parent's path + file's id */
 1260|  42.4k|			blob->file->path = parent->file->path;
 1261|  42.4k|			sc_append_file_id(&blob->file->path, file_id);
 1262|       |
 1263|       |			/* append blob to list of parent's children */
 1264|  6.92M|			for (p = &parent->files; *p != NULL; p = &(*p)->next)
  ------------------
  |  Branch (1264:29): [True: 6.87M, False: 42.4k]
  ------------------
 1265|  6.87M|				;
 1266|  42.4k|			*p = blob;
 1267|  42.4k|		}
 1268|    690|		else {
 1269|    690|			char path[10] = "0000";	/* long enough */
 1270|       |
 1271|       |			/* no parent: set file's path = file's id */
 1272|    690|			if (4 != snprintf(path, sizeof(path), "%04X", file_id & 0xFFFF)) {
  ------------------
  |  Branch (1272:8): [True: 0, False: 690]
  ------------------
 1273|      0|				free(blob);
 1274|      0|				return NULL;
 1275|      0|			}
 1276|       |
 1277|    690|			sc_format_path(path, &blob->file->path);
 1278|    690|		}
 1279|       |
 1280|       |		/* find matching DO info: set file type depending on it */
 1281|  1.69M|		for (info = priv->pgp_objects; (info != NULL) && (info->id > 0); info++) {
  ------------------
  |  Branch (1281:34): [True: 1.69M, False: 0]
  |  Branch (1281:52): [True: 1.68M, False: 11.7k]
  ------------------
 1282|  1.68M|			if (info->id == file_id) {
  ------------------
  |  Branch (1282:8): [True: 31.3k, False: 1.65M]
  ------------------
 1283|  31.3k|				blob->info = info;
 1284|  31.3k|				blob->file->type = blob->info->type;
 1285|  31.3k|				pgp_attach_acl(card, blob->file, info);
 1286|  31.3k|				break;
 1287|  31.3k|			}
 1288|  1.68M|		}
 1289|  43.1k|	}
 1290|       |
 1291|  43.1k|	return blob;
 1292|  43.1k|}
card-openpgp.c:pgp_attach_acl:
 1169|  31.3k|{
 1170|  31.3k|	unsigned int method = SC_AC_NONE;
  ------------------
  |  |  150|  31.3k|#define SC_AC_NONE			0x00000000
  ------------------
 1171|  31.3k|	unsigned long key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  31.3k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1172|       |
 1173|       |	/* Write access */
 1174|  31.3k|	switch (info->access & WRITE_MASK) {
  ------------------
  |  Branch (1174:10): [True: 31.3k, False: 0]
  ------------------
 1175|  9.55k|	case WRITE_NEVER:
  ------------------
  |  Branch (1175:2): [True: 9.55k, False: 21.8k]
  ------------------
 1176|  9.55k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  9.55k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1177|  9.55k|		break;
 1178|      0|	case WRITE_PIN1:
  ------------------
  |  Branch (1178:2): [True: 0, False: 31.3k]
  ------------------
 1179|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1180|      0|		key_ref = 0x01;
 1181|      0|		break;
 1182|  1.38k|	case WRITE_PIN2:
  ------------------
  |  Branch (1182:2): [True: 1.38k, False: 29.9k]
  ------------------
 1183|  1.38k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  1.38k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1184|  1.38k|		key_ref = 0x02;
 1185|  1.38k|		break;
 1186|  20.4k|	case WRITE_PIN3:
  ------------------
  |  Branch (1186:2): [True: 20.4k, False: 10.9k]
  ------------------
 1187|  20.4k|		method = SC_AC_CHV;
  ------------------
  |  |  151|  20.4k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1188|  20.4k|		key_ref = 0x03;
 1189|  20.4k|		break;
 1190|  31.3k|	}
 1191|       |
 1192|  31.3k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  62.7k|#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 (1192:6): [True: 31.3k, False: 0]
  |  Branch (1192:30): [True: 0, False: 0]
  ------------------
 1193|  31.3k|		sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|  31.3k|#define SC_AC_OP_WRITE			24
  ------------------
 1194|  31.3k|		sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|  31.3k|#define SC_AC_OP_UPDATE			23
  ------------------
 1195|  31.3k|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|  31.3k|#define SC_AC_OP_DELETE			2
  ------------------
 1196|  31.3k|		sc_file_add_acl_entry(file, SC_AC_OP_CREATE, method, key_ref);
  ------------------
  |  |  169|  31.3k|#define SC_AC_OP_CREATE			3
  ------------------
 1197|  31.3k|	}
 1198|      0|	else {
 1199|       |		/* When SC_AC_OP_DELETE is absent, we need to provide
 1200|       |		 * SC_AC_OP_DELETE_SELF for sc_pkcs15init_delete_by_path() */
 1201|      0|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE_SELF, method, key_ref);
  ------------------
  |  |  174|      0|#define SC_AC_OP_DELETE_SELF		8
  ------------------
 1202|      0|	}
 1203|       |
 1204|  31.3k|	method = SC_AC_NONE;
  ------------------
  |  |  150|  31.3k|#define SC_AC_NONE			0x00000000
  ------------------
 1205|  31.3k|	key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|  31.3k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
 1206|       |	/* Read access */
 1207|  31.3k|	switch (info->access & READ_MASK) {
  ------------------
  |  Branch (1207:10): [True: 3.41k, False: 27.9k]
  ------------------
 1208|  2.03k|	case READ_NEVER:
  ------------------
  |  Branch (1208:2): [True: 2.03k, False: 29.3k]
  ------------------
 1209|  2.03k|		method = SC_AC_NEVER;
  ------------------
  |  |  163|  2.03k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
 1210|  2.03k|		break;
 1211|      0|	case READ_PIN1:
  ------------------
  |  Branch (1211:2): [True: 0, False: 31.3k]
  ------------------
 1212|      0|		method = SC_AC_CHV;
  ------------------
  |  |  151|      0|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1213|      0|		key_ref = 0x01;
 1214|      0|		break;
 1215|    690|	case READ_PIN2:
  ------------------
  |  Branch (1215:2): [True: 690, False: 30.6k]
  ------------------
 1216|    690|		method = SC_AC_CHV;
  ------------------
  |  |  151|    690|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1217|    690|		key_ref = 0x02;
 1218|    690|		break;
 1219|    690|	case READ_PIN3:
  ------------------
  |  Branch (1219:2): [True: 690, False: 30.6k]
  ------------------
 1220|    690|		method = SC_AC_CHV;
  ------------------
  |  |  151|    690|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
 1221|    690|		key_ref = 0x03;
 1222|    690|		break;
 1223|  31.3k|	}
 1224|       |
 1225|  31.3k|	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  150|  62.7k|#define SC_AC_NONE			0x00000000
  ------------------
              	if (method != SC_AC_NONE || key_ref != SC_AC_KEY_REF_NONE) {
  ------------------
  |  |  204|  27.9k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  |  Branch (1225:6): [True: 3.41k, False: 27.9k]
  |  Branch (1225:30): [True: 0, False: 27.9k]
  ------------------
 1226|  3.41k|		sc_file_add_acl_entry(file, SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|  3.41k|#define SC_AC_OP_READ			22
  ------------------
 1227|  3.41k|	}
 1228|  31.3k|}
card-openpgp.c:pgp_match_card:
  326|  3.19k|{
  327|  3.19k|	int i;
  328|       |
  329|  3.19k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  3.19k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  3.19k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  3.19k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  3.19k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 3.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  330|       |
  331|  3.19k|	i = _sc_match_atr(card, pgp_atrs, &card->type);
  332|  3.19k|	if (i >= 0) {
  ------------------
  |  Branch (332:6): [True: 131, False: 3.06k]
  ------------------
  333|    131|		card->name = pgp_atrs[i].name;
  334|    131|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    131|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    131|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    131|	int _ret = r; \
  |  |  |  |  155|    131|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 131]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    131|	} else { \
  |  |  |  |  159|    131|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    131|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    131|	} \
  |  |  |  |  162|    131|	return _ret; \
  |  |  |  |  163|    131|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  335|    131|	}
  336|  3.06k|	else {
  337|  3.06k|		sc_path_t	partial_aid;
  338|  3.06k|		sc_file_t *file = NULL;
  339|       |
  340|       |		/* select application "OpenPGP" */
  341|  3.06k|		sc_format_path("D276:0001:2401", &partial_aid);
  342|  3.06k|		partial_aid.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  3.06k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  343|       |		/* OpenPGP card only supports selection *with* requested FCI */
  344|  3.06k|		i = iso_ops->select_file(card, &partial_aid, &file);
  345|  3.06k|		if (SC_SUCCESS == i) {
  ------------------
  |  |   28|  3.06k|#define SC_SUCCESS				0
  ------------------
  |  Branch (345:7): [True: 582, False: 2.47k]
  ------------------
  346|    582|			card->type = SC_CARD_TYPE_OPENPGP_BASE;
  347|    582|			card->name = default_cardname;
  348|       |
  349|    582|			if (file->namelen != 16)
  ------------------
  |  Branch (349:8): [True: 581, False: 1]
  ------------------
  350|    581|				(void) get_full_pgp_aid(card, file);
  351|    582|			if (file->namelen == 16) {
  ------------------
  |  Branch (351:8): [True: 26, False: 556]
  ------------------
  352|     26|				unsigned char major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|     26|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  353|       |
  354|     26|				switch (major) {
  355|      4|					case 1:
  ------------------
  |  Branch (355:6): [True: 4, False: 22]
  ------------------
  356|      4|						card->type = SC_CARD_TYPE_OPENPGP_V1;
  357|      4|						card->name = default_cardname_v1;
  358|      4|						break;
  359|     12|					case 2:
  ------------------
  |  Branch (359:6): [True: 12, False: 14]
  ------------------
  360|     12|						card->type = SC_CARD_TYPE_OPENPGP_V2;
  361|     12|						card->name = default_cardname_v2;
  362|     12|						break;
  363|      4|					case 3:
  ------------------
  |  Branch (363:6): [True: 4, False: 22]
  ------------------
  364|      4|						card->type = SC_CARD_TYPE_OPENPGP_V3;
  365|      4|						card->name = default_cardname_v3;
  366|      4|						break;
  367|      6|					default:
  ------------------
  |  Branch (367:6): [True: 6, False: 20]
  ------------------
  368|      6|						break;
  369|     26|				}
  370|     26|			}
  371|    582|			sc_file_free(file);
  372|    582|			LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  164|    582|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    582|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    582|	int _ret = r; \
  |  |  |  |  155|    582|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 582]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    582|	} else { \
  |  |  |  |  159|    582|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    582|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    582|	} \
  |  |  |  |  162|    582|	return _ret; \
  |  |  |  |  163|    582|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  373|    582|		}
  374|  3.06k|	}
  375|  2.47k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  2.47k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.47k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.47k|	int _ret = r; \
  |  |  |  |  155|  2.47k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.47k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.47k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.47k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.47k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.47k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.47k|	return _ret; \
  |  |  |  |  163|  2.47k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  376|  2.47k|}
card-openpgp.c:get_full_pgp_aid:
  307|  1.27k|{
  308|  1.27k|	int r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  1.27k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  309|       |
  310|  1.27k|	if (file != NULL) {
  ------------------
  |  Branch (310:6): [True: 1.27k, False: 0]
  ------------------
  311|       |		/* explicitly get the full aid */
  312|  1.27k|		r = sc_get_data(card, 0x004F, file->name, sizeof file->name);
  313|  1.27k|		file->namelen = MAX(r, 0);
  ------------------
  |  |   67|  1.27k|#define MAX(x, y) (((x) > (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (67:20): [True: 583, False: 695]
  |  |  ------------------
  ------------------
  314|  1.27k|	}
  315|       |
  316|  1.27k|	return r;
  317|  1.27k|}
card-openpgp.c:pgp_init:
  405|    713|{
  406|    713|	struct pgp_priv_data *priv;
  407|    713|	sc_path_t	path;
  408|    713|	sc_file_t	*file = NULL;
  409|    713|	int		r, i;
  410|       |
  411|    713|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    713|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    713|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    713|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    713|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 713]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  412|       |
  413|    713|	priv = calloc (1, sizeof *priv);
  414|    713|	if (!priv)
  ------------------
  |  Branch (414:6): [True: 0, False: 713]
  ------------------
  415|    713|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  416|    713|	card->drv_data = priv;
  417|       |
  418|    713|	card->cla = 0x00;
  419|       |
  420|       |	/* select application "OpenPGP" */
  421|    713|	sc_format_path("D276:0001:2401", &path);
  422|    713|	path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|    713|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  423|    713|	if ((r = iso_ops->select_file(card, &path, &file)) < 0) {
  ------------------
  |  Branch (423:6): [True: 15, False: 698]
  ------------------
  424|     15|		sc_file_free(file);
  425|     15|		pgp_finish(card);
  426|     15|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  427|     15|	}
  428|       |
  429|       |	/* defensive programming check */
  430|    698|	if (!file)   {
  ------------------
  |  Branch (430:6): [True: 0, False: 698]
  ------------------
  431|      0|		pgp_finish(card);
  432|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  433|      0|	}
  434|       |
  435|    698|	if (file->namelen != 16) {
  ------------------
  |  Branch (435:6): [True: 697, False: 1]
  ------------------
  436|       |		/* explicitly get the full aid */
  437|    697|		r = get_full_pgp_aid(card, file);
  438|    697|		if (r < 0) {
  ------------------
  |  Branch (438:7): [True: 8, False: 689]
  ------------------
  439|      8|			sc_file_free(file);
  440|      8|			pgp_finish(card);
  441|      8|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_CARD);
  ------------------
  |  |  164|      8|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      8|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      8|	int _ret = r; \
  |  |  |  |  155|      8|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      8|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      8|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 8, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      8|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      8|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  442|      8|		}
  443|    697|	}
  444|       |
  445|       |	/* read information from AID */
  446|    690|	if (file->namelen == 16) {
  ------------------
  |  Branch (446:6): [True: 426, False: 264]
  ------------------
  447|    426|		static char card_name[SC_MAX_APDU_BUFFER_SIZE] = "OpenPGP card";
  448|       |
  449|       |		/* OpenPGP card spec 1.1, 2.x & 3.x, section 4.2.1 & 4.1.2.1 */
  450|    426|		priv->bcd_version = bebytes2ushort(file->name + 6);
  451|    426|		card->version.fw_major = card->version.hw_major = BCD2UCHAR(file->name[6]);
  ------------------
  |  |  216|    426|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  452|    426|		card->version.fw_minor = card->version.hw_minor = BCD2UCHAR(file->name[7]);
  ------------------
  |  |  216|    426|#define BCD2UCHAR(x) (((((x) & 0xF0) >> 4) * 10) + ((x) & 0x0F))
  ------------------
  453|       |
  454|       |		/* for "standard" cards, include detailed card version & serial no. in card name */
  455|    426|		if (card->name == default_cardname_v1 ||
  ------------------
  |  Branch (455:7): [True: 1, False: 425]
  ------------------
  456|    425|		    card->name == default_cardname_v2 ||
  ------------------
  |  Branch (456:7): [True: 1, False: 424]
  ------------------
  457|    424|		    card->name == default_cardname_v3) {
  ------------------
  |  Branch (457:7): [True: 1, False: 423]
  ------------------
  458|      3|			snprintf(card_name, sizeof(card_name),
  459|      3|				 "OpenPGP card v%u.%u (%04X %08lX)",
  460|      3|				 card->version.hw_major, card->version.hw_minor,
  461|      3|				 bebytes2ushort(file->name + 8),
  462|      3|				 bebytes2ulong(file->name + 10));
  463|      3|		}
  464|    423|		else if (card->name != NULL) {
  ------------------
  |  Branch (464:12): [True: 423, False: 0]
  ------------------
  465|       |			/* for other cards, append serial number to the card name */
  466|    423|			snprintf(card_name, sizeof(card_name),
  467|    423|				 "%s (%04X %08lX)",
  468|    423|				 card->name,
  469|    423|				 bebytes2ushort(file->name + 8),
  470|    423|				 bebytes2ulong(file->name + 10));
  471|    423|		}
  472|    426|		card->name = card_name;
  473|       |
  474|       |		/* GPG compatibility: set card's serial number to manufacturer ID + serial number */
  475|    426|		memcpy(card->serialnr.value, file->name + 8, 6);
  476|    426|		card->serialnr.len = 6;
  477|    426|	} else {
  478|       |		/* set detailed card version */
  479|    264|		switch (card->type) {
  480|      2|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (480:4): [True: 2, False: 262]
  ------------------
  481|      2|				priv->bcd_version = OPENPGP_CARD_3_0;
  482|      2|				break;
  483|    116|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (483:4): [True: 116, False: 148]
  ------------------
  484|    126|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (484:4): [True: 10, False: 254]
  ------------------
  485|    126|				priv->bcd_version = OPENPGP_CARD_2_0;
  486|    126|				break;
  487|    136|			default:
  ------------------
  |  Branch (487:4): [True: 136, False: 128]
  ------------------
  488|    136|				priv->bcd_version = OPENPGP_CARD_1_1;
  489|    136|				break;
  490|    264|		}
  491|    264|	}
  492|       |
  493|       |	/* set pointer to correct list of card objects */
  494|    690|	priv->pgp_objects = (priv->bcd_version < OPENPGP_CARD_2_0) ? pgp1x_objects
  ------------------
  |  Branch (494:22): [True: 179, False: 511]
  ------------------
  495|    690|			  : (priv->bcd_version < OPENPGP_CARD_2_1) ? pgp20_objects
  ------------------
  |  Branch (495:8): [True: 128, False: 383]
  ------------------
  496|    511|			  : (priv->bcd_version < OPENPGP_CARD_3_0) ? pgp21_objects
  ------------------
  |  Branch (496:8): [True: 10, False: 373]
  ------------------
  497|    383|			  : (priv->bcd_version < OPENPGP_CARD_3_3) ? pgp30_objects
  ------------------
  |  Branch (497:8): [True: 6, False: 367]
  ------------------
  498|    373|			  : (priv->bcd_version < OPENPGP_CARD_3_4) ? pgp33_objects
  ------------------
  |  Branch (498:8): [True: 1, False: 366]
  ------------------
  499|    367|			  :					     pgp34_objects;
  500|       |
  501|       |	/* With gnuk, we use different curves */
  502|    690|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (502:6): [True: 127, False: 563]
  ------------------
  503|    127|		priv->ec_curves = ec_curves_gnuk;
  504|    563|	} else if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (504:13): [True: 363, False: 200]
  ------------------
  505|    363|		priv->ec_curves = ec_curves_openpgp34;
  506|    363|	} else {
  507|    200|		priv->ec_curves = ec_curves_openpgp;
  508|    200|	}
  509|       |
  510|       |	/* change file path to MF for reuse in MF */
  511|    690|	sc_format_path("3f00", &file->path);
  512|       |
  513|       |	/* set up the root of our fake file tree */
  514|       |	/* Transfers ownership of the file to the priv->mf structure */
  515|    690|	priv->mf = pgp_new_blob(card, NULL, 0x3f00, file);
  516|    690|	if (!priv->mf) {
  ------------------
  |  Branch (516:6): [True: 0, False: 690]
  ------------------
  517|      0|		sc_file_free(file);
  518|      0|		pgp_finish(card);
  519|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|      0|	}
  521|       |
  522|       |	/* select MF */
  523|    690|	priv->current = priv->mf;
  524|       |
  525|    690|	r = populate_blobs_to_mf(card, priv);
  526|    690|	if (r < 0) {
  ------------------
  |  Branch (526:6): [True: 0, False: 690]
  ------------------
  527|      0|		pgp_finish(card);
  528|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  529|      0|	}
  530|       |
  531|       |	/* get card_features from ATR & DOs */
  532|    690|	if (pgp_get_card_features(card)) {
  ------------------
  |  Branch (532:6): [True: 34, False: 656]
  ------------------
  533|     34|		LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  534|     34|	}
  535|       |
  536|       |	/* if algorithm attributes can be changed,
  537|       |	 * add supported algorithms based on specification for pkcs15-init */
  538|    656|	if (priv->ext_caps & EXT_CAP_ALG_ATTR_CHANGEABLE) {
  ------------------
  |  Branch (538:6): [True: 39, False: 617]
  ------------------
  539|     39|		unsigned long flags_rsa, flags_ecc, ext_flags;
  540|     39|		unsigned long flags_eddsa, flags_xeddsa;
  541|       |
  542|       |		/* OpenPGP card spec 1.1 & 2.x, section 7.2.9 & 7.2.10 / v3.x section 7.2.11 & 7.2.12 */
  543|     39|		flags_rsa = SC_ALGORITHM_RSA_PAD_PKCS1|
  ------------------
  |  |  120|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|     39|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  544|     39|			    SC_ALGORITHM_RSA_HASH_NONE|
  ------------------
  |  |  142|     39|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  545|     39|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     39|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  546|     39|		flags_ecc = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  183|     39|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  547|     39|			    SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  182|     39|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  548|     39|			    SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  184|     39|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|     39|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  549|     39|			    SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     39|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  550|     39|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE;
  ------------------
  |  |  210|     39|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
  551|       |
  552|     39|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW |
  ------------------
  |  |  197|     39|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
  553|     39|			      SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     39|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  554|       |		/* xeddsa may allow signing at some time */
  555|     39|		flags_xeddsa = SC_ALGORITHM_ECDH_CDH_RAW |
  ------------------
  |  |  182|     39|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
  556|     39|			       SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|     39|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  557|       |
  558|     39|		switch (card->type) {
  559|      0|			case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (559:4): [True: 0, False: 39]
  ------------------
  560|       |				/* RSA 1024 was removed for v3+ */
  561|      0|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  562|      0|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  563|       |				/* fallthrough */
  564|     12|			case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (564:4): [True: 12, False: 27]
  ------------------
  565|     12|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  566|     84|				for (i=0; priv->ec_curves[i].oid.value[0] >= 0; i++)
  ------------------
  |  Branch (566:15): [True: 72, False: 12]
  ------------------
  567|     72|				{
  568|     72|					if (priv->ec_curves[i].key_type == SC_ALGORITHM_EC)
  ------------------
  |  |   79|     72|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (568:10): [True: 24, False: 48]
  ------------------
  569|     24|						_sc_card_add_ec_alg(card, priv->ec_curves[i].size,
  570|     24|								flags_ecc, ext_flags, &priv->ec_curves[i].oid);
  571|     48|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|     48|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (571:15): [True: 24, False: 24]
  ------------------
  572|     24|						_sc_card_add_eddsa_alg(card, priv->ec_curves[i].size,
  573|     24|								flags_eddsa, ext_flags, &priv->ec_curves[i].oid);
  574|     24|					else if (priv->ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|     24|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (574:15): [True: 24, False: 0]
  ------------------
  575|     24|						_sc_card_add_xeddsa_alg(card, priv->ec_curves[i].size,
  576|     24|								flags_xeddsa, ext_flags, &priv->ec_curves[i].oid);
  577|      0|					else
  578|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  579|     72|				}
  580|     12|				break;
  581|     12|			case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (581:4): [True: 0, False: 39]
  ------------------
  582|     27|			default:
  ------------------
  |  Branch (582:4): [True: 27, False: 12]
  ------------------
  583|     27|				_sc_card_add_rsa_alg(card, 1024, flags_rsa, 0);
  584|     27|				_sc_card_add_rsa_alg(card, 2048, flags_rsa, 0);
  585|     27|				_sc_card_add_rsa_alg(card, 3072, flags_rsa, 0);
  586|     27|				_sc_card_add_rsa_alg(card, 4096, flags_rsa, 0);
  587|     27|				break;
  588|     39|		}
  589|     39|	}
  590|       |
  591|    656|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    656|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    656|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    656|	int _ret = r; \
  |  |  |  |  155|    656|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 656, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    656|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 656]
  |  |  |  |  ------------------
  |  |  |  |  157|    656|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    656|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    656|	return _ret; \
  |  |  |  |  163|    656|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  592|    656|}
card-openpgp.c:pgp_get_blob:
 1477|  10.3k|{
 1478|  10.3k|	pgp_blob_t		*child;
 1479|  10.3k|	int			r;
 1480|       |
 1481|  10.3k|	if ((r = pgp_enumerate_blob(card, blob)) < 0)
  ------------------
  |  Branch (1481:6): [True: 1.02k, False: 9.34k]
  ------------------
 1482|  1.02k|		return r;
 1483|       |
 1484|  70.7k|	for (child = blob->files; child; child = child->next) {
  ------------------
  |  Branch (1484:28): [True: 68.8k, False: 1.93k]
  ------------------
 1485|  68.8k|		if (child->id == id) {
  ------------------
  |  Branch (1485:7): [True: 7.41k, False: 61.3k]
  ------------------
 1486|  7.41k|			(void) pgp_read_blob(card, child);
 1487|  7.41k|			*ret = child;
 1488|  7.41k|			return SC_SUCCESS;
  ------------------
  |  |   28|  7.41k|#define SC_SUCCESS				0
  ------------------
 1489|  7.41k|		}
 1490|  68.8k|	}
 1491|       |
 1492|       |	/* This part is for "NOT FOUND" cases */
 1493|       |
 1494|       |	/* Special case:
 1495|       |	 * Gnuk does not have default value for children of DO 65 (DOs 5B, 5F2D, 5F35)
 1496|       |	 * So, if these blob was not found, we create it. */
 1497|  1.93k|	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  154|  3.86k|#define DO_CARDHOLDER            0x65
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  155|    432|#define DO_NAME                  0x5b
  ------------------
              	if (blob->id == DO_CARDHOLDER && (id == DO_NAME || id == DO_LANG_PREF || id == DO_SEX)) {
  ------------------
  |  |  156|    432|#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 (1497:6): [True: 216, False: 1.71k]
  |  Branch (1497:36): [True: 0, False: 216]
  |  Branch (1497:53): [True: 216, False: 0]
  |  Branch (1497:75): [True: 0, False: 0]
  ------------------
 1498|    216|		sc_log(card->ctx, "Create blob %X under %X", id, blob->id);
  ------------------
  |  |   71|    216|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1499|    216|		child = pgp_new_blob(card, blob, id, sc_file_new());
 1500|    216|		if (child) {
  ------------------
  |  Branch (1500:7): [True: 216, False: 0]
  ------------------
 1501|    216|			pgp_set_blob(child, NULL, 0);
 1502|    216|			*ret = child;
 1503|    216|			return SC_SUCCESS;
  ------------------
  |  |   28|    216|#define SC_SUCCESS				0
  ------------------
 1504|    216|		}
 1505|      0|		else
 1506|      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__
  |  |  ------------------
  ------------------
 1507|    216|			       "Not enough memory to create blob for DO %X",
 1508|    216|			       id);
 1509|    216|	}
 1510|       |
 1511|  1.71k|	return SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.71k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 1512|  1.93k|}
card-openpgp.c:pgp_enumerate_blob:
 1395|  10.7k|{
 1396|  10.7k|	const u8	*in;
 1397|  10.7k|	int		r;
 1398|  10.7k|	sc_file_t	*file = NULL;
 1399|       |
 1400|  10.7k|	if (blob->files != NULL)
  ------------------
  |  Branch (1400:6): [True: 8.63k, False: 2.10k]
  ------------------
 1401|  8.63k|		return SC_SUCCESS;
  ------------------
  |  |   28|  8.63k|#define SC_SUCCESS				0
  ------------------
 1402|       |
 1403|  2.10k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1403:6): [True: 960, False: 1.14k]
  ------------------
 1404|    960|		return r;
 1405|       |
 1406|  1.14k|	in = blob->data;
 1407|       |
 1408|  30.4k|	while ((int) blob->len > (in - blob->data)) {
  ------------------
  |  Branch (1408:9): [True: 29.7k, False: 759]
  ------------------
 1409|  29.7k|		unsigned int	cla, tag, tmptag;
 1410|  29.7k|		size_t		len;
 1411|  29.7k|		const u8	*data = in;
 1412|  29.7k|		pgp_blob_t	*new;
 1413|       |
 1414|  29.7k|		if (!in)
  ------------------
  |  Branch (1414:7): [True: 0, False: 29.7k]
  ------------------
 1415|      0|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|      0|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1416|       |
 1417|  29.7k|		r = sc_asn1_read_tag(&data, blob->len - (in - blob->data),
 1418|  29.7k|					&cla, &tag, &len);
 1419|  29.7k|		if (r == SC_ERROR_INVALID_ASN1_OBJECT) {
  ------------------
  |  |   82|  29.7k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (1419:7): [True: 93, False: 29.6k]
  ------------------
 1420|     93|			sc_log(card->ctx, "Invalid ASN.1 object");
  ------------------
  |  |   71|     93|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1421|     93|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|     93|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1422|     93|		}
 1423|       |		/* Check for unknown error, or empty data */
 1424|  29.6k|		if (((r < 0) && (r != SC_ERROR_ASN1_END_OF_CONTENTS)) ||
  ------------------
  |  |   84|    249|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1424:8): [True: 249, False: 29.3k]
  |  Branch (1424:19): [True: 0, False: 249]
  ------------------
 1425|  29.6k|		    (data == NULL)) {
  ------------------
  |  Branch (1425:7): [True: 82, False: 29.5k]
  ------------------
 1426|     82|			sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1427|     82|			return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|     82|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1428|     82|		}
 1429|       |
 1430|       |		/* undo ASN1's split of tag & class */
 1431|  30.2k|		for (tmptag = tag; tmptag > 0x0FF; tmptag >>= 8) {
  ------------------
  |  Branch (1431:22): [True: 671, False: 29.5k]
  ------------------
 1432|    671|			cla <<= 8;
 1433|    671|		}
 1434|  29.5k|		tag |= cla;
 1435|       |		/* Check for length mismatch */
 1436|  29.5k|		if ((r == SC_ERROR_ASN1_END_OF_CONTENTS) ||
  ------------------
  |  |   84|  29.5k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (1436:7): [True: 249, False: 29.3k]
  ------------------
 1437|  29.3k|		    (data + len > blob->data + blob->len)) {
  ------------------
  |  Branch (1437:7): [True: 0, False: 29.3k]
  ------------------
 1438|       |			// Check if it is not known Yubikey 5 issue
 1439|    249|			if ((tag != blob->id) || (tag != 0xfa)) {
  ------------------
  |  Branch (1439:8): [True: 204, False: 45]
  |  Branch (1439:29): [True: 8, False: 37]
  ------------------
 1440|    212|				sc_log(card->ctx, "Unexpected end of contents");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1441|    212|				return SC_ERROR_OBJECT_NOT_VALID;
  ------------------
  |  |   87|    212|#define SC_ERROR_OBJECT_NOT_VALID		-1406
  ------------------
 1442|    212|			}
 1443|    249|		}
 1444|       |
 1445|       |		/* Awful hack for composite DOs that have
 1446|       |		 * a TLV with the DO's id encompassing the
 1447|       |		 * entire blob. Example: Yubikey Neo */
 1448|  29.3k|		if (tag == blob->id) {
  ------------------
  |  Branch (1448:7): [True: 236, False: 29.1k]
  ------------------
 1449|    236|			in = data;
 1450|    236|			continue;
 1451|    236|		}
 1452|       |
 1453|       |		/* create fake file system hierarchy by
 1454|       |		 * using constructed DOs as DF */
 1455|  29.1k|		file = sc_file_new();
 1456|  29.1k|		if ((new = pgp_new_blob(card, blob, tag, file)) == NULL) {
  ------------------
  |  Branch (1456:7): [True: 0, False: 29.1k]
  ------------------
 1457|      0|			sc_file_free(file);
 1458|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1459|      0|		}
 1460|  29.1k|		if (pgp_set_blob(new, data, len) != SC_SUCCESS) {
  ------------------
  |  |   28|  29.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1460:7): [True: 0, False: 29.1k]
  ------------------
 1461|      0|			sc_file_free(file);
 1462|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1463|      0|		}
 1464|  29.1k|		in = data + len;
 1465|  29.1k|	}
 1466|       |
 1467|    759|	return SC_SUCCESS;
  ------------------
  |  |   28|    759|#define SC_SUCCESS				0
  ------------------
 1468|  1.14k|}
card-openpgp.c:pgp_set_blob:
 1137|  30.4k|{
 1138|  30.4k|	if (blob->data)
  ------------------
  |  Branch (1138:6): [True: 0, False: 30.4k]
  ------------------
 1139|      0|		free(blob->data);
 1140|  30.4k|	blob->data = NULL;
 1141|  30.4k|	blob->len    = 0;
 1142|  30.4k|	blob->status = 0;
 1143|       |
 1144|  30.4k|	if (len > 0) {
  ------------------
  |  Branch (1144:6): [True: 15.5k, False: 14.9k]
  ------------------
 1145|  15.5k|		void *tmp = calloc(1, len);
 1146|       |
 1147|  15.5k|		if (tmp == NULL)
  ------------------
  |  Branch (1147:7): [True: 0, False: 15.5k]
  ------------------
 1148|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1149|       |
 1150|  15.5k|		blob->data = tmp;
 1151|  15.5k|		blob->len  = (unsigned int)len;
 1152|  15.5k|		if (data != NULL)
  ------------------
  |  Branch (1152:7): [True: 15.5k, False: 0]
  ------------------
 1153|  15.5k|			memcpy(blob->data, data, len);
 1154|  15.5k|	}
 1155|       |
 1156|  30.4k|	if (blob->file)
  ------------------
  |  Branch (1156:6): [True: 30.4k, False: 0]
  ------------------
 1157|  30.4k|		blob->file->size = len;
 1158|       |
 1159|  30.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  30.4k|#define SC_SUCCESS				0
  ------------------
 1160|  30.4k|}
card-openpgp.c:pgp_read_blob:
 1345|  11.0k|{
 1346|  11.0k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  11.0k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1347|       |
 1348|  11.0k|	if (blob->data != NULL)
  ------------------
  |  Branch (1348:6): [True: 7.11k, False: 3.92k]
  ------------------
 1349|  7.11k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.11k|#define SC_SUCCESS				0
  ------------------
 1350|  3.92k|	if (blob->info == NULL)
  ------------------
  |  Branch (1350:6): [True: 0, False: 3.92k]
  ------------------
 1351|      0|		return blob->status;
 1352|       |
 1353|  3.92k|	if (blob->info->get_fn) {	/* readable, top-level DO */
  ------------------
  |  Branch (1353:6): [True: 3.85k, False: 78]
  ------------------
 1354|  3.85k|		u8 	buffer[MAX_OPENPGP_DO_SIZE];
 1355|  3.85k|		size_t	buf_len = sizeof(buffer);
 1356|  3.85k|		int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.85k|#define SC_SUCCESS				0
  ------------------
 1357|       |
 1358|       |		/* buffer length for certificate */
 1359|  3.85k|		if (blob->id == DO_CERT && priv->max_cert_size > 0) {
  ------------------
  |  |  138|  7.70k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (1359:7): [True: 148, False: 3.70k]
  |  Branch (1359:30): [True: 3, False: 145]
  ------------------
 1360|      3|			buf_len = MIN(priv->max_cert_size, sizeof(buffer));
  ------------------
  |  |   70|      3|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 1, False: 2]
  |  |  ------------------
  ------------------
 1361|      3|		}
 1362|       |
 1363|       |		/* buffer length for Gnuk pubkey */
 1364|  3.85k|		if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (1364:7): [True: 645, False: 3.20k]
  ------------------
 1365|    645|		    (blob->id == DO_AUTH ||
  ------------------
  |  |  143|  1.29k|#define DO_AUTH                  0xa400
  ------------------
  |  Branch (1365:8): [True: 0, False: 645]
  ------------------
 1366|    645|		     blob->id == DO_SIGN ||
  ------------------
  |  |  141|  1.29k|#define DO_SIGN                  0xb600
  ------------------
  |  Branch (1366:8): [True: 0, False: 645]
  ------------------
 1367|    645|		     blob->id == DO_ENCR ||
  ------------------
  |  |  142|  1.29k|#define DO_ENCR                  0xb800
  ------------------
  |  Branch (1367:8): [True: 0, False: 645]
  ------------------
 1368|    645|		     blob->id == DO_AUTH_SYM ||
  ------------------
  |  |  147|  1.29k|#define DO_AUTH_SYM              0xa401
  ------------------
  |  Branch (1368:8): [True: 0, False: 645]
  ------------------
 1369|    645|		     blob->id == DO_SIGN_SYM ||
  ------------------
  |  |  145|  1.29k|#define DO_SIGN_SYM              0xb601
  ------------------
  |  Branch (1369:8): [True: 0, False: 645]
  ------------------
 1370|    645|		     blob->id == DO_ENCR_SYM)) {
  ------------------
  |  |  146|    645|#define DO_ENCR_SYM              0xb801
  ------------------
  |  Branch (1370:8): [True: 0, False: 645]
  ------------------
 1371|      0|			buf_len = MIN(MAXLEN_RESP_PUBKEY_GNUK, sizeof(buffer));
  ------------------
  |  |   70|      0|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 0, Folded]
  |  |  ------------------
  ------------------
 1372|      0|		}
 1373|       |
 1374|  3.85k|		r = blob->info->get_fn(card, blob->id, buffer, buf_len);
 1375|       |
 1376|  3.85k|		if (r < 0) {	/* an error occurred */
  ------------------
  |  Branch (1376:7): [True: 2.68k, False: 1.16k]
  ------------------
 1377|  2.68k|			blob->status = r;
 1378|  2.68k|			return r;
 1379|  2.68k|		}
 1380|       |
 1381|  1.16k|		return pgp_set_blob(blob, buffer, r);
 1382|  3.85k|	}
 1383|     78|	else {		/* un-readable DO or part of a constructed DO */
 1384|     78|		return SC_SUCCESS;
  ------------------
  |  |   28|     78|#define SC_SUCCESS				0
  ------------------
 1385|     78|	}
 1386|  3.92k|}
card-openpgp.c:pgp_parse_algo_attr_blob:
  630|  10.5k|{
  631|  10.5k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  10.5k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  632|  10.5k|	struct sc_object_id oid;
  633|  10.5k|	unsigned int j, r;
  634|       |
  635|  10.5k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  10.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  10.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  10.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  10.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 10.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  636|       |
  637|  10.5k|	if (blob == NULL || blob->data == NULL || blob->len == 0 ||
  ------------------
  |  Branch (637:6): [True: 0, False: 10.5k]
  |  Branch (637:22): [True: 1.30k, False: 9.24k]
  |  Branch (637:44): [True: 0, False: 9.24k]
  ------------------
  638|  9.24k|	    blob->id < 0x00c1 || blob->id > 0x00c3 || key_info == NULL) {
  ------------------
  |  Branch (638:6): [True: 0, False: 9.24k]
  |  Branch (638:27): [True: 0, False: 9.24k]
  |  Branch (638:48): [True: 0, False: 9.24k]
  ------------------
  639|  1.30k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  164|  1.30k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.30k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.30k|	int _ret = r; \
  |  |  |  |  155|  1.30k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.30k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.30k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.30k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.30k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.30k|	return _ret; \
  |  |  |  |  163|  1.30k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  640|  1.30k|	}
  641|       |
  642|  9.24k|	key_info->key_id = blob->id - 0x00c0;	/* attribute algorithm blobs are C1 - C3 */
  643|       |
  644|  9.24k|	switch (blob->data[0]) {
  645|  2.97k|		case SC_OPENPGP_KEYALGO_RSA:
  ------------------
  |  |  869|  2.97k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  |  Branch (645:3): [True: 2.97k, False: 6.26k]
  ------------------
  646|  2.97k|			if (blob->len < 5) {
  ------------------
  |  Branch (646:8): [True: 1.96k, False: 1.01k]
  ------------------
  647|  1.96k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INCORRECT_PARAMETERS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  648|  1.96k|			}
  649|       |
  650|  1.01k|			key_info->algorithm = SC_OPENPGP_KEYALGO_RSA;
  ------------------
  |  |  869|  1.01k|#define	SC_OPENPGP_KEYALGO_RSA		0x01
  ------------------
  651|  1.01k|			key_info->u.rsa.modulus_len = bebytes2ushort(blob->data + 1);
  652|  1.01k|			key_info->u.rsa.exponent_len = bebytes2ushort(blob->data + 3);
  653|       |
  654|  1.01k|			key_info->u.rsa.keyformat = (blob->len > 5)
  ------------------
  |  Branch (654:32): [True: 342, False: 672]
  ------------------
  655|  1.01k|						  ? blob->data[5]
  656|  1.01k|						  : SC_OPENPGP_KEYFORMAT_RSA_STD;
  ------------------
  |  |  874|  1.68k|#define SC_OPENPGP_KEYFORMAT_RSA_STD	0    /* See 4.3.3.6 Algorithm Attributes */
  ------------------
  657|  1.01k|			break;
  658|  3.00k|		case SC_OPENPGP_KEYALGO_ECDH:
  ------------------
  |  |  870|  3.00k|#define	SC_OPENPGP_KEYALGO_ECDH		0x12
  ------------------
  |  Branch (658:3): [True: 3.00k, False: 6.23k]
  ------------------
  659|  4.32k|		case SC_OPENPGP_KEYALGO_ECDSA:
  ------------------
  |  |  871|  4.32k|#define	SC_OPENPGP_KEYALGO_ECDSA	0x13
  ------------------
  |  Branch (659:3): [True: 1.31k, False: 7.92k]
  ------------------
  660|  4.74k|		case SC_OPENPGP_KEYALGO_EDDSA:
  ------------------
  |  |  872|  4.74k|#define	SC_OPENPGP_KEYALGO_EDDSA	0x16
  ------------------
  |  Branch (660:3): [True: 415, False: 8.82k]
  ------------------
  661|       |
  662|       |			/* SC_OPENPGP_KEYALGO_ECDH || SC_OPENPGP_KEYALGO_ECDSA || SC_OPENPGP_KEYALGO_EDDSA */
  663|  4.74k|			key_info->algorithm = blob->data[0];
  664|       |
  665|       |			/* last byte is set to 0xFF if pubkey import is supported */
  666|  4.74k|			if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STDPUB){
  ------------------
  |  |  880|  4.74k|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  |  Branch (666:8): [True: 1.09k, False: 3.64k]
  ------------------
  667|  1.09k|				if (blob->len < 3)
  ------------------
  |  Branch (667:9): [True: 976, False: 120]
  ------------------
  668|    976|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    976|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  669|    120|				key_info->u.ec.oidv_len = blob->len - 2;
  670|    120|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STDPUB;
  ------------------
  |  |  880|    120|#define SC_OPENPGP_KEYFORMAT_EC_STDPUB	0xFF
  ------------------
  671|    120|			}
  672|  3.64k|			else {
  673|       |				/* otherwise, last byte could be 00, so let's ignore it, as
  674|       |				 * it is not part of OID */
  675|  3.64k|				if (blob->len < 2)
  ------------------
  |  Branch (675:9): [True: 667, False: 2.97k]
  ------------------
  676|    667|					return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|    667|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  677|  2.97k|				if (blob->data[blob->len-1] == SC_OPENPGP_KEYFORMAT_EC_STD)
  ------------------
  |  |  879|  2.97k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  |  Branch (677:9): [True: 785, False: 2.19k]
  ------------------
  678|    785|					key_info->u.ec.oidv_len = blob->len - 2;
  679|  2.19k|				else
  680|  2.19k|					key_info->u.ec.oidv_len = blob->len - 1;
  681|  2.97k|				key_info->u.ec.keyformat = SC_OPENPGP_KEYFORMAT_EC_STD;
  ------------------
  |  |  879|  2.97k|#define SC_OPENPGP_KEYFORMAT_EC_STD	0
  ------------------
  682|  2.97k|			}
  683|       |
  684|       |			/* Create copy of oid from blob */
  685|  3.09k|			sc_init_oid(&oid);
  686|  3.09k|			r = sc_asn1_decode_object_id(&blob->data[1], key_info->u.ec.oidv_len, &oid);
  687|       |
  688|       |			/* decoding failed, return sc_asn1_decode_object_id error code */
  689|  3.09k|			if (r > 0){
  ------------------
  |  Branch (689:8): [True: 2.26k, False: 831]
  ------------------
  690|  2.26k|				return r;
  691|  2.26k|			}
  692|       |			/* compare with list of supported ec_curves */
  693|  11.5k|			for (j = 0; priv->ec_curves[j].oid.value[0] >= 0; j++) {
  ------------------
  |  Branch (693:16): [True: 10.7k, False: 831]
  ------------------
  694|  10.7k|				if (sc_compare_oid(&priv->ec_curves[j].oid, &oid)) {
  ------------------
  |  Branch (694:9): [True: 0, False: 10.7k]
  ------------------
  695|      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__
  |  |  ------------------
  ------------------
  696|      0|						sc_dump_oid(&oid), j);
  697|      0|					key_info->u.ec.oid = priv->ec_curves[j].oid;
  698|      0|					key_info->u.ec.key_length = priv->ec_curves[j].size;
  699|      0|					break;
  700|      0|				}
  701|  10.7k|			}
  702|       |			/* We did not match the OID */
  703|    831|			if (priv->ec_curves[j].oid.value[0] < 0) {
  ------------------
  |  Branch (703:8): [True: 831, False: 0]
  ------------------
  704|    831|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    831|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    831|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    831|	int _ret = r; \
  |  |  |  |  155|    831|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 831, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    831|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    831|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 831, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    831|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    831|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    831|	return _ret; \
  |  |  |  |  163|    831|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  705|    831|			}
  706|      0|			break;
  707|  1.52k|		default:
  ------------------
  |  Branch (707:3): [True: 1.52k, False: 7.71k]
  ------------------
  708|  1.52k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|  1.52k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.52k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.52k|	int _ret = r; \
  |  |  |  |  155|  1.52k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.52k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.52k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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.52k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.52k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.52k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.52k|	} else { \
  |  |  |  |  159|      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.52k|	return _ret; \
  |  |  |  |  163|  1.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  9.24k|	}
  710|       |
  711|  1.01k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.01k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.01k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.01k|	int _ret = r; \
  |  |  |  |  155|  1.01k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.01k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.01k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.01k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.01k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.01k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.01k|	return _ret; \
  |  |  |  |  163|  1.01k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  712|  1.01k|}
card-openpgp.c:pgp_get_card_features:
  906|    690|{
  907|    690|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    690|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  908|    690|	u8 *hist_bytes = card->reader->atr_info.hist_bytes;
  909|    690|	size_t hist_bytes_len = card->reader->atr_info.hist_bytes_len;
  910|    690|	unsigned int i;
  911|    690|	pgp_blob_t *blob, *blob6e, *blob73, *blobfa;
  912|    690|	int handled_algos = 0;
  913|       |
  914|    690|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    690|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    690|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    690|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    690|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 690]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  915|       |
  916|       |	/* parse card capabilities from historical bytes in ATR */
  917|    690|	if (hist_bytes_len > 0) {
  ------------------
  |  Branch (917:6): [True: 270, False: 420]
  ------------------
  918|       |		/* category indicator 0x00, 0x10 or 0x80 => compact TLV (ISO) */
  919|    270|		switch (hist_bytes[0]) {
  ------------------
  |  Branch (919:11): [True: 161, False: 109]
  ------------------
  920|    149|			case 0x00:
  ------------------
  |  Branch (920:4): [True: 149, False: 121]
  ------------------
  921|    149|				if (hist_bytes_len > 4) {
  ------------------
  |  Branch (921:9): [True: 148, False: 1]
  ------------------
  922|    148|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-4);
  923|    148|				}
  924|    149|				break;
  925|     10|			case 0x80:
  ------------------
  |  Branch (925:4): [True: 10, False: 260]
  ------------------
  926|     10|				if (hist_bytes_len > 1) {
  ------------------
  |  Branch (926:9): [True: 9, False: 1]
  ------------------
  927|      9|					pgp_parse_hist_bytes(card, hist_bytes+1, hist_bytes_len-1);
  928|      9|				}
  929|     10|				break;
  930|      2|			case 0x10:
  ------------------
  |  Branch (930:4): [True: 2, False: 268]
  ------------------
  931|      2|				if (hist_bytes_len > 2) {
  ------------------
  |  Branch (931:9): [True: 1, False: 1]
  ------------------
  932|      1|					pgp_parse_hist_bytes(card, hist_bytes+2, hist_bytes_len-2);
  933|      1|				}
  934|      2|				break;
  935|    270|		}
  936|    270|	}
  937|       |
  938|       |	/* v1.1 does not support lifecycle via ACTIVATE & TERMINATE: set default */
  939|    690|	priv->ext_caps &= ~EXT_CAP_LCS;
  940|       |
  941|    690|	if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (941:6): [True: 511, False: 179]
  ------------------
  942|       |		/* get card capabilities from "historical bytes" DO */
  943|    511|		if ((pgp_get_blob(card, priv->mf, 0x5f52, &blob) >= 0) &&
  ------------------
  |  Branch (943:7): [True: 511, False: 0]
  ------------------
  944|    511|		    (blob->data != NULL) && (blob->data[0] == 0x00)) {
  ------------------
  |  Branch (944:7): [True: 47, False: 464]
  |  Branch (944:31): [True: 37, False: 10]
  ------------------
  945|       |
  946|     37|			if (blob->len > 4) {
  ------------------
  |  Branch (946:8): [True: 34, False: 3]
  ------------------
  947|     34|				pgp_parse_hist_bytes(card, blob->data+1, blob->len-4);
  948|     34|			}
  949|       |
  950|       |			/* get card status from historical bytes status indicator */
  951|     37|			if ((blob->data[0] == 0x00) && (blob->len >= 4)) {
  ------------------
  |  Branch (951:8): [True: 37, False: 0]
  |  Branch (951:35): [True: 34, False: 3]
  ------------------
  952|     34|				priv->state = blob->data[blob->len-3];
  953|       |				/* state not CARD_STATE_UNKNOWN => LCS supported */
  954|     34|				if (priv->state != CARD_STATE_UNKNOWN)
  ------------------
  |  Branch (954:9): [True: 25, False: 9]
  ------------------
  955|     25|					priv->ext_caps |= EXT_CAP_LCS;
  956|     34|			}
  957|     37|		}
  958|    511|	}
  959|       |
  960|    690|	if (priv->bcd_version >= OPENPGP_CARD_3_1) {
  ------------------
  |  Branch (960:6): [True: 368, False: 322]
  ------------------
  961|    368|		card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    368|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  962|    368|	}
  963|       |
  964|    690|	if (priv->bcd_version >= OPENPGP_CARD_3_4) {
  ------------------
  |  Branch (964:6): [True: 366, False: 324]
  ------------------
  965|       |		/* Parse supported algorithms from Algorithm Information DO
  966|       |		 * see OpenPGP card spec 3.4 section 4.4.3.11 */
  967|    366|		if (pgp_get_blob(card, priv->mf, 0x00fa, &blobfa) >= 0) {
  ------------------
  |  Branch (967:7): [True: 366, False: 0]
  ------------------
  968|    366|			pgp_blob_t *child;
  969|    366|			pgp_enumerate_blob(card, blobfa);
  970|       |			/* There will be multiple children with the same ID, but
  971|       |			 * different algos, so we need to iterate over all of them */
  972|  17.7k|			for (child = blobfa->files; child; child = child->next) {
  ------------------
  |  Branch (972:32): [True: 17.4k, False: 366]
  ------------------
  973|  17.4k|				if ((child->id < 0x00c1) || (child->id > 0x00c3))
  ------------------
  |  Branch (973:9): [True: 5.02k, False: 12.3k]
  |  Branch (973:33): [True: 2.18k, False: 10.1k]
  ------------------
  974|  7.21k|					continue;
  975|  10.1k|				sc_cardctl_openpgp_key_gen_store_info_t key_info;
  976|  10.1k|				if (pgp_parse_algo_attr_blob(card, child, &key_info) >= 0)
  ------------------
  |  Branch (976:9): [True: 785, False: 9.40k]
  ------------------
  977|    785|					handled_algos += _pgp_add_algo(card, &key_info, 0x00fa);
  978|  10.1k|			}
  979|    366|		}
  980|    366|	}
  981|       |
  982|       |	/* v1.1 & v2.x: special DOs are limited to 254 bytes */
  983|    690|	priv->max_specialDO_size = 254;
  984|       |
  985|    690|	if ((pgp_get_blob(card, priv->mf, 0x006e, &blob6e) >= 0) &&
  ------------------
  |  Branch (985:6): [True: 690, False: 0]
  ------------------
  986|    690|	    (pgp_get_blob(card, blob6e, 0x0073, &blob73) >= 0)) {
  ------------------
  |  Branch (986:6): [True: 171, False: 519]
  ------------------
  987|       |
  988|       |		/* get "extended capabilities" DO */
  989|    171|		if ((pgp_get_blob(card, blob73, 0x00c0, &blob) >= 0) &&
  ------------------
  |  Branch (989:7): [True: 46, False: 125]
  ------------------
  990|     46|		    (blob->data != NULL) && (blob->len > 0)) {
  ------------------
  |  Branch (990:7): [True: 45, False: 1]
  |  Branch (990:31): [True: 45, False: 0]
  ------------------
  991|     45|			if ((blob->data[0] & 0x01) && (priv->bcd_version >= OPENPGP_CARD_3_3)) {
  ------------------
  |  Branch (991:8): [True: 24, False: 21]
  |  Branch (991:34): [True: 20, False: 4]
  ------------------
  992|     20|				priv->ext_caps |= EXT_CAP_KDF_DO;
  993|     20|			}
  994|       |			/* v2.0+: bit 0x04 in first byte means "algorithm attributes changeable" */
  995|     45|			if ((blob->data[0] & 0x04) &&
  ------------------
  |  Branch (995:8): [True: 41, False: 4]
  ------------------
  996|     41|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (996:6): [True: 39, False: 2]
  ------------------
  997|     39|				priv->ext_caps |= EXT_CAP_ALG_ATTR_CHANGEABLE;
  998|       |			/* bit 0x08 in first byte means "support for private use DOs" */
  999|     45|			if (blob->data[0] & 0x08)
  ------------------
  |  Branch (999:8): [True: 6, False: 39]
  ------------------
 1000|      6|				priv->ext_caps |= EXT_CAP_PRIVATE_DO;
 1001|       |			/* bit 0x10 in first byte means "support for CHV status byte changeable" */
 1002|     45|			if (blob->data[0] & 0x10)
  ------------------
  |  Branch (1002:8): [True: 16, False: 29]
  ------------------
 1003|     16|				priv->ext_caps |= EXT_CAP_C4_CHANGEABLE;
 1004|       |			/* bit 0x20 in first byte means "support for Key Import" */
 1005|     45|			if (blob->data[0] & 0x20)
  ------------------
  |  Branch (1005:8): [True: 13, False: 32]
  ------------------
 1006|     13|				priv->ext_caps |= EXT_CAP_KEY_IMPORT;
 1007|       |			/* bit 0x40 in first byte means "support for Get Challenge" */
 1008|     45|			if (blob->data[0] & 0x40) {
  ------------------
  |  Branch (1008:8): [True: 10, False: 35]
  ------------------
 1009|     10|				card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     10|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 1010|     10|				priv->ext_caps |= EXT_CAP_GET_CHALLENGE;
 1011|     10|			}
 1012|       |			/* v2.0+: bit 0x80 in first byte means "support Secure Messaging" */
 1013|     45|			if ((blob->data[0] & 0x80) &&
  ------------------
  |  Branch (1013:8): [True: 15, False: 30]
  ------------------
 1014|     15|					(priv->bcd_version >= OPENPGP_CARD_2_0))
  ------------------
  |  Branch (1014:6): [True: 13, False: 2]
  ------------------
 1015|     13|				priv->ext_caps |= EXT_CAP_SM;
 1016|       |
 1017|     45|			if ((priv->bcd_version >= OPENPGP_CARD_2_0) && (blob->len >= 10)) {
  ------------------
  |  Branch (1017:8): [True: 43, False: 2]
  |  Branch (1017:51): [True: 22, False: 21]
  ------------------
 1018|       |				/* v2.0+: max. challenge size is at bytes 3-4 */
 1019|     22|				priv->max_challenge_size = bebytes2ushort(blob->data + 2);
 1020|       |				/* v2.0+: max. cert size it at bytes 5-6 */
 1021|     22|				priv->max_cert_size = bebytes2ushort(blob->data + 4);
 1022|       |
 1023|     22|				if (priv->bcd_version < OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1023:9): [True: 6, False: 16]
  ------------------
 1024|       |					/* v2.x: SM algorithm is at byte 2: 0 == 3DES */
 1025|      6|					priv->sm_algo = blob->data[1];
 1026|      6|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1026:10): [True: 4, False: 2]
  |  Branch (1026:45): [True: 1, False: 3]
  ------------------
 1027|      1|						priv->sm_algo = SM_ALGO_3DES;
 1028|       |
 1029|       |					/* v2.x: max. send/receive sizes are at bytes 7-8 resp. 9-10 */
 1030|      6|					card->max_send_size = bebytes2ushort(blob->data + 6);
 1031|      6|					card->max_recv_size = bebytes2ushort(blob->data + 8);
 1032|      6|				}
 1033|     16|				else {
 1034|       |					/* v3.0+: SM algorithm is at byte 2: 0 == UNKNOWN */
 1035|     16|					priv->sm_algo = blob->data[1];
 1036|     16|					if ((priv->sm_algo == SM_ALGO_NONE) && (priv->ext_caps & EXT_CAP_SM))
  ------------------
  |  Branch (1036:10): [True: 10, False: 6]
  |  Branch (1036:45): [True: 7, False: 3]
  ------------------
 1037|      7|						priv->sm_algo = SM_ALGO_UNKNOWN;
 1038|       |
 1039|       |					/* v3.0+: max. size of special DOs is at bytes 7-8 */
 1040|     16|					priv->max_specialDO_size = bebytes2ushort(blob->data + 6);
 1041|     16|				}
 1042|     22|				if (priv->bcd_version >= OPENPGP_CARD_3_3 && (blob->len >= 10)) {
  ------------------
  |  Branch (1042:9): [True: 16, False: 6]
  |  Branch (1042:50): [True: 16, False: 0]
  ------------------
 1043|       |					/* v3.3+: MSE for key numbers 2(DEC) and 3(AUT) supported */
 1044|     16|					if (blob->data[9])
  ------------------
  |  Branch (1044:10): [True: 10, False: 6]
  ------------------
 1045|     10|						priv->ext_caps |= EXT_CAP_MSE;
 1046|     16|				}
 1047|     22|			}
 1048|     45|		}
 1049|       |
 1050|       |		/* get max. PIN length from "CHV status bytes" DO */
 1051|    171|		if ((pgp_get_blob(card, blob73, 0x00c4, &blob) >= 0) &&
  ------------------
  |  Branch (1051:7): [True: 131, False: 40]
  ------------------
 1052|    131|			(blob->data != NULL) && (blob->len > 1)) {
  ------------------
  |  Branch (1052:4): [True: 129, False: 2]
  |  Branch (1052:28): [True: 128, False: 1]
  ------------------
 1053|       |			/* 2nd byte in "CHV status bytes" DO means "max. PIN length" */
 1054|    128|			card->max_pin_len = blob->data[1];
 1055|    128|		}
 1056|       |
 1057|    171|		if (priv->bcd_version >= OPENPGP_CARD_3_0) {
  ------------------
  |  Branch (1057:7): [True: 114, False: 57]
  ------------------
 1058|       |			/* v3.0+: get length info from "extended length information" DO */
 1059|    114|			if ((pgp_get_blob(card, blob6e, 0x7f66, &blob) >= 0) &&
  ------------------
  |  Branch (1059:8): [True: 3, False: 111]
  ------------------
 1060|      3|				(blob->data != NULL) && (blob->len >= 8)) {
  ------------------
  |  Branch (1060:5): [True: 2, False: 1]
  |  Branch (1060:29): [True: 1, False: 1]
  ------------------
 1061|       |				/* kludge: treat as SIMPLE DO and use appropriate offsets */
 1062|      1|				card->max_send_size = bebytes2ushort(blob->data + 2);
 1063|      1|				card->max_recv_size = bebytes2ushort(blob->data + 6);
 1064|      1|			}
 1065|    114|		}
 1066|       |
 1067|    171|#ifdef ENABLE_OPENSSL
 1068|    171|		if (priv->ext_caps & EXT_CAP_KDF_DO) {
  ------------------
  |  Branch (1068:7): [True: 20, False: 151]
  ------------------
 1069|     20|			int r = pgp_decode_kdf_do(card, priv);
 1070|     20|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
  |  Branch (1070:8): [True: 19, False: 1]
  ------------------
 1071|     19|				sc_log(card->ctx, "Failed to decode KDF DO: %s", sc_strerror(r));
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1072|     19|			}
 1073|     20|		}
 1074|    171|#endif /* ENABLE_OPENSSL */
 1075|       |
 1076|       |		/* if we found at least one usable algo, let's skip other ways to find them */
 1077|    171|		if (handled_algos) {
  ------------------
  |  Branch (1077:7): [True: 0, False: 171]
  ------------------
 1078|      0|			sc_log(card->ctx, "Algo list populated from Algorithm Information DO");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1079|      0|			LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1080|      0|		}
 1081|       |
 1082|       |		/* get _current_ algorithms & key lengths from "algorithm attributes" DOs
 1083|       |		 *
 1084|       |		 * All available algorithms should be already provided by pgp_init. However, if another
 1085|       |		 * algorithm is found in the "algorithm attributes" DOs, it is supported by the card as
 1086|       |		 * well and therefore added
 1087|       |		 * see OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1088|    684|		for (i = 0x00c1; i <= 0x00c3; i++) {
  ------------------
  |  Branch (1088:20): [True: 513, False: 171]
  ------------------
 1089|    513|			sc_cardctl_openpgp_key_gen_store_info_t key_info;
 1090|       |
 1091|    513|			sc_log(card->ctx, "Parsing algorithm attributes DO %uX" , i);
  ------------------
  |  |   71|    513|#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|       |
 1093|       |			/* OpenPGP card spec 1.1 & 2.x section 4.3.3.6 / v3.x section 4.4.3.7 */
 1094|    513|			if ((pgp_get_blob(card, blob73, i, &blob) >= 0) &&
  ------------------
  |  Branch (1094:8): [True: 354, False: 159]
  ------------------
 1095|    354|			    (pgp_parse_algo_attr_blob(card, blob, &key_info) >= 0)) {
  ------------------
  |  Branch (1095:8): [True: 229, False: 125]
  ------------------
 1096|    229|				if (!_pgp_add_algo(card, &key_info, i))
  ------------------
  |  Branch (1096:9): [True: 0, False: 229]
  ------------------
 1097|    229|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1098|    229|			}
 1099|    513|		}
 1100|       |
 1101|    171|	}
 1102|       |
 1103|    690|	LOG_FUNC_RETURN(card->ctx, handled_algos);
  ------------------
  |  |  164|    690|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    690|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    690|	int _ret = r; \
  |  |  |  |  155|    690|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 656, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  156|    656|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 656]
  |  |  |  |  ------------------
  |  |  |  |  157|    656|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    656|	} else { \
  |  |  |  |  159|     34|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     34|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     34|	} \
  |  |  |  |  162|    690|	return _ret; \
  |  |  |  |  163|    690|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1104|    690|}
card-openpgp.c:pgp_parse_hist_bytes:
  600|    192|{
  601|    192|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    192|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
  602|    192|	const u8 *ptr;
  603|       |
  604|       |	/* IS07816-4 hist bytes: 3rd function table */
  605|    192|	if ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x73, NULL)) != NULL) {
  ------------------
  |  Branch (605:6): [True: 143, False: 49]
  ------------------
  606|       |		/* bit 0x40 in byte 3 of TL 0x73 means "extended Le/Lc" */
  607|    143|		if (ptr[2] & 0x40) {
  ------------------
  |  Branch (607:7): [True: 8, False: 135]
  ------------------
  608|      8|			card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|      8|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  609|      8|			priv->ext_caps |= EXT_CAP_APDU_EXT;
  610|      8|		}
  611|       |		/* bit 0x80 in byte 3 of TL 0x73 means "Command chaining" */
  612|    143|		if (ptr[2] & 0x80) {
  ------------------
  |  Branch (612:7): [True: 132, False: 11]
  ------------------
  613|    132|			priv->ext_caps |= EXT_CAP_CHAINING;
  614|    132|		}
  615|    143|	}
  616|       |
  617|    192|	if ((priv->bcd_version >= OPENPGP_CARD_3_0) &&
  ------------------
  |  Branch (617:6): [True: 46, False: 146]
  ------------------
  618|     46|	    ((ptr = sc_compacttlv_find_tag(ctlv, ctlv_len, 0x31, NULL)) != NULL)) {
  ------------------
  |  Branch (618:6): [True: 18, False: 28]
  ------------------
  619|       |		// ToDo ...
  620|     18|	}
  621|    192|}
card-openpgp.c:pgp_decode_kdf_do:
  802|     20|{
  803|     20|	pgp_pin_kdf_info_t *pin_kdf_info = (pgp_pin_kdf_info_t *)calloc(1, sizeof(pgp_pin_kdf_info_t));
  804|     20|	int r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|     20|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  805|     20|	pgp_blob_t *kdf_blob;
  806|     20|	const uint8_t *data;
  807|     20|	size_t data_len;
  808|     20|	size_t tag_len;
  809|     20|	const uint8_t *p;
  810|     20|	pgp_blob_t *blob;
  811|       |
  812|     20|	if (!pin_kdf_info) {
  ------------------
  |  Branch (812:6): [True: 0, False: 20]
  ------------------
  813|      0|		return r;
  814|      0|	}
  815|       |
  816|     20|	r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     20|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  817|     20|	priv->pin_kdf_info = NULL;
  818|     20|	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |  159|     20|#define DO_KDF                   0xf9
  ------------------
              	if ((pgp_get_blob(card, priv->mf, DO_KDF, &kdf_blob) != SC_SUCCESS) || (kdf_blob->len < 3)) {
  ------------------
  |  |   28|     20|#define SC_SUCCESS				0
  ------------------
  |  Branch (818:6): [True: 0, False: 20]
  |  Branch (818:73): [True: 6, False: 14]
  ------------------
  819|      6|		sc_log(card->ctx, "KDF DO does not exists or contains invalid data but card claims to support it");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  820|      6|		goto out;
  821|      6|	}
  822|       |
  823|     14|	data = kdf_blob->data;
  824|     14|	data_len = kdf_blob->len;
  825|     14|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x81, &tag_len);
  826|     14|	if (!p) {
  ------------------
  |  Branch (826:6): [True: 1, False: 13]
  ------------------
  827|      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__
  |  |  ------------------
  ------------------
  828|      1|		goto out;
  829|      1|	}
  830|     13|	if (tag_len != 1) {
  ------------------
  |  Branch (830:6): [True: 1, False: 12]
  ------------------
  831|      1|		sc_log(card->ctx, "Unexpected KDF algorithm byte length, expects 1, got %" SC_FORMAT_LEN_SIZE_T "u", 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__
  |  |  ------------------
  ------------------
  832|      1|		goto out;
  833|      1|	}
  834|       |
  835|     12|	if (*p != 0x3) {
  ------------------
  |  Branch (835:6): [True: 2, False: 10]
  ------------------
  836|      2|		if (*p == 0x0) {
  ------------------
  |  Branch (836:7): [True: 1, False: 1]
  ------------------
  837|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  838|      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__
  |  |  ------------------
  ------------------
  839|      1|		} else {
  840|      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__
  |  |  ------------------
  ------------------
  841|      1|		}
  842|      2|		goto out;
  843|      2|	}
  844|       |
  845|     10|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x82, &tag_len);
  846|     10|	if (!p) {
  ------------------
  |  Branch (846:6): [True: 5, False: 5]
  ------------------
  847|      5|		sc_log(card->ctx, "KDF hash algorithm byte not found");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  848|      5|		goto out;
  849|      5|	}
  850|      5|	if (tag_len != 1) {
  ------------------
  |  Branch (850:6): [True: 1, False: 4]
  ------------------
  851|      1|		sc_log(card->ctx, "Unexpected KDF hash algorithm byte length, expects 1, got %" SC_FORMAT_LEN_SIZE_T "u", 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__
  |  |  ------------------
  ------------------
  852|      1|		goto out;
  853|      1|	}
  854|       |
  855|      4|	switch (*p) {
  856|      1|	case 0x08:
  ------------------
  |  Branch (856:2): [True: 1, False: 3]
  ------------------
  857|      1|		pin_kdf_info->hash_algo = "SHA256";
  858|      1|		break;
  859|      2|	case 0x0A:
  ------------------
  |  Branch (859:2): [True: 2, False: 2]
  ------------------
  860|      2|		pin_kdf_info->hash_algo = "SHA512";
  861|      2|		break;
  862|      1|	default:
  ------------------
  |  Branch (862:2): [True: 1, False: 3]
  ------------------
  863|      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__
  |  |  ------------------
  ------------------
  864|      1|		goto out;
  865|      4|	}
  866|       |
  867|      3|	p = sc_asn1_find_tag(card->ctx, data, data_len, 0x83, &tag_len);
  868|      3|	if (!p) {
  ------------------
  |  Branch (868:6): [True: 2, False: 1]
  ------------------
  869|      2|		sc_log(card->ctx, "KDF iteration count not found");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  870|      2|		goto out;
  871|      2|	}
  872|      1|	if (tag_len != 4) {
  ------------------
  |  Branch (872:6): [True: 0, False: 1]
  ------------------
  873|      0|		sc_log(card->ctx, "Unexpected KDF iteration count length, expects 4, got %" SC_FORMAT_LEN_SIZE_T "u", tag_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__
  |  |  ------------------
  ------------------
  874|      0|		goto out;
  875|      0|	}
  876|      1|	pin_kdf_info->iterations = (uint32_t)bebytes2ulong(p);
  877|       |
  878|      1|	r = pgp_get_blob(card, kdf_blob, 0x84, &blob);
  879|      1|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (879:6): [True: 1, False: 0]
  ------------------
  880|      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__
  |  |  ------------------
  ------------------
  881|      1|		goto out;
  882|      1|	}
  883|      0|	pin_kdf_info->userpw_salt = blob;
  884|       |
  885|      0|	r = pgp_get_blob(card, kdf_blob, 0x86, &blob);
  886|      0|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (886:6): [True: 0, False: 0]
  ------------------
  887|      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__
  |  |  ------------------
  ------------------
  888|      0|		goto out;
  889|      0|	}
  890|      0|	pin_kdf_info->adminpw_salt = blob;
  891|       |
  892|      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__
  |  |  ------------------
  ------------------
  893|      0|	priv->pin_kdf_info = pin_kdf_info;
  894|      0|	return r;
  895|     20|out:
  896|     20|	free(pin_kdf_info);
  897|     20|	return r;
  898|      0|}
card-openpgp.c:pgp_finish:
 1112|    713|{
 1113|    713|	if (card != NULL) {
  ------------------
  |  Branch (1113:6): [True: 713, False: 0]
  ------------------
 1114|    713|		struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    713|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1115|       |
 1116|    713|		if (priv != NULL) {
  ------------------
  |  Branch (1116:7): [True: 713, False: 0]
  ------------------
 1117|       |			/* delete fake file hierarchy */
 1118|    713|			pgp_free_blobs(priv->mf);
 1119|       |
 1120|       |			/* delete kdf do related data if exists */
 1121|    713|			free(priv->pin_kdf_info);
 1122|       |
 1123|       |			/* delete private data */
 1124|    713|			free(priv);
 1125|    713|		}
 1126|    713|		card->drv_data = NULL;
 1127|    713|	}
 1128|    713|	return SC_SUCCESS;
  ------------------
  |  |   28|    713|#define SC_SUCCESS				0
  ------------------
 1129|    713|}
card-openpgp.c:pgp_free_blobs:
 1325|  43.1k|{
 1326|  43.1k|	if (blob) {
  ------------------
  |  Branch (1326:6): [True: 43.1k, False: 23]
  ------------------
 1327|  43.1k|		pgp_blob_t *child = blob->files;
 1328|       |
 1329|  85.5k|		while (child != NULL) {
  ------------------
  |  Branch (1329:10): [True: 42.4k, False: 43.1k]
  ------------------
 1330|  42.4k|			pgp_blob_t *next = child->next;
 1331|       |
 1332|  42.4k|			pgp_free_blobs(child);
 1333|  42.4k|			child = next;
 1334|  42.4k|		}
 1335|  43.1k|		pgp_free_blob(blob);
 1336|  43.1k|	}
 1337|  43.1k|}
card-openpgp.c:pgp_free_blob:
 1300|  43.1k|{
 1301|  43.1k|	if (blob) {
  ------------------
  |  Branch (1301:6): [True: 43.1k, False: 0]
  ------------------
 1302|  43.1k|		if (blob->parent) {
  ------------------
  |  Branch (1302:7): [True: 42.4k, False: 690]
  ------------------
 1303|  42.4k|			pgp_blob_t **p;
 1304|       |
 1305|       |			/* remove blob from list of parent's children */
 1306|  42.4k|			for (p = &blob->parent->files; *p != NULL && *p != blob; p = &(*p)->next)
  ------------------
  |  Branch (1306:35): [True: 42.4k, False: 0]
  |  Branch (1306:49): [True: 0, False: 42.4k]
  ------------------
 1307|      0|				;
 1308|  42.4k|			if (*p == blob)
  ------------------
  |  Branch (1308:8): [True: 42.4k, False: 0]
  ------------------
 1309|  42.4k|				*p = blob->next;
 1310|  42.4k|		}
 1311|       |
 1312|  43.1k|		sc_file_free(blob->file);
 1313|  43.1k|		if (blob->data)
  ------------------
  |  Branch (1313:7): [True: 15.5k, False: 27.6k]
  ------------------
 1314|  15.5k|			free(blob->data);
 1315|  43.1k|		free(blob);
 1316|  43.1k|	}
 1317|  43.1k|}
card-openpgp.c:pgp_select_file:
 1611|  6.24k|{
 1612|  6.24k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  6.24k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1613|  6.24k|	pgp_blob_t	*blob;
 1614|  6.24k|	unsigned int	path_start = 0;
 1615|  6.24k|	unsigned int	n;
 1616|  6.24k|	sc_path_t dummy_path;
 1617|       |
 1618|  6.24k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  6.24k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  6.24k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  6.24k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  6.24k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 6.24k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1619|       |
 1620|  6.24k|	if (path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  6.24k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (1620:6): [True: 1.06k, False: 5.17k]
  ------------------
 1621|  6.24k|		LOG_FUNC_RETURN(card->ctx, iso_ops->select_file(card, path, ret));
  ------------------
  |  |  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.00k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.00k, False: 66]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1622|       |
 1623|  5.17k|	if (path->len < 2 || (path->len & 1))
  ------------------
  |  Branch (1623:6): [True: 0, False: 5.17k]
  |  Branch (1623:23): [True: 0, False: 5.17k]
  ------------------
 1624|  5.17k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1625|  5.17k|				"invalid path length");
 1626|       |
 1627|  5.17k|	if (path->type == SC_PATH_TYPE_FILE_ID && path->len != 2)
  ------------------
  |  |  117|  10.3k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (1627:6): [True: 0, False: 5.17k]
  |  Branch (1627:44): [True: 0, False: 0]
  ------------------
 1628|  5.17k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1629|  5.17k|				"invalid path type");
 1630|       |
 1631|       |	/* Due to pkcs15init implementation, sometimes a file at path "11001101"
 1632|       |	 * need to be written (one use case is when importing key&cert from p12 file).
 1633|       |	 * This file does not exist in OpenPGP but pkcs15 requires that
 1634|       |	 * writing this file must be successful.
 1635|       |	 * So, we pretend that selecting & writing this file is successful.
 1636|       |	 * The "11001101"is defined in sc_pkcs15emu_get_df() function, pkcs15-sync.c file. */
 1637|  5.17k|	sc_format_path("11001101", &dummy_path);
 1638|  5.17k|	if (sc_compare_path(path, &dummy_path)) {
  ------------------
  |  Branch (1638:6): [True: 0, False: 5.17k]
  ------------------
 1639|      0|		if (ret != NULL) {
  ------------------
  |  Branch (1639:7): [True: 0, False: 0]
  ------------------
 1640|      0|			*ret = sc_file_new();
 1641|       |			/* One use case of this dummy file is after writing certificate in pkcs15init.
 1642|       |			 * So we set its size to be the same as max certificate size the card supports. */
 1643|      0|			(*ret)->size = priv->max_cert_size;
 1644|      0|		}
 1645|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1646|      0|	}
 1647|       |
 1648|       |	/* ignore explicitly mentioned MF at the path's beginning */
 1649|  5.17k|	path_start = pgp_strip_path(card, path);
 1650|       |
 1651|       |	/* starting with the MF ... */
 1652|  5.17k|	blob = priv->mf;
 1653|       |	/* ... recurse through the tree following the path */
 1654|  10.5k|	for (n = path_start; n < path->len; n += 2) {
  ------------------
  |  Branch (1654:23): [True: 7.12k, False: 3.38k]
  ------------------
 1655|  7.12k|		unsigned int	id = bebytes2ushort(path->value + n);
 1656|  7.12k|		int		r = pgp_get_blob(card, blob, id, &blob);
 1657|       |
 1658|       |		/* This file ID is referred when importing key&certificate via pkcs15init, like above.
 1659|       |		 * We pretend to successfully find this inexistent file. */
 1660|  7.12k|		if (id == 0x4402 || id == 0x5f48) {
  ------------------
  |  Branch (1660:7): [True: 0, False: 7.12k]
  |  Branch (1660:23): [True: 0, False: 7.12k]
  ------------------
 1661|      0|			if (ret == NULL)
  ------------------
  |  Branch (1661:8): [True: 0, False: 0]
  ------------------
 1662|       |				/* No need to return file */
 1663|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1664|       |
 1665|       |			/* Else, need to return file */
 1666|      0|			*ret = sc_file_new();
 1667|      0|			(*ret)->size = priv->max_cert_size;
 1668|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1669|      0|		}
 1670|       |
 1671|  7.12k|		if (r < 0) {	/* failure */
  ------------------
  |  Branch (1671:7): [True: 1.78k, False: 5.33k]
  ------------------
 1672|  1.78k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1673|  1.78k|		}
 1674|  7.12k|	}
 1675|       |
 1676|       |	/* success: select file = set "current" pointer to blob found */
 1677|  3.38k|	priv->current = blob;
 1678|       |
 1679|  3.38k|	if (ret)
  ------------------
  |  Branch (1679:6): [True: 1.82k, False: 1.56k]
  ------------------
 1680|  1.82k|		sc_file_dup(ret, blob->file);
 1681|       |
 1682|  3.38k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  3.38k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  3.38k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  3.38k|	int _ret = r; \
  |  |  |  |  155|  3.38k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 3.38k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  3.38k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 3.38k]
  |  |  |  |  ------------------
  |  |  |  |  157|  3.38k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  3.38k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  3.38k|	return _ret; \
  |  |  |  |  163|  3.38k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1683|  3.38k|}
card-openpgp.c:pgp_strip_path:
 1592|  5.17k|{
 1593|  5.17k|	unsigned int start_point = 0;
 1594|       |	/* start_point will move through the path string */
 1595|  5.17k|	if (path->len == 0)
  ------------------
  |  Branch (1595:6): [True: 0, False: 5.17k]
  ------------------
 1596|      0|		return 0;
 1597|       |
 1598|       |	/* ignore 3F00 (MF) at the beginning */
 1599|  5.17k|	start_point = (memcmp(path->value, "\x3f\x00", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1599:16): [True: 2.87k, False: 2.29k]
  ------------------
 1600|       |	/* strip path of PKCS15-App DF (5015) */
 1601|  5.17k|	start_point += (memcmp(path->value + start_point, "\x50\x15", 2) == 0) ? 2 : 0;
  ------------------
  |  Branch (1601:17): [True: 1.21k, False: 3.95k]
  ------------------
 1602|  5.17k|	return start_point;
 1603|  5.17k|}
card-openpgp.c:pgp_read_binary:
 1752|  1.52k|{
 1753|  1.52k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  1.52k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1754|  1.52k|	pgp_blob_t	*blob;
 1755|  1.52k|	int		r;
 1756|       |
 1757|  1.52k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.52k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.52k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.52k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.52k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.52k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1758|       |
 1759|       |	/* jump to selected file */
 1760|  1.52k|	blob = priv->current;
 1761|       |
 1762|  1.52k|	if (blob == NULL)
  ------------------
  |  Branch (1762:6): [True: 0, False: 1.52k]
  ------------------
 1763|  1.52k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1764|       |
 1765|  1.52k|	if (blob->file->type != SC_FILE_TYPE_WORKING_EF)
  ------------------
  |  |  216|  1.52k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  |  Branch (1765:6): [True: 0, False: 1.52k]
  ------------------
 1766|  1.52k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1767|       |
 1768|  1.52k|	if ((r = pgp_read_blob(card, blob)) < 0)
  ------------------
  |  Branch (1768:6): [True: 0, False: 1.52k]
  ------------------
 1769|  1.52k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1770|       |
 1771|  1.52k|	if (idx > blob->len)
  ------------------
  |  Branch (1771:6): [True: 0, False: 1.52k]
  ------------------
 1772|  1.52k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1773|       |
 1774|  1.52k|	if (idx + count > blob->len)
  ------------------
  |  Branch (1774:6): [True: 0, False: 1.52k]
  ------------------
 1775|      0|		count = blob->len - idx;
 1776|  1.52k|	memcpy(buf, blob->data + idx, count);
 1777|       |
 1778|  1.52k|	LOG_FUNC_RETURN(card->ctx, (int)count);
  ------------------
  |  |  164|  1.52k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.52k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.52k|	int _ret = r; \
  |  |  |  |  155|  1.52k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.52k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.52k|	} else { \
  |  |  |  |  159|  1.52k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.52k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.52k|	} \
  |  |  |  |  162|  1.52k|	return _ret; \
  |  |  |  |  163|  1.52k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1779|  1.52k|}
card-openpgp.c:pgp_pin_cmd:
 2389|  1.02k|{
 2390|  1.02k|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|  1.02k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2391|  1.02k|	struct sc_card_operations ops = {.pin_cmd = iso_ops->pin_cmd};
 2392|       |
 2393|  1.02k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  1.02k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  1.02k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  1.02k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  1.02k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 1.02k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2394|       |
 2395|  1.02k|	if (data->pin_type != SC_AC_CHV)
  ------------------
  |  |  151|  1.02k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (2395:6): [True: 0, False: 1.02k]
  ------------------
 2396|  1.02k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2397|  1.02k|				"invalid PIN type");
 2398|       |
 2399|       |	/* In general, the PIN Reference is extracted from the key-id,
 2400|       |	 * for example, CHV0 -> Ref=0, CHV1 -> Ref=1.
 2401|       |	 * However, in the case of OpenPGP, the PIN Ref to compose APDU
 2402|       |	 * must be 81, 82, 83.
 2403|       |	 * So, if we receive Ref=1, Ref=2, we must convert to 81, 82...
 2404|       |	 * In OpenPGP v1, the PINs are named CHV1, CHV2, CHV3.
 2405|       |	 * In v2, they are named PW1, PW3 (PW1 operates in 2 modes).
 2406|       |	 *
 2407|       |	 * The PIN references (P2 in APDU) for "VERIFY" are the same in both versions:
 2408|       |	 * 81 (CHV1 or PW1), 82 (CHV2 or PW1-mode 2), 83 (CHV3 or PW3),
 2409|       |	 * On the other hand from version 2.0 "CHANGE REFERENCE DATA" and
 2410|       |	 * "RESET RETRY COUNTER" don't support PW1-mode 2 (82) and need this
 2411|       |	 * value changed to PW1 (81).
 2412|       |	 * Both of these commands also differ between card versions in that
 2413|       |	 * v1 cards can use only implicit old PIN or CHV3 test for both commands
 2414|       |	 * whereas v2 can use both implicit (for PW3) and explicit
 2415|       |	 * (for special "Resetting Code") PIN test for "RESET RETRY COUNTER"
 2416|       |	 * and only explicit test for "CHANGE REFERENCE DATA".
 2417|       |	 *
 2418|       |	 * Note that if this function is called from sc_pkcs15_verify_pin() in pkcs15-pin.c,
 2419|       |	 * the Ref is already 81, 82, 83.
 2420|       |	 */
 2421|       |
 2422|       |	/* convert the PIN Reference if needed */
 2423|  1.02k|	data->pin_reference |= 0x80;
 2424|       |
 2425|       |	/* check version-dependent constraints */
 2426|  1.02k|	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  423|  2.05k|#define SC_PIN_CMD_CHANGE	1
  ------------------
              	if (data->cmd == SC_PIN_CMD_CHANGE || data->cmd == SC_PIN_CMD_UNBLOCK) {
  ------------------
  |  |  424|    913|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2426:6): [True: 116, False: 913]
  |  Branch (2426:40): [True: 103, False: 810]
  ------------------
 2427|    219|		if (priv->bcd_version >= OPENPGP_CARD_2_0) {
  ------------------
  |  Branch (2427:7): [True: 207, False: 12]
  ------------------
 2428|    207|			if (data->pin_reference == 0x82)
  ------------------
  |  Branch (2428:8): [True: 81, False: 126]
  ------------------
 2429|     81|				data->pin_reference = 0x81;
 2430|       |
 2431|    207|			if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  423|    207|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (2431:8): [True: 110, False: 97]
  ------------------
 2432|    110|				if (data->pin1.len == 0 &&
  ------------------
  |  Branch (2432:9): [True: 0, False: 110]
  ------------------
 2433|      0|				    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2433:9): [True: 0, False: 0]
  ------------------
 2434|    110|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2435|    110|							"v2 cards don't support implicit old PIN for PIN change");
 2436|       |
 2437|    110|				data->flags &= ~SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|    110|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2438|    110|			}
 2439|    207|		} else {
 2440|     12|			if (data->pin1.len != 0) {
  ------------------
  |  Branch (2440:8): [True: 12, False: 0]
  ------------------
 2441|     12|				sc_log(card->ctx,
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2442|     12|				       "v1 cards don't support explicit old or CHV3 PIN, PIN ignored.");
 2443|     12|				sc_log(card->ctx,
  ------------------
  |  |   71|     12|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2444|     12|				       "please make sure that you have verified the relevant PIN first.");
 2445|     12|				data->pin1.len = 0;
 2446|     12|			}
 2447|       |
 2448|     12|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|     12|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 2449|     12|		}
 2450|    219|	}
 2451|       |
 2452|  1.02k|	if (data->cmd == SC_PIN_CMD_UNBLOCK && data->pin2.len == 0 &&
  ------------------
  |  |  424|  2.05k|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (2452:6): [True: 103, False: 926]
  |  Branch (2452:41): [True: 0, False: 103]
  ------------------
 2453|      0|	    !(data->flags & SC_PIN_CMD_USE_PINPAD))
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (2453:6): [True: 0, False: 0]
  ------------------
 2454|  1.02k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2455|  1.02k|				"new PIN must be provided for unblock operation");
 2456|       |
 2457|       |	/* ensure pin_reference is 81, 82, 83 */
 2458|  1.02k|	if (data->pin_reference < 0x81 || data->pin_reference > 0x83)
  ------------------
  |  Branch (2458:6): [True: 16, False: 1.01k]
  |  Branch (2458:36): [True: 0, False: 1.01k]
  ------------------
 2459|  1.02k|		LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
  ------------------
  |  |  174|     16|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     16|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     16|	int _ret = (r); \
  |  |  |  |  168|     16|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     16|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     16|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     16|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     16|		return _ret; \
  |  |  |  |  172|     16|	} \
  |  |  |  |  173|     16|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2460|  1.01k|				"Invalid key ID; must be 1, 2, or 3");
 2461|       |
 2462|       |	/* emulate SC_PIN_CMD_GET_INFO command for cards not supporting it */
 2463|  1.01k|	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  425|  2.02k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
              	if (data->cmd == SC_PIN_CMD_GET_INFO && (card->caps & SC_CARD_CAP_ISO7816_PIN_INFO) == 0) {
  ------------------
  |  |  560|    578|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (2463:6): [True: 578, False: 435]
  |  Branch (2463:42): [True: 264, False: 314]
  ------------------
 2464|    264|		u8 c4data[10];
 2465|    264|		int r;
 2466|       |
 2467|    264|		r = sc_get_data(card, 0x00c4, c4data, sizeof(c4data));
 2468|    264|		LOG_TEST_RET(card->ctx, r, "reading CHV status bytes failed");
  ------------------
  |  |  174|    264|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    264|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    264|	int _ret = (r); \
  |  |  |  |  168|    264|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 248, False: 16]
  |  |  |  |  ------------------
  |  |  |  |  169|    248|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    248|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    248|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    248|		return _ret; \
  |  |  |  |  172|    248|	} \
  |  |  |  |  173|    264|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 16]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2469|       |
 2470|     16|		if (r != 7)
  ------------------
  |  Branch (2470:7): [True: 13, False: 3]
  ------------------
 2471|     16|			LOG_TEST_RET(card->ctx, SC_ERROR_OBJECT_NOT_VALID,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2472|      3|				"CHV status bytes have unexpected length");
 2473|       |
 2474|       |		/* The definition of fields of DO C4 changed between OpenPGP
 2475|       |		 * card specification v1.1 and v2.0. There is no longer a separate
 2476|       |		 * CHV2 retry counter but only one retry counter for both PW1 mode 1
 2477|       |		 * and mode 2 at byte 5 (count from 1) of the DO.
 2478|       |		 */
 2479|      3|		if (priv->bcd_version >= OPENPGP_CARD_2_0 && data->pin_reference == 0x82)
  ------------------
  |  Branch (2479:7): [True: 2, False: 1]
  |  Branch (2479:48): [True: 1, False: 1]
  ------------------
 2480|      1|			data->pin_reference = 0x81;
 2481|       |
 2482|      3|		data->pin1.tries_left = c4data[3 + (data->pin_reference & 0x0F)];
 2483|      3|		data->pin1.max_tries = 3;
 2484|      3|		data->pin1.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      3|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 2485|      3|		if (tries_left != NULL)
  ------------------
  |  Branch (2485:7): [True: 0, False: 3]
  ------------------
 2486|      0|			*tries_left = data->pin1.tries_left;
 2487|       |
 2488|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2489|      3|	}
 2490|       |
 2491|    749|#ifdef ENABLE_OPENSSL
 2492|    749|	if (priv->pin_kdf_info) {
  ------------------
  |  Branch (2492:6): [True: 0, False: 749]
  ------------------
 2493|      0|		ops.pin_cmd = &pgp_kdf_do_pin_cmd;
 2494|      0|	}
 2495|    749|#endif /* ENABLE_OPENSSL */
 2496|       |
 2497|    749|	LOG_FUNC_RETURN(card->ctx, ops.pin_cmd(card, data, tries_left));
  ------------------
  |  |  164|    749|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    749|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    749|	int _ret = r; \
  |  |  |  |  155|    749|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 749, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    749|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    575|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 575, False: 174]
  |  |  |  |  ------------------
  |  |  |  |  157|    749|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    749|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    749|	return _ret; \
  |  |  |  |  163|    749|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2498|    749|}
card-openpgp.c:pgp_get_data:
 1991|  5.59k|{
 1992|  5.59k|	sc_apdu_t	apdu;
 1993|  5.59k|	int		r;
 1994|       |
 1995|  5.59k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.59k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.59k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.59k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.59k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.59k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1996|       |
 1997|  5.59k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xCA, tag >> 8, tag);
  ------------------
  |  |  301|  5.59k|#define SC_APDU_CASE_2			0x22
  ------------------
 1998|  5.59k|	apdu.le = ((buf_len >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : buf_len;
  ------------------
  |  |  554|  4.05k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (1998:13): [True: 4.05k, False: 1.54k]
  |  Branch (1998:33): [True: 4.01k, False: 40]
  ------------------
 1999|  5.59k|	apdu.resp = buf;
 2000|  5.59k|	apdu.resplen = buf_len;
 2001|       |
 2002|  5.59k|	r = sc_transmit_apdu(card, &apdu);
 2003|  5.59k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  5.59k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.59k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.59k|	int _ret = (r); \
  |  |  |  |  168|  5.59k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 35, False: 5.55k]
  |  |  |  |  ------------------
  |  |  |  |  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|  5.59k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.55k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2004|       |
 2005|  5.55k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2006|       |
 2007|       |	/* Gnuk returns an error instead of empty data if there is no certificate or private DO.
 2008|       |	 * So, for this case, we ignore error and consider success */
 2009|  5.55k|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK &&
  ------------------
  |  Branch (2009:6): [True: 1.10k, False: 4.45k]
  ------------------
 2010|  1.10k|	    (tag == DO_CERT  ||
  ------------------
  |  |  138|  2.20k|#define DO_CERT                  0x7f21
  ------------------
  |  Branch (2010:7): [True: 163, False: 940]
  ------------------
 2011|    940|	     tag == DO_PRIV1 ||
  ------------------
  |  |  149|  2.04k|#define DO_PRIV1                 0x0101
  ------------------
  |  Branch (2011:7): [True: 12, False: 928]
  ------------------
 2012|    928|	     tag == DO_PRIV2 ||
  ------------------
  |  |  150|  2.03k|#define DO_PRIV2                 0x0102
  ------------------
  |  Branch (2012:7): [True: 12, False: 916]
  ------------------
 2013|    916|	     tag == DO_PRIV3 ||
  ------------------
  |  |  151|  2.01k|#define DO_PRIV3                 0x0103
  ------------------
  |  Branch (2013:7): [True: 12, False: 904]
  ------------------
 2014|    904|	     tag == DO_PRIV4)) {
  ------------------
  |  |  152|    904|#define DO_PRIV4                 0x0104
  ------------------
  |  Branch (2014:7): [True: 12, False: 892]
  ------------------
 2015|    211|		if (r == SC_ERROR_DATA_OBJECT_NOT_FOUND) {
  ------------------
  |  |   66|    211|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
  |  Branch (2015:7): [True: 1, False: 210]
  ------------------
 2016|      1|			r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 2017|      1|			apdu.resplen = 0;
 2018|      1|		}
 2019|    211|	}
 2020|  5.55k|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|  5.55k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.55k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.55k|	int _ret = (r); \
  |  |  |  |  168|  5.55k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3.50k, False: 2.05k]
  |  |  |  |  ------------------
  |  |  |  |  169|  3.50k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  3.50k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  3.50k|		return _ret; \
  |  |  |  |  172|  3.50k|	} \
  |  |  |  |  173|  5.55k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 2.05k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2021|       |
 2022|  2.05k|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  2.05k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.05k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.05k|	int _ret = r; \
  |  |  |  |  155|  2.05k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 709, False: 1.34k]
  |  |  |  |  ------------------
  |  |  |  |  156|    709|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 709]
  |  |  |  |  ------------------
  |  |  |  |  157|    709|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.34k|	} else { \
  |  |  |  |  159|  1.34k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.34k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.34k|	} \
  |  |  |  |  162|  2.05k|	return _ret; \
  |  |  |  |  163|  2.05k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2023|  2.05k|}
card-openpgp.c:pgp_set_security_env:
 2541|    356|{
 2542|    356|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    356|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2543|       |
 2544|    356|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    356|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    356|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    356|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    356|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 356]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2545|       |
 2546|       |	/* The SC_SEC_ENV_ALG_PRESENT is set always so let it pass for GNUK */
 2547|    356|	if ((env->flags & SC_SEC_ENV_ALG_PRESENT)
  ------------------
  |  |   69|    356|#define SC_SEC_ENV_ALG_PRESENT		0x0010
  ------------------
  |  Branch (2547:6): [True: 356, False: 0]
  ------------------
 2548|    356|		&& (env->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   78|    356|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2548:6): [True: 0, False: 356]
  ------------------
 2549|      0|		&& (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (2549:6): [True: 0, False: 0]
  ------------------
 2550|      0|		&& (card->type != SC_CARD_TYPE_OPENPGP_GNUK))
  ------------------
  |  Branch (2550:6): [True: 0, False: 0]
  ------------------
 2551|    356|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2552|    356|				"only RSA algorithm supported");
 2553|       |
 2554|    356|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || (env->key_ref_len != 1))
  ------------------
  |  |   67|    356|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (2554:6): [True: 0, False: 356]
  |  Branch (2554:52): [True: 0, False: 356]
  ------------------
 2555|    356|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2556|    356|				"exactly one key reference required");
 2557|       |
 2558|    356|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
  ------------------
  |  |   66|    356|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (2558:6): [True: 0, False: 356]
  ------------------
 2559|    356|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2560|    356|			"passing file references not supported");
 2561|       |
 2562|    356|	sc_log(card->ctx, "Key ref %d", env->key_ref[0]);
  ------------------
  |  |   71|    356|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2563|    356|	switch (env->operation) {
 2564|    282|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|    282|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2564:2): [True: 282, False: 74]
  ------------------
 2565|    282|		sc_log(card->ctx, "Operation: Sign.");
  ------------------
  |  |   71|    282|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2566|    282|		if (env->key_ref[0] != 0x00 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2566:7): [True: 127, False: 155]
  |  Branch (2566:34): [True: 0, False: 127]
  ------------------
 2567|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2568|      0|				"Key reference not compatible with "
 2569|      0|				"requested usage");
 2570|      0|		}
 2571|    282|		break;
 2572|    282|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|     74|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2572:2): [True: 74, False: 282]
  ------------------
 2573|     74|		sc_log(card->ctx, "Operation: Decipher.");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2574|       |		/* we allow key ref 2 (auth key) to be used for deciphering */
 2575|     74|		if (env->key_ref[0] != 0x01 && env->key_ref[0] != 0x02) {
  ------------------
  |  Branch (2575:7): [True: 1, False: 73]
  |  Branch (2575:34): [True: 0, False: 1]
  ------------------
 2576|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2577|      0|				"Key reference not compatible with "
 2578|      0|				"requested usage");
 2579|      0|		}
 2580|     74|		break;
 2581|     74|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   59|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2581:2): [True: 0, False: 356]
  ------------------
 2582|      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__
  |  |  ------------------
  ------------------
 2583|      0|		break;
 2584|      0|	default:
  ------------------
  |  Branch (2584:2): [True: 0, False: 356]
  ------------------
 2585|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2586|    356|				"invalid operation");
 2587|    356|	}
 2588|       |
 2589|    356|	priv->sec_env = *env;
 2590|       |
 2591|    356|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    356|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    356|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    356|	int _ret = r; \
  |  |  |  |  155|    356|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 356, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    356|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 356]
  |  |  |  |  ------------------
  |  |  |  |  157|    356|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    356|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    356|	return _ret; \
  |  |  |  |  163|    356|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2592|    356|}
card-openpgp.c:pgp_compute_signature:
 2646|    282|{
 2647|    282|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|    282|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2648|    282|	sc_security_env_t	*env = &priv->sec_env;
 2649|    282|	sc_apdu_t		apdu;
 2650|    282|	u8 apdu_case = (card->type == SC_CARD_TYPE_OPENPGP_GNUK)
  ------------------
  |  Branch (2650:17): [True: 8, False: 274]
  ------------------
 2651|    282|			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  294|      8|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_4;
  ------------------
  |  |  303|    556|#define SC_APDU_CASE_4			0x24
  ------------------
 2652|    282|	int			r;
 2653|       |
 2654|    282|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    282|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    282|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    282|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    282|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 282]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2655|       |
 2656|    282|	if (env->operation != SC_SEC_OPERATION_SIGN)
  ------------------
  |  |   57|    282|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (2656:6): [True: 0, False: 282]
  ------------------
 2657|    282|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2658|    282|				"invalid operation");
 2659|       |
 2660|    282|	switch (env->key_ref[0]) {
 2661|    155|	case 0x00: /* signature key */
  ------------------
  |  Branch (2661:2): [True: 155, False: 127]
  ------------------
 2662|       |		/* PSO SIGNATURE */
 2663|    155|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x9E, 0x9A);
 2664|    155|		break;
 2665|    127|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2665:2): [True: 127, False: 155]
  ------------------
 2666|       |		/* INTERNAL AUTHENTICATE */
 2667|    127|		sc_format_apdu(card, &apdu, apdu_case, 0x88, 0, 0);
 2668|    127|		break;
 2669|      0|	case 0x01:
  ------------------
  |  Branch (2669:2): [True: 0, False: 282]
  ------------------
 2670|      0|	default:
  ------------------
  |  Branch (2670:2): [True: 0, False: 282]
  ------------------
 2671|       |		/* From PKCS #11 point of view, we should be able to use
 2672|       |		 * curve25519 to do digital signature, but it is not how it
 2673|       |		 * is used in OpenPGP so we will not allow it here */
 2674|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2675|    282|			"invalid key reference");
 2676|    282|	}
 2677|       |
 2678|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2679|    282|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  554|    282|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2679:6): [True: 276, False: 6]
  |  Branch (2679:52): [True: 8, False: 268]
  ------------------
 2680|      8|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      8|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2681|       |
 2682|    282|	apdu.lc = data_len;
 2683|    282|	apdu.data = (u8 *)data;
 2684|    282|	apdu.datalen = data_len;
 2685|    282|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  554|    282|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2685:13): [True: 282, False: 0]
  |  Branch (2685:32): [True: 276, False: 6]
  ------------------
 2686|    282|	apdu.resp    = out;
 2687|    282|	apdu.resplen = outlen;
 2688|       |
 2689|    282|	r = sc_transmit_apdu(card, &apdu);
 2690|    282|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    282|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    282|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    282|	int _ret = (r); \
  |  |  |  |  168|    282|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 125, False: 157]
  |  |  |  |  ------------------
  |  |  |  |  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|    282|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 157]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2691|       |
 2692|    157|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2693|    157|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|    157|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    157|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    157|	int _ret = (r); \
  |  |  |  |  168|    157|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 124, False: 33]
  |  |  |  |  ------------------
  |  |  |  |  169|    124|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    124|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    124|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    124|		return _ret; \
  |  |  |  |  172|    124|	} \
  |  |  |  |  173|    157|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 33]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2694|       |
 2695|     33|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 13, False: 20]
  |  |  |  |  ------------------
  |  |  |  |  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|     20|	} else { \
  |  |  |  |  159|     20|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     20|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     20|	} \
  |  |  |  |  162|     33|	return _ret; \
  |  |  |  |  163|     33|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2696|     33|}
card-openpgp.c:pgp_decipher:
 2705|     52|{
 2706|     52|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|     52|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2707|     52|	sc_security_env_t	*env = &priv->sec_env;
 2708|     52|	sc_apdu_t	apdu;
 2709|     52|	u8 apdu_case = SC_APDU_CASE_4;
  ------------------
  |  |  303|     52|#define SC_APDU_CASE_4			0x24
  ------------------
 2710|     52|	u8		*temp = NULL, *p = NULL;
 2711|     52|	size_t		templen, pklen, dolen;
 2712|     52|	int		r;
 2713|       |
 2714|     52|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     52|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     52|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     52|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     52|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 52]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2715|       |
 2716|       |	/* padding according to OpenPGP card spec 1.1 & 2.x section 7.2.9 / 3.x section 7.2.11
 2717|       |	 * The longest possible prefix is 10 bytes for ECDH */
 2718|     52|	templen = inlen + 10;
 2719|     52|	if (!(temp = malloc(templen)))
  ------------------
  |  Branch (2719:6): [True: 0, False: 52]
  ------------------
 2720|     52|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2721|       |
 2722|       |	/* padding byte: 0xa6 = ECC; 0x00 = RSA; 0x02 = AES */
 2723|     52|	switch (env->algorithm) {
 2724|     52|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|     52|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (2724:2): [True: 52, False: 0]
  ------------------
 2725|       |		/* This is just PKCS#1.5 start byte and it should be already
 2726|       |		 * provided by the padding routines. But it lets put it here
 2727|       |		 * to make sure it does not conflict with following indicators */
 2728|     52|		temp[0] = 0x00;
 2729|     52|		memcpy(temp + 1, in, inlen);
 2730|     52|		inlen += 1;
 2731|     52|		break;
 2732|       |
 2733|      0|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (2733:2): [True: 0, False: 52]
  ------------------
 2734|      0|	case SC_ALGORITHM_XEDDSA:
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (2734:2): [True: 0, False: 52]
  ------------------
 2735|       |		/* Calculate length of External Public Key (0x86) */
 2736|      0|		r = sc_asn1_put_tag(0x86, NULL, inlen, NULL, 0, NULL);
 2737|      0|		if (r <= 0) {
  ------------------
  |  Branch (2737:7): [True: 0, False: 0]
  ------------------
 2738|      0|			free(temp);
 2739|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2740|      0|		}
 2741|      0|		pklen = r;
 2742|       |
 2743|       |		/* Calculate length of Public Key DO (0x7F49) */
 2744|      0|		r = sc_asn1_put_tag(0x7f49, NULL, pklen, NULL, 0, NULL);
 2745|      0|		if (r <= 0) {
  ------------------
  |  Branch (2745:7): [True: 0, False: 0]
  ------------------
 2746|      0|			free(temp);
 2747|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2748|      0|		}
 2749|      0|		dolen = r;
 2750|       |
 2751|      0|		p = temp;
 2752|       |		/* This is 0xA6 Cipher DO with associated length field */
 2753|      0|		r = sc_asn1_put_tag(0xA6, NULL, dolen, p, templen - (p - temp), &p);
 2754|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2754:7): [True: 0, False: 0]
  ------------------
 2755|      0|			free(temp);
 2756|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2757|      0|		}
 2758|       |
 2759|       |		/* Public Key DO (0x7F49) with associated length field */
 2760|      0|		r = sc_asn1_put_tag(0x7F49, NULL, pklen, p, templen - (p - temp), &p);
 2761|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2761:7): [True: 0, False: 0]
  ------------------
 2762|      0|			free(temp);
 2763|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2764|      0|		}
 2765|       |
 2766|       |		/* External Public Key (0x86) with associated length */
 2767|      0|		r = sc_asn1_put_tag(0x86, in, inlen, p, templen - (p - temp), &p);
 2768|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (2768:7): [True: 0, False: 0]
  ------------------
 2769|      0|			free(temp);
 2770|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2771|      0|		}
 2772|      0|		inlen = (p - temp);
 2773|      0|		break;
 2774|      0|	case SC_ALGORITHM_AES:
  ------------------
  |  |   88|      0|#define SC_ALGORITHM_AES		67
  ------------------
  |  Branch (2774:2): [True: 0, False: 52]
  ------------------
 2775|       |		/* not supported yet */
 2776|       |		/*
 2777|       |		temp[0] = 0x02;
 2778|       |		memcpy(temp + 1, in, inlen);
 2779|       |		inlen += 1;
 2780|       |		*/
 2781|       |		/* fall through */
 2782|      0|	default:
  ------------------
  |  Branch (2782:2): [True: 0, False: 52]
  ------------------
 2783|      0|		free(temp);
 2784|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2785|     52|	}
 2786|       |
 2787|     52|	in = temp;
 2788|       |
 2789|     52|	if (env->operation != SC_SEC_OPERATION_DECIPHER &&
  ------------------
  |  |   56|    104|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (2789:6): [True: 0, False: 52]
  ------------------
 2790|      0|			env->operation != SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   59|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (2790:4): [True: 0, False: 0]
  ------------------
 2791|      0|		free(temp);
 2792|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2793|      0|				"invalid operation");
 2794|      0|	}
 2795|       |
 2796|     52|	switch (env->key_ref[0]) {
 2797|     51|	case 0x01: /* Decryption key */
  ------------------
  |  Branch (2797:2): [True: 51, False: 1]
  ------------------
 2798|     52|	case 0x02: /* authentication key */
  ------------------
  |  Branch (2798:2): [True: 1, False: 51]
  ------------------
 2799|       |		/* PSO DECIPHER */
 2800|     52|		sc_format_apdu(card, &apdu, apdu_case, 0x2A, 0x80, 0x86);
 2801|     52|		break;
 2802|      0|	case 0x00: /* signature key */
  ------------------
  |  Branch (2802:2): [True: 0, False: 52]
  ------------------
 2803|      0|	default:
  ------------------
  |  Branch (2803:2): [True: 0, False: 52]
  ------------------
 2804|      0|		free(temp);
 2805|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2806|     52|				"invalid key reference");
 2807|     52|	}
 2808|       |
 2809|       |	/* Gnuk only supports short APDU, so we need to use command chaining */
 2810|     52|	if (card->type == SC_CARD_TYPE_OPENPGP_GNUK) {
  ------------------
  |  Branch (2810:6): [True: 1, False: 51]
  ------------------
 2811|      1|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      1|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2812|      1|	}
 2813|       |	/* if card/reader does not support extended APDUs, but chaining, then set it */
 2814|     52|	if (((card->caps & SC_CARD_CAP_APDU_EXT) == 0) && (priv->ext_caps & EXT_CAP_CHAINING))
  ------------------
  |  |  554|     52|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2814:6): [True: 51, False: 1]
  |  Branch (2814:52): [True: 1, False: 50]
  ------------------
 2815|      1|		apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|      1|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 2816|       |
 2817|     52|	apdu.lc = inlen;
 2818|     52|	apdu.data = (u8 *)in;
 2819|     52|	apdu.datalen = inlen;
 2820|     52|	apdu.le = ((outlen >= 256) && !(card->caps & SC_CARD_CAP_APDU_EXT)) ? 256 : outlen;
  ------------------
  |  |  554|     52|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (2820:13): [True: 52, False: 0]
  |  Branch (2820:32): [True: 51, False: 1]
  ------------------
 2821|     52|	apdu.resp = out;
 2822|     52|	apdu.resplen = outlen;
 2823|       |
 2824|       |	/* For OpenPGP Card >=v3.3, key slot 3 instead of 2 can be used for deciphering,
 2825|       |	 * but this has to be set via MSE beforehand on every usage (slot 2 is used by default)
 2826|       |	 * see section 7.2.18 of the specification of OpenPGP Card v3.3 */
 2827|     52|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2827:6): [True: 49, False: 3]
  |  Branch (2827:47): [True: 1, False: 48]
  ------------------
 2828|      1|		pgp_set_MSE(card, 3, 0xb8);
 2829|      1|	}
 2830|       |
 2831|     52|	r = sc_transmit_apdu(card, &apdu);
 2832|     52|	free(temp);
 2833|     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: 9, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  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|     52|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 43]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2834|       |
 2835|     43|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2836|     43|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     43|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     43|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     43|	int _ret = (r); \
  |  |  |  |  168|     43|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 35, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  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|     43|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2837|       |
 2838|       |	/* For OpenPGP Card >=v3.3, use key slot 2 for deciphering again (set to default) */
 2839|      8|	if (priv->bcd_version >= OPENPGP_CARD_3_3 && env->key_ref[0] == 0x02){
  ------------------
  |  Branch (2839:6): [True: 7, False: 1]
  |  Branch (2839:47): [True: 0, False: 7]
  ------------------
 2840|      0|		pgp_set_MSE(card, 2, 0xb8);
 2841|      0|	}
 2842|       |
 2843|      8|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 4, False: 4]
  |  |  |  |  ------------------
  |  |  |  |  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|      4|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      4|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      4|	} \
  |  |  |  |  162|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2844|      8|}
card-openpgp.c:pgp_set_MSE:
 2607|      1|{
 2608|      1|	struct pgp_priv_data	*priv = DRVDATA(card);
  ------------------
  |  |  189|      1|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 2609|      1|	sc_apdu_t	apdu;
 2610|      1|	u8	apdu_case = SC_APDU_CASE_3;
  ------------------
  |  |  302|      1|#define SC_APDU_CASE_3			0x23
  ------------------
 2611|      1|	u8	apdu_data[3];
 2612|      1|	int	r;
 2613|       |
 2614|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2615|       |
 2616|       |	// check if MSE is supported
 2617|      1|	if (!(priv->ext_caps & EXT_CAP_MSE))
  ------------------
  |  Branch (2617:6): [True: 0, False: 1]
  ------------------
 2618|      1|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2619|       |
 2620|       |	// create apdu
 2621|      1|	sc_format_apdu(card, &apdu, apdu_case, 0x22, 0x41, p2);
 2622|      1|	apdu.lc = 3;
 2623|      1|	apdu_data[0] = 0x83;
 2624|      1|	apdu_data[1] = 0x01;
 2625|      1|	apdu_data[2] = key;
 2626|      1|	apdu.data = apdu_data;
 2627|      1|	apdu.datalen = 3;
 2628|       |
 2629|       |	// transmit apdu
 2630|      1|	r = sc_transmit_apdu(card, &apdu);
 2631|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2632|       |
 2633|      1|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 2634|      1|	LOG_TEST_RET(card->ctx, r, "Card returned 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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2635|       |
 2636|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2637|      0|}
card-openpgp.c:pgp_card_ctl:
 4013|    228|{
 4014|    228|	int r;
 4015|       |
 4016|    228|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    228|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    228|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    228|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    228|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 228]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4017|       |
 4018|    228|	switch(cmd) {
  ------------------
  |  Branch (4018:9): [True: 228, False: 0]
  ------------------
 4019|     28|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4019:2): [True: 28, False: 200]
  ------------------
 4020|     28|		memmove((sc_serial_number_t *) ptr, &card->serialnr, sizeof(card->serialnr));
 4021|     28|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     28|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     28|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     28|	int _ret = r; \
  |  |  |  |  155|     28|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 28, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     28|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 28]
  |  |  |  |  ------------------
  |  |  |  |  157|     28|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     28|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     28|	return _ret; \
  |  |  |  |  163|     28|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4022|      0|		break;
 4023|    200|	case SC_CARDCTL_OPENPGP_SELECT_DATA:
  ------------------
  |  Branch (4023:2): [True: 200, False: 28]
  ------------------
 4024|    200|		r = pgp_select_data(card, *((u8 *) ptr));
 4025|    200|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    200|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    200|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    200|	int _ret = r; \
  |  |  |  |  155|    200|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 200, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    200|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    176|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 176, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|    200|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    200|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    200|	return _ret; \
  |  |  |  |  163|    200|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4026|      0|		break;
 4027|      0|#ifdef ENABLE_OPENSSL
 4028|      0|	case SC_CARDCTL_OPENPGP_GENERATE_KEY:
  ------------------
  |  Branch (4028:2): [True: 0, False: 228]
  ------------------
 4029|      0|		r = pgp_gen_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4030|      0|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4031|      0|		break;
 4032|      0|	case SC_CARDCTL_OPENPGP_STORE_KEY:
  ------------------
  |  Branch (4032:2): [True: 0, False: 228]
  ------------------
 4033|      0|		r = pgp_store_key(card, (sc_cardctl_openpgp_key_gen_store_info_t *)ptr);
 4034|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4035|      0|		break;
 4036|      0|#endif /* ENABLE_OPENSSL */
 4037|      0|	case SC_CARDCTL_ERASE_CARD:
  ------------------
  |  Branch (4037:2): [True: 0, False: 228]
  ------------------
 4038|      0|		r = pgp_erase_card(card);
 4039|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4040|      0|		break;
 4041|    228|	}
 4042|       |
 4043|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4044|      0|}
card-openpgp.c:pgp_select_data:
 1953|    200|{
 1954|    200|	sc_apdu_t	apdu;
 1955|    200|	u8	apdu_data[6];
 1956|    200|	int	r;
 1957|    200|	struct pgp_priv_data *priv = DRVDATA(card);
  ------------------
  |  |  189|    200|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 1958|       |
 1959|    200|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    200|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    200|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    200|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    200|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 200]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1960|       |
 1961|    200|	if (priv->bcd_version < OPENPGP_CARD_3_0)
  ------------------
  |  Branch (1961:6): [True: 103, False: 97]
  ------------------
 1962|    200|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|    103|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    103|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    103|	int _ret = r; \
  |  |  |  |  155|    103|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    103|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    103|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 103, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    103|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    103|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    103|	return _ret; \
  |  |  |  |  163|    103|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1963|       |
 1964|     97|	sc_log(card->ctx, "select data with: %u", p1);
  ------------------
  |  |   71|     97|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1965|       |
 1966|       |	// create apdu data (taken from spec: SELECT DATA 7.2.5.)
 1967|     97|	apdu_data[0] = 0x60;
 1968|     97|	apdu_data[1] = 0x04;
 1969|     97|	apdu_data[2] = 0x5c;
 1970|     97|	apdu_data[3] = 0x02;
 1971|     97|	apdu_data[4] = 0x7f;
 1972|     97|	apdu_data[5] = 0x21;
 1973|       |
 1974|       |	// apdu, cla, ins, p1, p2, data, datalen, resp, resplen
 1975|     97|	sc_format_apdu_ex(&apdu, 0x00, 0xA5, p1, 0x04, apdu_data, sizeof(apdu_data), NULL, 0);
 1976|       |
 1977|       |	// transmit apdu
 1978|     97|	r = sc_transmit_apdu(card, &apdu);
 1979|     97|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     97|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     97|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     97|	int _ret = (r); \
  |  |  |  |  168|     97|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 92]
  |  |  |  |  ------------------
  |  |  |  |  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|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 92]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1980|     92|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1981|     92|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  174|     92|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     92|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     92|	int _ret = (r); \
  |  |  |  |  168|     92|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 68, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  169|     68|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     68|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     68|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     68|		return _ret; \
  |  |  |  |  172|     68|	} \
  |  |  |  |  173|     92|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1982|     24|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     24|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     24|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     24|	int _ret = r; \
  |  |  |  |  155|     24|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 24, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     24|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     24|	return _ret; \
  |  |  |  |  163|     24|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1983|     24|}
card-openpgp.c:pgp_card_reader_lock_obtained:
 4173|  9.28k|{
 4174|  9.28k|	struct pgp_priv_data *priv = DRVDATA(card); /* may be null during initialization */
  ------------------
  |  |  189|  9.28k|#define DRVDATA(card)        ((struct pgp_priv_data *) ((card)->drv_data))
  ------------------
 4175|  9.28k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  9.28k|#define SC_SUCCESS				0
  ------------------
 4176|       |
 4177|  9.28k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.28k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.28k]
  |  |  ------------------
  ------------------
 4178|       |
 4179|  9.28k|	if (card->flags & SC_CARD_FLAG_KEEP_ALIVE
  ------------------
  |  |  544|  18.5k|#define SC_CARD_FLAG_KEEP_ALIVE	0x00000004
  ------------------
  |  Branch (4179:6): [True: 0, False: 9.28k]
  ------------------
 4180|      0|			&& was_reset <= 0
  ------------------
  |  Branch (4180:7): [True: 0, False: 0]
  ------------------
 4181|      0|			&& priv != NULL && priv->mf && priv->mf->file) {
  ------------------
  |  Branch (4181:7): [True: 0, False: 0]
  |  Branch (4181:23): [True: 0, False: 0]
  |  Branch (4181:35): [True: 0, False: 0]
  ------------------
 4182|       |		/* check whether applet is still selected */
 4183|      0|		unsigned char aid[16];
 4184|       |
 4185|      0|		r = sc_get_data(card, 0x004F, aid, sizeof aid);
 4186|      0|		if ((size_t) r != priv->mf->file->namelen
  ------------------
  |  Branch (4186:7): [True: 0, False: 0]
  ------------------
 4187|      0|				|| 0 != memcmp(aid, priv->mf->file->name, r)) {
  ------------------
  |  Branch (4187:8): [True: 0, False: 0]
  ------------------
 4188|       |			/* reselect is required */
 4189|      0|			was_reset = 1;
 4190|      0|		}
 4191|      0|		r = SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 4192|      0|	}
 4193|       |
 4194|  9.28k|	if (was_reset > 0) {
  ------------------
  |  Branch (4194:6): [True: 0, False: 9.28k]
  ------------------
 4195|      0|		sc_file_t	*file = NULL;
 4196|      0|		sc_path_t	path;
 4197|       |		/* select application "OpenPGP" */
 4198|      0|		sc_format_path("D276:0001:2401", &path);
 4199|      0|		path.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 4200|      0|		r = iso_ops->select_file(card, &path, &file);
 4201|      0|		sc_file_free(file);
 4202|      0|	}
 4203|       |
 4204|  9.28k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  9.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.28k|	int _ret = r; \
  |  |  |  |  155|  9.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.28k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.28k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 9.28k]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.28k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.28k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  9.28k|	return _ret; \
  |  |  |  |  163|  9.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4205|  9.28k|}

sc_get_piv_driver:
 6473|  15.3k|{
 6474|  15.3k|	return sc_get_driver();
 6475|  15.3k|}
card-piv.c:sc_get_driver:
 6446|  15.3k|{
 6447|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6448|       |
 6449|  15.3k|	piv_ops = *iso_drv->ops;
 6450|  15.3k|	piv_ops.match_card = piv_match_card;
 6451|  15.3k|	piv_ops.init = piv_init;
 6452|  15.3k|	piv_ops.finish = piv_finish;
 6453|       |
 6454|  15.3k|	piv_ops.select_file = piv_select_file; /* must use get/put, could emulate? */
 6455|  15.3k|	piv_ops.get_challenge = piv_get_challenge;
 6456|  15.3k|	piv_ops.logout = piv_logout;
 6457|  15.3k|	piv_ops.read_binary = piv_read_binary;
 6458|  15.3k|	piv_ops.write_binary = piv_write_binary;
 6459|  15.3k|	piv_ops.set_security_env = piv_set_security_env;
 6460|  15.3k|	piv_ops.restore_security_env = piv_restore_security_env;
 6461|  15.3k|	piv_ops.compute_signature = piv_compute_signature;
 6462|  15.3k|	piv_ops.decipher = piv_decipher;
 6463|  15.3k|	piv_ops.check_sw = piv_check_sw;
 6464|  15.3k|	piv_ops.card_ctl = piv_card_ctl;
 6465|  15.3k|	piv_ops.pin_cmd = piv_pin_cmd;
 6466|  15.3k|	piv_ops.card_reader_lock_obtained = piv_card_reader_lock_obtained;
 6467|       |
 6468|  15.3k|	return &piv_drv;
 6469|  15.3k|}
card-piv.c:piv_match_card:
 5408|  5.07k|{
 5409|  5.07k|	int r = 0;
 5410|       |
 5411|  5.07k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d\n", card->type);
  ------------------
  |  |   70|  5.07k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5412|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5413|       |	/* user provided card type must be one we know */
 5414|  5.07k|	switch (card->type) {
 5415|  5.07k|	case -1:
  ------------------
  |  Branch (5415:2): [True: 5.07k, False: 0]
  ------------------
 5416|  5.07k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5416:2): [True: 0, False: 5.07k]
  ------------------
 5417|  5.07k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5417:2): [True: 0, False: 5.07k]
  ------------------
 5418|  5.07k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5418:2): [True: 0, False: 5.07k]
  ------------------
 5419|  5.07k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5419:2): [True: 0, False: 5.07k]
  ------------------
 5420|  5.07k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5420:2): [True: 0, False: 5.07k]
  ------------------
 5421|  5.07k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5421:2): [True: 0, False: 5.07k]
  ------------------
 5422|  5.07k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5422:2): [True: 0, False: 5.07k]
  ------------------
 5423|  5.07k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5423:2): [True: 0, False: 5.07k]
  ------------------
 5424|  5.07k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5424:2): [True: 0, False: 5.07k]
  ------------------
 5425|  5.07k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5425:2): [True: 0, False: 5.07k]
  ------------------
 5426|  5.07k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5426:2): [True: 0, False: 5.07k]
  ------------------
 5427|  5.07k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5427:2): [True: 0, False: 5.07k]
  ------------------
 5428|  5.07k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5428:2): [True: 0, False: 5.07k]
  ------------------
 5429|  5.07k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5429:2): [True: 0, False: 5.07k]
  ------------------
 5430|  5.07k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5430:2): [True: 0, False: 5.07k]
  ------------------
 5431|  5.07k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5431:2): [True: 0, False: 5.07k]
  ------------------
 5432|  5.07k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5432:2): [True: 0, False: 5.07k]
  ------------------
 5433|  5.07k|		break;
 5434|      0|	default:
  ------------------
  |  Branch (5434:2): [True: 0, False: 5.07k]
  ------------------
 5435|      0|		return 0; /* can not handle the card */
 5436|  5.07k|	}
 5437|       |
 5438|  5.07k|	r = sc_lock(card);
 5439|  5.07k|	if (r < 0)
  ------------------
  |  Branch (5439:6): [True: 0, False: 5.07k]
  ------------------
 5440|      0|		return 0;
 5441|       |	/* its one we know, or we can test for it in piv_init */
 5442|  5.07k|	r = piv_match_card_continued(card);
 5443|  5.07k|	sc_unlock(card);
 5444|       |
 5445|  5.07k|	if (r < 0 || !card->drv_data) {
  ------------------
  |  Branch (5445:6): [True: 4.28k, False: 786]
  |  Branch (5445:15): [True: 0, False: 786]
  ------------------
 5446|       |		/* clean up what we left in card */
 5447|  4.28k|		piv_finish(card);
 5448|  4.28k|		return 0; /* match failed */
 5449|  4.28k|	}
 5450|       |
 5451|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5452|    786|	return 1; /* matched */
 5453|  5.07k|}
card-piv.c:piv_match_card_continued:
 5457|  5.07k|{
 5458|  5.07k|	int i, r = 0, r2 = 0;
 5459|  5.07k|	int type = -1;
 5460|  5.07k|	piv_private_data_t *priv = NULL;
 5461|  5.07k|	int saved_type = card->type;
 5462|  5.07k|	sc_apdu_t apdu;
 5463|  5.07k|	u8 yubico_version_buf[3] = {0};
 5464|       |
 5465|       |	/* piv_match_card may be called with card->type, set by opensc.conf */
 5466|       |	/* User provided card type must be one we know */
 5467|       |
 5468|  5.07k|	switch (card->type) {
 5469|  5.07k|	case -1:
  ------------------
  |  Branch (5469:2): [True: 5.07k, False: 0]
  ------------------
 5470|  5.07k|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5470:2): [True: 0, False: 5.07k]
  ------------------
 5471|  5.07k|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5471:2): [True: 0, False: 5.07k]
  ------------------
 5472|  5.07k|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5472:2): [True: 0, False: 5.07k]
  ------------------
 5473|  5.07k|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5473:2): [True: 0, False: 5.07k]
  ------------------
 5474|  5.07k|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5474:2): [True: 0, False: 5.07k]
  ------------------
 5475|  5.07k|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5475:2): [True: 0, False: 5.07k]
  ------------------
 5476|  5.07k|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5476:2): [True: 0, False: 5.07k]
  ------------------
 5477|  5.07k|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5477:2): [True: 0, False: 5.07k]
  ------------------
 5478|  5.07k|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5478:2): [True: 0, False: 5.07k]
  ------------------
 5479|  5.07k|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5479:2): [True: 0, False: 5.07k]
  ------------------
 5480|  5.07k|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5480:2): [True: 0, False: 5.07k]
  ------------------
 5481|  5.07k|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5481:2): [True: 0, False: 5.07k]
  ------------------
 5482|  5.07k|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5482:2): [True: 0, False: 5.07k]
  ------------------
 5483|  5.07k|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5483:2): [True: 0, False: 5.07k]
  ------------------
 5484|  5.07k|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5484:2): [True: 0, False: 5.07k]
  ------------------
 5485|  5.07k|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5485:2): [True: 0, False: 5.07k]
  ------------------
 5486|  5.07k|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5486:2): [True: 0, False: 5.07k]
  ------------------
 5487|  5.07k|		type = card->type;
 5488|  5.07k|		break;
 5489|      0|	default:
  ------------------
  |  Branch (5489:2): [True: 0, False: 5.07k]
  ------------------
 5490|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5491|  5.07k|	}
 5492|  5.07k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.07k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5493|  5.07k|	if (type == -1) {
  ------------------
  |  Branch (5493:6): [True: 5.07k, False: 0]
  ------------------
 5494|       |		/*
 5495|       |		 * Try to identify card by ATR or historical data in ATR
 5496|       |		 * currently all PIV card will respond to piv_find_aid
 5497|       |		 * the same. But in future may need to know card type first,
 5498|       |		 * so do it here.
 5499|       |		 */
 5500|       |
 5501|  5.07k|		if (card->reader->atr_info.hist_bytes != NULL) {
  ------------------
  |  Branch (5501:7): [True: 2.27k, False: 2.79k]
  ------------------
 5502|  2.27k|			if (card->reader->atr_info.hist_bytes_len == 8 &&
  ------------------
  |  Branch (5502:8): [True: 387, False: 1.88k]
  ------------------
 5503|    387|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey4", 8))) {
  ------------------
  |  Branch (5503:6): [True: 129, False: 258]
  ------------------
 5504|    129|				type = SC_CARD_TYPE_PIV_II_YUBIKEY4;
 5505|  2.14k|			} else if (card->reader->atr_info.hist_bytes_len >= 7 &&
  ------------------
  |  Branch (5505:15): [True: 1.43k, False: 707]
  ------------------
 5506|  1.43k|					!(memcmp(card->reader->atr_info.hist_bytes, "Yubikey", 7))) {
  ------------------
  |  Branch (5506:6): [True: 333, False: 1.10k]
  ------------------
 5507|    333|				type = SC_CARD_TYPE_PIV_II_NEO;
 5508|  1.81k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5508:15): [True: 1.13k, False: 674]
  ------------------
 5509|  1.13k|					!(memcmp(card->reader->atr_info.hist_bytes, "PIVKEY", 6))) {
  ------------------
  |  Branch (5509:6): [True: 60, False: 1.07k]
  ------------------
 5510|     60|				type = SC_CARD_TYPE_PIV_II_PIVKEY;
 5511|  1.75k|			} else if (card->reader->atr_info.hist_bytes_len >= 6 &&
  ------------------
  |  Branch (5511:15): [True: 1.07k, False: 674]
  ------------------
 5512|  1.07k|					!(memcmp(card->reader->atr_info.hist_bytes, (u8 *)"TK\x00PIV", 6))) {
  ------------------
  |  Branch (5512:6): [True: 3, False: 1.07k]
  ------------------
 5513|      3|				type = SC_CARD_TYPE_PIV_II_TOKEN2;
 5514|      3|			}
 5515|       |			/* look for TLV historic data */
 5516|  1.74k|			else if (card->reader->atr_info.hist_bytes_len > 0 &&
  ------------------
  |  Branch (5516:13): [True: 1.73k, False: 10]
  ------------------
 5517|  1.73k|					card->reader->atr_info.hist_bytes[0] == 0x80u) { /* compact TLV */
  ------------------
  |  Branch (5517:6): [True: 553, False: 1.18k]
  ------------------
 5518|    553|				size_t datalen;
 5519|    553|				const u8 *data;
 5520|       |
 5521|       |				/* look for card issuer's data:  tag 5X where X is datalen */
 5522|    553|				if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5522:9): [True: 23, False: 530]
  ------------------
 5523|    553|						     card->reader->atr_info.hist_bytes_len - 1, 0x50, &datalen))) {
 5524|     23|					if (datalen >= 8 && !(memcmp(data, "Nitrokey", 8))) { /* first 8 are Nitrokey */
  ------------------
  |  Branch (5524:10): [True: 12, False: 11]
  |  Branch (5524:26): [True: 2, False: 10]
  ------------------
 5525|      2|						type = SC_CARD_TYPE_PIV_II_NITROKEY;
 5526|     21|					} else if (datalen == 7 && !(memcmp(data, "YubiKey", 7))) {
  ------------------
  |  Branch (5526:17): [True: 6, False: 15]
  |  Branch (5526:33): [True: 1, False: 5]
  ------------------
 5527|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4  really 5 */
 5528|      1|					}
 5529|       |					/* Yubikey 5 NFC ATR using ACR122 contactless reader does not match
 5530|       |					 * https://developers.yubico.com/PIV/Introduction/Yubico_extensions.html
 5531|       |					 * On Windows 10, using Omnikey 5021, the ATR is correct
 5532|       |					 * will look at only 6 bytes that do match
 5533|       |					 */
 5534|     20|					else if (datalen == 7 && !(memcmp(data, "YubiKe", 6))) {
  ------------------
  |  Branch (5534:15): [True: 5, False: 15]
  |  Branch (5534:31): [True: 1, False: 4]
  ------------------
 5535|      1|						type = SC_CARD_TYPE_PIV_II_YUBIKEY4; /* reader says 4 really 5 */
 5536|      1|					}
 5537|    530|				} else if ((data = sc_compacttlv_find_tag(card->reader->atr_info.hist_bytes + 1,
  ------------------
  |  Branch (5537:16): [True: 168, False: 362]
  ------------------
 5538|    530|							    card->reader->atr_info.hist_bytes_len - 1, 0xF0, &datalen))) {
 5539|    168|					int k;
 5540|       |
 5541|    239|					for (k = 0; piv_aids[k].len_long != 0; k++) {
  ------------------
  |  Branch (5541:18): [True: 168, False: 71]
  ------------------
 5542|    168|						if (datalen == piv_aids[k].len_long &&
  ------------------
  |  Branch (5542:11): [True: 160, False: 8]
  ------------------
 5543|    160|								!memcmp(data, piv_aids[k].value, datalen)) {
  ------------------
  |  Branch (5543:9): [True: 97, False: 63]
  ------------------
 5544|     97|							type = SC_CARD_TYPE_PIV_II_HIST;
 5545|     97|							break;
 5546|     97|						}
 5547|    168|					}
 5548|    168|				}
 5549|    553|			}
 5550|  2.27k|		}
 5551|       |
 5552|  5.07k|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.07k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5553|       |
 5554|  5.07k|		if (type == -1) {
  ------------------
  |  Branch (5554:7): [True: 4.44k, False: 626]
  ------------------
 5555|       |			/* use known ATRs  which changes the type */
 5556|  4.44k|			i = _sc_match_atr(card, piv_atrs, &type);
 5557|  4.44k|			if (i < 0)
  ------------------
  |  Branch (5557:8): [True: 4.40k, False: 46]
  ------------------
 5558|  4.40k|				type = SC_CARD_TYPE_PIV_II_BASE; /* May be some newer unknown card including CAC or PIV-like card */
 5559|  4.44k|		}
 5560|  5.07k|	}
 5561|       |
 5562|  5.07k|	card->type = type;
 5563|       |
 5564|       |	/* we either found via ATR historic bytes or ATR directly */
 5565|  5.07k|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d type:%d r:%d\n", card->type, type, r);
  ------------------
  |  |   70|  5.07k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5566|       |
 5567|       |	/* allocate and init basic fields */
 5568|  5.07k|	priv = calloc(1, sizeof(piv_private_data_t));
 5569|       |
 5570|  5.07k|	if (!priv)
  ------------------
  |  Branch (5570:6): [True: 0, False: 5.07k]
  ------------------
 5571|  5.07k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5572|       |
 5573|  5.07k|	card->drv_data = priv; /* will free if no match, or pass on to piv_init */
 5574|       |	/*
 5575|       |	 * Largest object defined in NIST sp800-73-3 and sp800-73-4 is 12710 bytes
 5576|       |	 * If for some reason future cards have larger objects, this value needs to
 5577|       |	 * be increased here.
 5578|       |	 */
 5579|  5.07k|	priv->max_object_size = MAX_FILE_SIZE - 256; /* fix SM apdu resplen issue */
  ------------------
  |  |  229|  5.07k|#define MAX_FILE_SIZE 65535
  ------------------
 5580|  5.07k|	priv->selected_obj = -1;
 5581|  5.07k|	priv->pin_preference = 0x80; /* 800-73-3 part 1, table 3 */
 5582|  5.07k|	priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|  5.07k|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 5583|  5.07k|	priv->pstate = PIV_STATE_MATCH;
 5584|       |
 5585|       |#ifdef ENABLE_PIV_SM
 5586|       |	memset(&card->sm_ctx, 0, sizeof card->sm_ctx);
 5587|       |	card->sm_ctx.ops.open = piv_sm_open;
 5588|       |	card->sm_ctx.ops.get_sm_apdu = piv_get_sm_apdu;
 5589|       |	card->sm_ctx.ops.free_sm_apdu = piv_free_sm_apdu;
 5590|       |	card->sm_ctx.ops.close = piv_sm_close;
 5591|       |#endif /* ENABLE_PIV_SM */
 5592|       |
 5593|       |	/* See if contactless  or run as virtual card */
 5594|       |	/* PivApplet in .github/test_piv.sh for example */
 5595|  5.07k|	if (card->reader->atr.len >= 4 &&
  ------------------
  |  Branch (5595:6): [True: 2.56k, False: 2.50k]
  ------------------
 5596|  2.56k|			card->reader->atr.value[0] == 0x3b &&
  ------------------
  |  Branch (5596:4): [True: 2.30k, False: 264]
  ------------------
 5597|  2.30k|			(card->reader->atr.value[1] & 0xF0) == 0x80 &&
  ------------------
  |  Branch (5597:4): [True: 246, False: 2.05k]
  ------------------
 5598|    246|			card->reader->atr.value[2] == 0x80 &&
  ------------------
  |  Branch (5598:4): [True: 136, False: 110]
  ------------------
 5599|    136|			card->reader->atr.value[3] == 0x01) {
  ------------------
  |  Branch (5599:4): [True: 120, False: 16]
  ------------------
 5600|    120|		priv->init_flags |= PIV_INIT_CONTACTLESS;
  ------------------
  |  |  382|    120|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
 5601|    120|	}
 5602|       |
 5603|   309k|	for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++)
  ------------------
  |  Branch (5603:14): [True: 304k, False: 5.07k]
  ------------------
 5604|   304k|		if (piv_objects[i].flags & PIV_OBJECT_NOT_PRESENT)
  ------------------
  |  |  634|   304k|#define PIV_OBJECT_NOT_PRESENT		0x04
  ------------------
  |  Branch (5604:7): [True: 101k, False: 202k]
  ------------------
 5605|   101k|			priv->obj_cache[i].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|   106k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5606|       |	/*
 5607|       |	 * Detect if active AID is PIV. NIST 800-73 says only one PIV application per card
 5608|       |	 * and PIV must be the default application.
 5609|       |	 * Try to avoid doing a select_aid and losing the login state on some cards.
 5610|       |	 * We may get interference on some cards by other drivers trying SELECT_AID before
 5611|       |	 * we get to see if PIV application is still active. Putting PIV driver first might help.
 5612|       |	 *
 5613|       |	 * Discovery Object introduced in 800-73-3 so will return OK if found and PIV applet active.
 5614|       |	 * Will fail with SC_ERROR_FILE_NOT_FOUND if 800-73-3 and no Discovery object.
 5615|       |	 * But some other card could also return SC_ERROR_FILE_NOT_FOUND.
 5616|       |	 * Will fail for other reasons if wrong applet is selected or bad PIV implementation.
 5617|       |	 */
 5618|       |
 5619|       |	/*
 5620|       |	 * if ATR matched or user forced card type
 5621|       |	 * test if PIV is active applet without using AID If fails try AID
 5622|       |	 */
 5623|       |
 5624|  5.07k|	if (card->type > SC_CARD_TYPE_PIV_II_BASE &&
  ------------------
  |  Branch (5624:6): [True: 672, False: 4.40k]
  ------------------
 5625|    672|			!(priv->init_flags & PIV_INIT_CONTACTLESS)) {
  ------------------
  |  |  382|    672|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5625:4): [True: 671, False: 1]
  ------------------
 5626|    671|		r = piv_find_discovery(card);
 5627|    671|		if (r < 0) {
  ------------------
  |  Branch (5627:7): [True: 433, False: 238]
  ------------------
 5628|    433|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, 0); /* don't cache  on failure */
 5629|    433|			r = piv_find_aid(card);
 5630|    433|			LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|    433|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    433|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    433|	int _ret = (r); \
  |  |  |  |  178|    433|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 134, False: 299]
  |  |  |  |  ------------------
  |  |  |  |  179|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    134|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    134|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    134|		goto err; \
  |  |  |  |  182|    134|	} \
  |  |  |  |  183|    433|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 299]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5631|    433|		}
 5632|  4.40k|	} else {
 5633|       |		/* piv_find_aid saves al_label from response */
 5634|  4.40k|		r = piv_find_aid(card);
 5635|  4.40k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Not a PIV card");
  ------------------
  |  |  184|  4.40k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  4.40k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  4.40k|	int _ret = (r); \
  |  |  |  |  178|  4.40k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4.15k, False: 249]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.15k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  4.15k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  4.15k|		goto err; \
  |  |  |  |  182|  4.15k|	} \
  |  |  |  |  183|  4.40k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 249]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5636|  4.40k|	}
 5637|       |
 5638|       |	/* Know to be PIV card but not the type */
 5639|       |
 5640|       |	/* If card type still unknown, see if Application Label is known and set card->type */
 5641|    786|	if (priv->al_label && priv->al_labellen) {
  ------------------
  |  Branch (5641:6): [True: 3, False: 783]
  |  Branch (5641:24): [True: 1, False: 2]
  ------------------
 5642|      1|		switch (card->type) {
  ------------------
  |  Branch (5642:11): [True: 1, False: 0]
  ------------------
 5643|      1|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5643:3): [True: 1, False: 0]
  ------------------
 5644|      1|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5644:3): [True: 0, False: 1]
  ------------------
 5645|      2|			for (i = 0; al_map[i].al_label; i++) {
  ------------------
  |  Branch (5645:16): [True: 1, False: 1]
  ------------------
 5646|      1|				if ((priv->al_labellen >= al_map[i].al_labellen) &&
  ------------------
  |  Branch (5646:9): [True: 0, False: 1]
  ------------------
 5647|      0|						(!memcmp(priv->al_label, al_map[i].al_label, al_map[i].al_labellen))) {
  ------------------
  |  Branch (5647:7): [True: 0, False: 0]
  ------------------
 5648|      0|					sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "AL match i:%d type:%d", i, al_map[i].al_type);
  ------------------
  |  |   70|      0|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5649|      0|					card->type = al_map[i].al_type;
 5650|      0|					break;
 5651|      0|				}
 5652|      1|			}
 5653|      1|			break;
 5654|      1|		}
 5655|      1|	}
 5656|       |
 5657|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d  CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5658|    786|			card->type, priv->card_issues, r, priv->alg_ids);
 5659|       |
 5660|       |	/*
 5661|       |	 * Assumes all Yubikey/Nitrokey/Token2/PivApplet cards are all "Yubico like"
 5662|       |	 * via ATR, ATR Historic bytes or Application Label
 5663|       |	 * Will also check if BASE cards are Yubikey like card and return a version number
 5664|       |	 * SC_CARD_TYPE_PIV_II_GENERIC can be set by user to not test for Yubico version
 5665|       |	 */
 5666|    786|	switch (card->type) {
  ------------------
  |  Branch (5666:10): [True: 633, False: 153]
  ------------------
 5667|    272|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5667:2): [True: 272, False: 514]
  ------------------
 5668|    383|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5668:2): [True: 111, False: 675]
  ------------------
 5669|    383|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5669:2): [True: 0, False: 786]
  ------------------
 5670|    384|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5670:2): [True: 1, False: 785]
  ------------------
 5671|    384|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5671:2): [True: 0, False: 786]
  ------------------
 5672|    384|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5672:2): [True: 0, False: 786]
  ------------------
 5673|    633|	case SC_CARD_TYPE_PIV_II_BASE: /* unknown PIV card */
  ------------------
  |  Branch (5673:2): [True: 249, False: 537]
  ------------------
 5674|    633|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xFD, 0x00, 0x00);
  ------------------
  |  |  292|    633|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
 5675|    633|		apdu.lc = 0;
 5676|    633|		apdu.data = NULL;
 5677|    633|		apdu.datalen = 0;
 5678|    633|		apdu.resp = yubico_version_buf;
 5679|    633|		apdu.resplen = sizeof(yubico_version_buf);
 5680|    633|		apdu.le = apdu.resplen;
 5681|    633|		r2 = sc_transmit_apdu(card, &apdu); /* if not supported yubico_version == 0 */
 5682|    633|		if (apdu.resplen == 3) {
  ------------------
  |  Branch (5682:7): [True: 375, False: 258]
  ------------------
 5683|    375|			priv->yubico_version = (yubico_version_buf[0] << 16) | (yubico_version_buf[1] << 8) | yubico_version_buf[2];
 5684|    375|			sc_log(card->ctx, "Yubikey version test card->type=%d, r=0x%08x version=0x%08x", card->type, r, priv->yubico_version);
  ------------------
  |  |   71|    375|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5685|    375|		}
 5686|    633|		break;
 5687|    786|	}
 5688|       |
 5689|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5690|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5691|       |
 5692|       |	/* We now know PIV AID is active, test CCC object. 800-73-* say CCC is required */
 5693|       |	/* CCC not readable over contactless, unless using VCI. but dont need CCC for SC_CARD_TYPE_PIV_II_800_73_4 */
 5694|    786|	switch (card->type) {
  ------------------
  |  Branch (5694:10): [True: 356, False: 430]
  ------------------
 5695|       |	/*
 5696|       |	 * For cards that may also be CAC, try and read the CCC
 5697|       |	 * CCC is required and all Dual PIV/CAC will have a CCC
 5698|       |	 * Currently Dual PIV/CAC are based on NIST 800-73-1 which does not have Discovery or History
 5699|       |	 */
 5700|    249|	case SC_CARD_TYPE_PIV_II_BASE: /* i.e. really dont know what this is */
  ------------------
  |  Branch (5700:2): [True: 249, False: 537]
  ------------------
 5701|    249|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5701:2): [True: 0, False: 786]
  ------------------
 5702|    343|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5702:2): [True: 94, False: 692]
  ------------------
 5703|    343|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5703:2): [True: 0, False: 786]
  ------------------
 5704|    343|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5704:2): [True: 0, False: 786]
  ------------------
 5705|    356|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5705:2): [True: 13, False: 773]
  ------------------
 5706|    356|		r2 = piv_process_ccc(card);
 5707|    356|		sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    356|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5708|    356|				card->type, r2, priv->card_issues, r, priv->alg_ids);
 5709|       |		/* Ignore any error. */
 5710|       |		/* If CCC says it has CAC with PKI on card set to one of the SC_CARD_TYPE_PIV_II_*_DUAL_CAC */
 5711|    356|		if (priv->ccc_flags & PIV_CCC_F3_CAC_PKI) {
  ------------------
  |  |  171|    356|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
  |  Branch (5711:7): [True: 6, False: 350]
  ------------------
 5712|      6|			switch (card->type) {
  ------------------
  |  Branch (5712:12): [True: 6, False: 0]
  ------------------
 5713|      0|			case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5713:4): [True: 0, False: 6]
  ------------------
 5714|      0|			case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5714:4): [True: 0, False: 6]
  ------------------
 5715|      5|			case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5715:4): [True: 5, False: 1]
  ------------------
 5716|      5|			case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5716:4): [True: 0, False: 6]
  ------------------
 5717|      5|				card->type = SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC;
 5718|      5|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  578|      5|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5719|      5|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      5|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5720|      5|				break;
 5721|      0|			case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5721:4): [True: 0, False: 6]
  ------------------
 5722|      0|				card->type = SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC;
 5723|      0|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  578|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5724|      0|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5725|      0|				break;
 5726|      1|			case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5726:4): [True: 1, False: 5]
  ------------------
 5727|      1|				card->type = SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC;
 5728|      1|				priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  578|      1|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5729|      1|				priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      1|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5730|      1|				break;
 5731|      6|			}
 5732|      6|		}
 5733|    356|		break;
 5734|       |
 5735|    356|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5735:2): [True: 0, False: 786]
  ------------------
 5736|      0|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5736:2): [True: 0, False: 786]
  ------------------
 5737|      0|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5737:2): [True: 0, False: 786]
  ------------------
 5738|      0|		priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  578|      0|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5739|      0|		priv->obj_cache[PIV_OBJ_DISCOVERY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5740|      0|		break;
 5741|    786|	}
 5742|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5743|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5744|       |
 5745|       |	/* If contactless or run as virtual card try to get alg refs from AC entries in response to SELECT AID */
 5746|    786|	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  377|    786|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
              	if (!(priv->init_flags & PIV_INIT_AID_PARSED) && priv->init_flags & PIV_INIT_CONTACTLESS) {
  ------------------
  |  |  382|    238|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (5746:6): [True: 238, False: 548]
  |  Branch (5746:51): [True: 0, False: 238]
  ------------------
 5747|      0|		r2 = piv_find_aid(card);
 5748|      0|	}
 5749|       |
 5750|       |	/* Read AID if needed for these cards types */
 5751|    786|	if (!(priv->init_flags & PIV_INIT_AID_PARSED)) {
  ------------------
  |  |  377|    786|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
  |  Branch (5751:6): [True: 238, False: 548]
  ------------------
 5752|    238|		switch (card->type) {
  ------------------
  |  Branch (5752:11): [True: 1, False: 237]
  ------------------
 5753|      0|		case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5753:3): [True: 0, False: 238]
  ------------------
 5754|      0|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5754:3): [True: 0, False: 238]
  ------------------
 5755|      0|		case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5755:3): [True: 0, False: 238]
  ------------------
 5756|      0|		case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5756:3): [True: 0, False: 238]
  ------------------
 5757|      1|		case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5757:3): [True: 1, False: 237]
  ------------------
 5758|      1|		case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5758:3): [True: 0, False: 238]
  ------------------
 5759|      1|			r2 = piv_find_aid(card);
 5760|    238|		}
 5761|    238|	}
 5762|       |
 5763|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5764|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5765|       |
 5766|       |	/* if card did not specify any of the NIST basic alg_ids add them */
 5767|    786|	if ((priv->alg_ids & AI_NIST) == 0) {
  ------------------
  |  |  597|    786|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  588|    786|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  589|    786|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  590|    786|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  592|    786|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  593|    786|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
  |  Branch (5767:6): [True: 786, False: 0]
  ------------------
 5768|    786|		priv->alg_ids |= AI_NIST;
  ------------------
  |  |  597|    786|#define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  588|    786|#define AI_RSA_1024			    0x00000001U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  589|    786|#define AI_RSA_2048			    0x00000002U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  590|    786|#define AI_RSA_3072			    0x00000004U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  592|    786|#define AI_EC_256			    0x00000100U
  |  |  ------------------
  |  |               #define AI_NIST (AI_RSA_1024 | AI_RSA_2048 | AI_RSA_3072 | AI_EC_256 | AI_EC_384)
  |  |  ------------------
  |  |  |  |  593|    786|#define AI_EC_384			    0x00000200U
  |  |  ------------------
  ------------------
 5769|    786|	}
 5770|       |
 5771|       |	/* If unknown card has 800-73-4 features, it must be based on 800-73-4 or above */
 5772|    786|	switch (card->type) {
  ------------------
  |  Branch (5772:10): [True: 249, False: 537]
  ------------------
 5773|    249|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5773:2): [True: 249, False: 537]
  ------------------
 5774|    249|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5774:2): [True: 0, False: 786]
  ------------------
 5775|    249|		if (priv->init_flags & PIV_INIT_AID_AC_SM) {
  ------------------
  |  |  378|    249|#define PIV_INIT_AID_AC_SM			0x00000002u
  ------------------
  |  Branch (5775:7): [True: 0, False: 249]
  ------------------
 5776|      0|			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5777|      0|		}
 5778|       |
 5779|       |#ifdef ENABLE_PIV_SM
 5780|       |		/* Discovery object has pin policy. 800-74-4 bits, its at least SC_CARD_TYPE_PIV_II_800_73_4 */
 5781|       |		if ((priv->pin_policy & (PIV_PP_OCC | PIV_PP_VCI_IMPL | PIV_PP_VCI_WITHOUT_PC)) != 0) {
 5782|       |			card->type = SC_CARD_TYPE_PIV_II_800_73_4;
 5783|       |		}
 5784|       |#endif
 5785|    249|		break;
 5786|    786|	}
 5787|       |
 5788|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5789|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5790|       |
 5791|       |	/*
 5792|       |	 * Set card_issues flags based card->type and version numbers if available.
 5793|       |	 *
 5794|       |	 * YubiKey NEO, Yubikey 4 and other devices with PIV applets, have compliance
 5795|       |	 * issues with the NIST 800-73-3 specs. The OpenSC developers do not have
 5796|       |	 * access to all the different devices or versions of the devices.
 5797|       |	 * Vendor and user input is welcome on any compliance issues.
 5798|       |	 *
 5799|       |	 * For the Yubico devices The assumption is also made that if a bug is
 5800|       |	 * fixed in a Yubico version that means it is fixed on both NEO and Yubikey 4.
 5801|       |	 *
 5802|       |	 * The flags CI_CANT_USE_GETDATA_FOR_STATE and CI_DISCOVERY_USELESS
 5803|       |	 * may be set earlier or later then in the following code.
 5804|       |	 */
 5805|       |
 5806|    786|	sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   70|    786|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5807|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5808|    786|	switch (card->type) {
 5809|    272|	case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (5809:2): [True: 272, False: 514]
  ------------------
 5810|    272|		priv->card_issues |= CI_NO_EC384 |
  ------------------
  |  |  584|    272|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
 5811|    272|				     CI_VERIFY_630X |
  ------------------
  |  |  572|    272|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
 5812|    272|				     CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  581|    272|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5813|    272|				     CI_LEAKS_FILE_NOT_FOUND |
  ------------------
  |  |  577|    272|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5814|    272|				     CI_NFC_EXPOSE_TOO_MUCH;
  ------------------
  |  |  582|    272|#define CI_NFC_EXPOSE_TOO_MUCH		    0x00000200U /* PIN, crypto and objects exposed over NFS in violation of 800-73-3 */
  ------------------
 5815|    272|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5815:7): [True: 166, False: 106]
  ------------------
 5816|    166|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  573|    166|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5817|    272|		break;
 5818|       |
 5819|    111|	case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (5819:2): [True: 111, False: 675]
  ------------------
 5820|    111|	case SC_CARD_TYPE_PIV_II_PIVAPPLET:
  ------------------
  |  Branch (5820:2): [True: 0, False: 786]
  ------------------
 5821|    112|	case SC_CARD_TYPE_PIV_II_TOKEN2:
  ------------------
  |  Branch (5821:2): [True: 1, False: 785]
  ------------------
 5822|    112|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE |
  ------------------
  |  |  581|    112|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5823|    112|				     CI_LEAKS_FILE_NOT_FOUND;
  ------------------
  |  |  577|    112|#define CI_LEAKS_FILE_NOT_FOUND		    0x00000010U /* GET DATA of empty object returns 6A 82 even if PIN not verified */
  ------------------
 5824|    112|		if (priv->yubico_version < 0x00040302)
  ------------------
  |  Branch (5824:7): [True: 27, False: 85]
  ------------------
 5825|     27|			priv->card_issues |= CI_VERIFY_LC0_FAIL;
  ------------------
  |  |  573|     27|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5826|    112|		if (priv->yubico_version >= 0x00050700) /* Also used by Token2 */
  ------------------
  |  Branch (5826:7): [True: 80, False: 32]
  ------------------
 5827|     80|			priv->alg_ids |= AI_RSA_4096 | AI_25519;
  ------------------
  |  |  591|     80|#define AI_RSA_4096			    0x00000008U
  ------------------
              			priv->alg_ids |= AI_RSA_4096 | AI_25519;
  ------------------
  |  |  594|     80|#define AI_25519			    0x00100000U
  ------------------
 5828|    112|		break;
 5829|       |
 5830|      0|	case SC_CARD_TYPE_PIV_II_NITROKEY:
  ------------------
  |  Branch (5830:2): [True: 0, False: 786]
  ------------------
 5831|      0|		priv->card_issues |= CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  581|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5832|      0|		if (priv->yubico_version >= 0x00010802) /* use for NitroKey too */
  ------------------
  |  Branch (5832:7): [True: 0, False: 0]
  ------------------
 5833|      0|			priv->alg_ids |= AI_RSA_4096;
  ------------------
  |  |  591|      0|#define AI_RSA_4096			    0x00000008U
  ------------------
 5834|      0|		break;
 5835|       |
 5836|      0|	case SC_CARD_TYPE_PIV_II_GI_DE:
  ------------------
  |  Branch (5836:2): [True: 0, False: 786]
  ------------------
 5837|     12|	case SC_CARD_TYPE_PIV_II_OBERTHUR:
  ------------------
  |  Branch (5837:2): [True: 12, False: 774]
  ------------------
 5838|     12|	case SC_CARD_TYPE_PIV_II_GEMALTO:
  ------------------
  |  Branch (5838:2): [True: 0, False: 786]
  ------------------
 5839|     12|	case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (5839:2): [True: 0, False: 786]
  ------------------
 5840|     12|		priv->card_issues |= 0; /* could add others here */
 5841|     12|		break;
 5842|       |
 5843|    249|	case SC_CARD_TYPE_PIV_II_BASE:
  ------------------
  |  Branch (5843:2): [True: 249, False: 537]
  ------------------
 5844|    338|	case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (5844:2): [True: 89, False: 697]
  ------------------
 5845|    338|	case SC_CARD_TYPE_PIV_II_800_73_4:
  ------------------
  |  Branch (5845:2): [True: 0, False: 786]
  ------------------
 5846|    338|		priv->card_issues |= 0; /* could add others here */
 5847|    338|		break;
 5848|       |
 5849|      5|	case SC_CARD_TYPE_PIV_II_GI_DE_DUAL_CAC:
  ------------------
  |  Branch (5849:2): [True: 5, False: 781]
  ------------------
 5850|      5|	case SC_CARD_TYPE_PIV_II_GEMALTO_DUAL_CAC:
  ------------------
  |  Branch (5850:2): [True: 0, False: 786]
  ------------------
 5851|      6|	case SC_CARD_TYPE_PIV_II_OBERTHUR_DUAL_CAC:
  ------------------
  |  Branch (5851:2): [True: 1, False: 785]
  ------------------
 5852|      6|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  573|      6|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5853|      6|				     CI_PIV_AID_LOSE_STATE |
  ------------------
  |  |  579|      6|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5854|      6|				     CI_NO_RANDOM |
  ------------------
  |  |  575|      6|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5855|      6|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  581|      6|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5856|      6|		break;
 5857|       |
 5858|      0|	case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (5858:2): [True: 0, False: 786]
  ------------------
 5859|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  573|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5860|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  581|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5861|      0|		break;
 5862|       |
 5863|     46|	case SC_CARD_TYPE_PIV_II_PIVKEY:
  ------------------
  |  Branch (5863:2): [True: 46, False: 740]
  ------------------
 5864|     46|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  573|     46|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5865|     46|				     CI_PIV_AID_LOSE_STATE | /* be conservative */
  ------------------
  |  |  579|     46|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
 5866|     46|				     CI_NO_RANDOM;	     /* does not have 9B key */
  ------------------
  |  |  575|     46|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
 5867|       |							     /* Discovery object returns 6A 82 so is not on card by default */
 5868|     46|		break;
 5869|       |
 5870|      0|	default:
  ------------------
  |  Branch (5870:2): [True: 0, False: 786]
  ------------------
 5871|      0|		priv->card_issues |= CI_VERIFY_LC0_FAIL |
  ------------------
  |  |  573|      0|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
 5872|      0|				     CI_OTHER_AID_LOSE_STATE;
  ------------------
  |  |  581|      0|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
 5873|       |		/* opensc.conf may have it wrong, continue anyway */
 5874|      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__
  |  |  ------------------
  ------------------
 5875|      0|		card->type = SC_CARD_TYPE_PIV_II_GENERIC;
 5876|    786|	}
 5877|    786|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    786|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5878|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5879|       |
 5880|    786|	if (!(priv->card_issues & CI_DISCOVERY_USELESS) && !(priv->init_flags & PIV_INIT_DISCOVERY_PARSED)) {
  ------------------
  |  |  578|    786|#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)) {
  ------------------
  |  |  379|    780|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
  |  Branch (5880:6): [True: 780, False: 6]
  |  Branch (5880:53): [True: 543, False: 237]
  ------------------
 5881|       |		/*
 5882|       |		 * We now know PIV AID is active, test DISCOVERY object again
 5883|       |		 * Some PIV don't support DISCOVERY and return
 5884|       |		 * SC_ERROR_INCORRECT_PARAMETERS. Any error
 5885|       |		 * including SC_ERROR_FILE_NOT_FOUND means we cannot use discovery
 5886|       |		 * to test for active AID.
 5887|       |		 */
 5888|    543|		r2 = piv_find_discovery(card);
 5889|       |
 5890|    543|		if (r2 < 0) {
  ------------------
  |  Branch (5890:7): [True: 459, False: 84]
  ------------------
 5891|    459|			priv->card_issues |= CI_DISCOVERY_USELESS;
  ------------------
  |  |  578|    459|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
 5892|    459|			piv_obj_cache_free_entry(card, PIV_OBJ_DISCOVERY, PIV_OBJ_CACHE_NOT_PRESENT);
  ------------------
  |  |  150|    459|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5893|    459|		}
 5894|    543|	}
 5895|       |
 5896|    786|	sc_log(card->ctx, "PIV_MATCH card->type:%d r2:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|    786|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5897|    786|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5898|       |	/* Matched, caller will use or free priv and sc_lock as needed */
 5899|    786|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    786|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    786|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    786|	int _ret = r; \
  |  |  |  |  155|    786|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 786, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    786|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 786]
  |  |  |  |  ------------------
  |  |  |  |  157|    786|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    786|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    786|	return _ret; \
  |  |  |  |  163|    786|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5900|       |
 5901|  4.28k|err:
 5902|  4.28k|	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.28k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5903|  4.28k|			card->type, r2, priv->card_issues, r, priv->alg_ids);
 5904|       |	/* don't match. Does not have a PIV applet. */
 5905|  4.28k|	piv_finish(card);
 5906|  4.28k|	card->type = saved_type;
 5907|  4.28k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.28k|	int _ret = r; \
  |  |  |  |  155|  4.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.28k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.28k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.28k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.28k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.28k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.28k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.28k|	return _ret; \
  |  |  |  |  163|  4.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5908|  4.28k|}
card-piv.c:piv_find_discovery:
 5057|  4.28k|{
 5058|  4.28k|	int r = 0;
 5059|  4.28k|	size_t rbuflen;
 5060|  4.28k|	u8 *rbuf = NULL;
 5061|  4.28k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  4.28k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5062|       |
 5063|  4.28k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  4.28k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  4.28k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  4.28k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 4.28k]
  |  |  ------------------
  ------------------
 5064|       |
 5065|       |	/*
 5066|       |	 * During piv_card_reader_lock_obtained,
 5067|       |	 * we use the discovery object to test if card present, and
 5068|       |	 * if PIV AID is active.
 5069|       |	 */
 5070|  4.28k|	if (priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  150|  4.28k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (5070:6): [True: 0, False: 4.28k]
  ------------------
 5071|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 5072|      0|		goto end;
 5073|      0|	}
 5074|       |
 5075|       |	/* If not valid: read, test,  cache */
 5076|  4.28k|	if (!(priv->obj_cache[PIV_OBJ_DISCOVERY].flags & PIV_OBJ_CACHE_VALID)) {
  ------------------
  |  |  148|  4.28k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (5076:6): [True: 1.21k, False: 3.07k]
  ------------------
 5077|  1.21k|		r = piv_process_discovery(card);
 5078|  3.07k|	} else {
 5079|       |		/* if already in cache,force read */
 5080|  3.07k|		rbuflen = 1;
 5081|  3.07k|		r = piv_get_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 5082|       |		/* if same response as last, no need to parse */
 5083|  3.07k|		if (r == 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == 0)
  ------------------
  |  Branch (5083:7): [True: 0, False: 3.07k]
  |  Branch (5083:17): [True: 0, False: 0]
  ------------------
 5084|      0|			goto end;
 5085|       |
 5086|  3.07k|		if (r >= 0 && priv->obj_cache[PIV_OBJ_DISCOVERY].obj_len == rbuflen &&
  ------------------
  |  Branch (5086:7): [True: 25, False: 3.04k]
  |  Branch (5086:17): [True: 18, False: 7]
  ------------------
 5087|     18|				priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data &&
  ------------------
  |  Branch (5087:5): [True: 18, False: 0]
  ------------------
 5088|     18|				!memcmp(rbuf, priv->obj_cache[PIV_OBJ_DISCOVERY].obj_data, rbuflen)) {
  ------------------
  |  Branch (5088:5): [True: 9, False: 9]
  ------------------
 5089|      9|			goto end;
 5090|      9|		}
 5091|       |		/* This should not happen  bad card */
 5092|  3.06k|		sc_log(card->ctx, "Discovery not the same as previously read object");
  ------------------
  |  |   71|  3.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5093|  3.06k|		r = SC_ERROR_CORRUPTED_DATA;
  ------------------
  |  |   68|  3.06k|#define SC_ERROR_CORRUPTED_DATA			-1218
  ------------------
 5094|  3.06k|		goto end;
 5095|  3.07k|	}
 5096|       |
 5097|  4.28k|end:
 5098|  4.28k|	free(rbuf);
 5099|  4.28k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  4.28k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.28k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.28k|	int _ret = r; \
  |  |  |  |  155|  4.28k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.27k, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.27k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  3.95k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.95k, False: 322]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.27k|	} 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|  4.28k|	return _ret; \
  |  |  |  |  163|  4.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5100|  4.28k|}
card-piv.c:piv_process_discovery:
 4950|  1.21k|{
 4951|  1.21k|	int r;
 4952|  1.21k|	u8 *rbuf = NULL;
 4953|  1.21k|	size_t rbuflen = 0;
 4954|       |
 4955|  1.21k|	r = piv_get_cached_data(card, PIV_OBJ_DISCOVERY, &rbuf, &rbuflen);
 4956|       |	/* Note rbuf and rbuflen are now pointers into cache */
 4957|  1.21k|	if (r < 0)
  ------------------
  |  Branch (4957:6): [True: 850, False: 364]
  ------------------
 4958|    850|		goto err;
 4959|       |
 4960|       |	/* the object is now cached, see what we have */
 4961|    364|	r = piv_parse_discovery(card, rbuf, rbuflen, 0);
 4962|       |
 4963|  1.21k|err:
 4964|  1.21k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.21k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.21k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.21k|	int _ret = r; \
  |  |  |  |  155|  1.21k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.21k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.21k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    892|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 892, False: 322]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.21k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.21k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.21k|	return _ret; \
  |  |  |  |  163|  1.21k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4965|  1.21k|}
card-piv.c:piv_get_cached_data:
 3189|  11.1k|{
 3190|       |
 3191|  11.1k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  11.1k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3192|  11.1k|	int r;
 3193|  11.1k|	u8 *rbuf = NULL;
 3194|  11.1k|	size_t rbuflen;
 3195|       |
 3196|  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]
  |  |  ------------------
  ------------------
 3197|       |
 3198|  11.1k|	if (enumtag < 0 || enumtag >= PIV_OBJ_LAST_ENUM)
  ------------------
  |  Branch (3198:6): [True: 0, False: 11.1k]
  |  Branch (3198:21): [True: 0, False: 11.1k]
  ------------------
 3199|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3200|       |
 3201|  11.1k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 3202|       |
 3203|       |	/* see if we have it cached */
 3204|  11.1k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_VALID) {
  ------------------
  |  |  148|  11.1k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
  |  Branch (3204:6): [True: 1.49k, False: 9.62k]
  ------------------
 3205|       |
 3206|  1.49k|		sc_log(card->ctx,
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 3207|  1.49k|				"found #%d %p:%" SC_FORMAT_LEN_SIZE_T "u %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3208|  1.49k|				enumtag,
 3209|  1.49k|				priv->obj_cache[enumtag].obj_data,
 3210|  1.49k|				priv->obj_cache[enumtag].obj_len,
 3211|  1.49k|				priv->obj_cache[enumtag].internal_obj_data,
 3212|  1.49k|				priv->obj_cache[enumtag].internal_obj_len);
 3213|       |
 3214|  1.49k|		if (priv->obj_cache[enumtag].obj_len == 0) {
  ------------------
  |  Branch (3214:7): [True: 0, False: 1.49k]
  ------------------
 3215|      0|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3216|      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__
  |  |  ------------------
  ------------------
 3217|      0|			goto err;
 3218|      0|		}
 3219|  1.49k|		*buf = priv->obj_cache[enumtag].obj_data;
 3220|  1.49k|		*buf_len = priv->obj_cache[enumtag].obj_len;
 3221|  1.49k|		r = (int)*buf_len;
 3222|  1.49k|		goto ok;
 3223|  1.49k|	}
 3224|       |
 3225|       |	/*
 3226|       |	 * If we know it can not be on the card  i.e. History object
 3227|       |	 * has been read, and we know what other certs may or
 3228|       |	 * may not be on the card. We can avoid extra overhead
 3229|       |	 * Also used if object on card was not parsable
 3230|       |	 */
 3231|       |
 3232|  9.62k|	if (priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT) {
  ------------------
  |  |  150|  9.62k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (3232:6): [True: 0, False: 9.62k]
  ------------------
 3233|      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__
  |  |  ------------------
  ------------------
 3234|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3235|      0|		goto err;
 3236|      0|	}
 3237|       |
 3238|       |	/* Not cached, try to get it, piv_get_data will allocate a buf */
 3239|  9.62k|	sc_log(card->ctx, "get #%d", enumtag);
  ------------------
  |  |   71|  9.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__
  |  |  ------------------
  ------------------
 3240|  9.62k|	rbuflen = 1;
 3241|  9.62k|	r = piv_get_data(card, enumtag, &rbuf, &rbuflen);
 3242|  9.62k|	if (r > 0) {
  ------------------
  |  Branch (3242:6): [True: 2.30k, False: 7.31k]
  ------------------
 3243|  2.30k|		priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|  2.30k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3244|  2.30k|		priv->obj_cache[enumtag].obj_len = r;
 3245|  2.30k|		priv->obj_cache[enumtag].obj_data = rbuf;
 3246|  2.30k|		*buf = rbuf;
 3247|  2.30k|		*buf_len = r;
 3248|       |
 3249|  2.30k|		sc_log(card->ctx,
  ------------------
  |  |   71|  2.30k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3250|  2.30k|				"added #%d  %p:%" SC_FORMAT_LEN_SIZE_T "u %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3251|  2.30k|				enumtag,
 3252|  2.30k|				priv->obj_cache[enumtag].obj_data,
 3253|  2.30k|				priv->obj_cache[enumtag].obj_len,
 3254|  2.30k|				priv->obj_cache[enumtag].internal_obj_data,
 3255|  2.30k|				priv->obj_cache[enumtag].internal_obj_len);
 3256|       |
 3257|  7.31k|	} else {
 3258|  7.31k|		free(rbuf);
 3259|  7.31k|		if (r == 0 || r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|  7.31k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (3259:7): [True: 0, False: 7.31k]
  |  Branch (3259:17): [True: 1.34k, False: 5.97k]
  ------------------
 3260|  1.34k|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|  1.34k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3261|  1.34k|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|  1.34k|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 3262|  1.34k|			priv->obj_cache[enumtag].obj_len = 0;
 3263|  5.97k|		} else {
 3264|  5.97k|			goto err;
 3265|  5.97k|		}
 3266|  7.31k|	}
 3267|  5.14k|ok:
 3268|       |
 3269|  11.1k|err:
 3270|  11.1k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  11.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.1k|	int _ret = r; \
  |  |  |  |  155|  11.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.31k, False: 3.80k]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|  7.31k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.31k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.31k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.31k|	} else { \
  |  |  |  |  159|  3.80k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.80k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.80k|	} \
  |  |  |  |  162|  11.1k|	return _ret; \
  |  |  |  |  163|  11.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3271|  11.1k|}
card-piv.c:piv_parse_discovery:
 4893|    364|{
 4894|    364|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    364|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4895|    364|	int r = 0;
 4896|    364|	const u8 *body;
 4897|    364|	size_t bodylen;
 4898|    364|	const u8 *aid;
 4899|    364|	size_t aidlen;
 4900|    364|	const u8 *pinp;
 4901|    364|	size_t pinplen;
 4902|    364|	unsigned int cla_out, tag_out;
 4903|       |
 4904|    364|	if (rbuflen != 0) {
  ------------------
  |  Branch (4904:6): [True: 364, False: 0]
  ------------------
 4905|    364|		body = rbuf;
 4906|    364|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    728|#define SC_SUCCESS				0
  ------------------
  |  Branch (4906:7): [True: 0, False: 364]
  ------------------
 4907|    364|				body == NULL ||
  ------------------
  |  Branch (4907:5): [True: 0, False: 364]
  ------------------
 4908|    364|				bodylen == 0 ||
  ------------------
  |  Branch (4908:5): [True: 3, False: 361]
  ------------------
 4909|    361|				((cla_out | tag_out) != 0x7E)) {
  ------------------
  |  Branch (4909:5): [True: 0, False: 361]
  ------------------
 4910|      3|			sc_log(card->ctx, "DER problem %d", r);
  ------------------
  |  |   71|      3|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4911|      3|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 4912|      3|			goto err;
 4913|      3|		}
 4914|       |
 4915|    361|		sc_log(card->ctx,
  ------------------
  |  |   71|    361|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4916|    361|				"Discovery 0x%2.2x 0x%2.2x %p:%" SC_FORMAT_LEN_SIZE_T "u",
 4917|    361|				cla_out, tag_out, body, bodylen);
 4918|    361|		aidlen = 0;
 4919|    361|		aid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x4F, &aidlen);
 4920|    361|		if (aid == NULL || aidlen < piv_aids[0].len_short ||
  ------------------
  |  Branch (4920:7): [True: 14, False: 347]
  |  Branch (4920:22): [True: 1, False: 346]
  ------------------
 4921|    346|				memcmp(aid, piv_aids[0].value, piv_aids[0].len_short) != 0) {
  ------------------
  |  Branch (4921:5): [True: 24, False: 322]
  ------------------
 4922|     39|			sc_log(card->ctx, "Discovery object not PIV");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4923|     39|			r = SC_ERROR_INVALID_CARD; /* This is an error */
  ------------------
  |  |   60|     39|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
 4924|     39|			goto err;
 4925|     39|		}
 4926|    322|		if (aid_only == 0) {
  ------------------
  |  Branch (4926:7): [True: 322, False: 0]
  ------------------
 4927|    322|			pinp = sc_asn1_find_tag(card->ctx, body, bodylen, 0x5F2F, &pinplen);
 4928|    322|			if (pinp && pinplen == 2) {
  ------------------
  |  Branch (4928:8): [True: 145, False: 177]
  |  Branch (4928:16): [True: 143, False: 2]
  ------------------
 4929|    143|				priv->init_flags |= PIV_INIT_DISCOVERY_PP;
  ------------------
  |  |  380|    143|#define PIV_INIT_DISCOVERY_PP			0x00000008u
  ------------------
 4930|    143|				priv->pin_policy = (*pinp << 8) + *(pinp + 1);
 4931|    143|				sc_log(card->ctx, "Discovery pinp flags=0x%2.2x 0x%2.2x", *pinp, *(pinp + 1));
  ------------------
  |  |   71|    143|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 4932|    143|				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  368|    143|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  369|    143|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  368|    143|#define PIV_PP_PIN		0x00004000u
  ------------------
              				if ((priv->pin_policy & (PIV_PP_PIN | PIV_PP_GLOBAL)) == (PIV_PP_PIN | PIV_PP_GLOBAL) &&
  ------------------
  |  |  369|    143|#define PIV_PP_GLOBAL		0x00002000u
  ------------------
  |  Branch (4932:9): [True: 3, False: 140]
  ------------------
 4933|      3|						priv->pin_policy & PIV_PP_GLOBAL_PRIMARY) {
  ------------------
  |  |  374|      3|#define PIV_PP_GLOBAL_PRIMARY	0x00000020u
  ------------------
  |  Branch (4933:7): [True: 1, False: 2]
  ------------------
 4934|      1|					sc_log(card->ctx, "Pin Preference - Global");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4935|      1|					priv->pin_preference = 0x00;
 4936|      1|				}
 4937|    143|			}
 4938|    322|		}
 4939|    322|		r = SC_SUCCESS;
  ------------------
  |  |   28|    322|#define SC_SUCCESS				0
  ------------------
 4940|    322|		priv->init_flags |= PIV_INIT_DISCOVERY_PARSED;
  ------------------
  |  |  379|    322|#define PIV_INIT_DISCOVERY_PARSED		0x00000004u
  ------------------
 4941|    322|	}
 4942|       |
 4943|    364|err:
 4944|    364|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    364|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    364|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    364|	int _ret = r; \
  |  |  |  |  155|    364|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 364, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    364|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 322]
  |  |  |  |  ------------------
  |  |  |  |  157|    364|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    364|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    364|	return _ret; \
  |  |  |  |  163|    364|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4945|    364|}
card-piv.c:piv_get_data:
 3077|  12.7k|{
 3078|  12.7k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  12.7k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3079|  12.7k|	u8 *p;
 3080|  12.7k|	u8 *tbuf;
 3081|  12.7k|	int r = 0;
 3082|  12.7k|	u8 tagbuf[8];
 3083|  12.7k|	size_t tag_len;
 3084|  12.7k|	int alloc_buf = 0;
 3085|       |
 3086|  12.7k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  12.7k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  12.7k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  12.7k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 12.7k]
  |  |  ------------------
  ------------------
 3087|       |
 3088|  12.7k|	sc_log(card->ctx, "#%d, %s", enumtag, piv_objects[enumtag].name);
  ------------------
  |  |   71|  12.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3089|       |
 3090|  12.7k|	r = sc_lock(card); /* do check len and get data in same transaction */
 3091|  12.7k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  12.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3091:6): [True: 0, False: 12.7k]
  ------------------
 3092|      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__
  |  |  ------------------
  ------------------
 3093|      0|		return r;
 3094|      0|	}
 3095|       |
 3096|  12.7k|	tag_len = piv_objects[enumtag].tag_len;
 3097|       |
 3098|  12.7k|	p = tagbuf;
 3099|  12.7k|	r = sc_asn1_put_tag(0x5c, piv_objects[enumtag].tag_value, tag_len, tagbuf, sizeof(tagbuf), &p);
 3100|  12.7k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  12.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3100:6): [True: 0, False: 12.7k]
  ------------------
 3101|      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__
  |  |  ------------------
  ------------------
 3102|      0|		goto err;
 3103|      0|	}
 3104|       |
 3105|  12.7k|	if (*buf_len == 1 && *buf == NULL) {
  ------------------
  |  Branch (3105:6): [True: 12.6k, False: 35]
  |  Branch (3105:23): [True: 12.6k, False: 0]
  ------------------
 3106|  12.6k|		*buf_len = priv->max_object_size; /* will allocate below */
 3107|  12.6k|		alloc_buf = 1;
 3108|  12.6k|	}
 3109|       |
 3110|  12.7k|	sc_log(card->ctx,
  ------------------
  |  |   71|  12.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3111|  12.7k|			"buffer for #%d *buf=0x%p len=%" SC_FORMAT_LEN_SIZE_T "u",
 3112|  12.7k|			enumtag, *buf, *buf_len);
 3113|  12.7k|	if (*buf == NULL && *buf_len > 0) {
  ------------------
  |  Branch (3113:6): [True: 12.6k, False: 35]
  |  Branch (3113:22): [True: 12.6k, False: 0]
  ------------------
 3114|  12.6k|		if (*buf_len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  12.6k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (3114:7): [True: 0, False: 12.6k]
  ------------------
 3115|      0|			r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 3116|      0|			goto err;
 3117|      0|		}
 3118|  12.6k|		*buf = malloc(*buf_len);
 3119|  12.6k|		if (*buf == NULL) {
  ------------------
  |  Branch (3119:7): [True: 0, False: 12.6k]
  ------------------
 3120|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3121|      0|			goto err;
 3122|      0|		}
 3123|  12.6k|	}
 3124|       |
 3125|       |#ifdef ENABLE_PIV_SM
 3126|       |	/*
 3127|       |	 * Over contact reader, OK to read non sensitive object in clear even when SM is active
 3128|       |	 * but only if using default policy and we are not in reader_lock_obtained
 3129|       |	 * Discovery object will use SM from reader_lock_obtained to catch if SM is still valid
 3130|       |	 * i.e. no interference from other applications
 3131|       |	 */
 3132|       |	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",
 3133|       |			enumtag, card->sm_ctx.sm_mode, piv_objects[enumtag].flags, priv->sm_flags, priv->init_flags);
 3134|       |	if (priv->sm_flags & PIV_SM_FLAGS_SM_IS_ACTIVE &&
 3135|       |			enumtag != PIV_OBJ_DISCOVERY &&
 3136|       |			card->sm_ctx.sm_mode == SM_MODE_TRANSMIT &&
 3137|       |			!(piv_objects[enumtag].flags & PIV_OBJECT_NEEDS_PIN) &&
 3138|       |			!(priv->sm_flags & (PIV_SM_FLAGS_NEVER | PIV_SM_FLAGS_ALWAYS)) &&
 3139|       |			!(priv->init_flags & (PIV_INIT_CONTACTLESS | PIV_INIT_IN_READER_LOCK_OBTAINED))) {
 3140|       |		sc_log(card->ctx, "Set PIV_SM_GET_DATA_IN_CLEAR");
 3141|       |		priv->sm_flags |= PIV_SM_GET_DATA_IN_CLEAR;
 3142|       |	}
 3143|       |
 3144|       |#endif /* ENABLE_PIV_SM */
 3145|  12.7k|	r = piv_general_io(card, 0xCB, 0x3F, 0xFF, tagbuf, p - tagbuf, *buf, *buf_len);
 3146|  12.7k|	if (r > 0) {
  ------------------
  |  Branch (3146:6): [True: 3.32k, False: 9.40k]
  ------------------
 3147|  3.32k|		int r_tag;
 3148|  3.32k|		unsigned int cla_out, tag_out;
 3149|  3.32k|		size_t bodylen = 0;
 3150|  3.32k|		const u8 *body = *buf;
 3151|  3.32k|		r_tag = sc_asn1_read_tag(&body, r, &cla_out, &tag_out, &bodylen);
 3152|  3.32k|		if (r_tag != SC_SUCCESS || body == NULL ||
  ------------------
  |  |   28|  6.65k|#define SC_SUCCESS				0
  ------------------
  |  Branch (3152:7): [True: 534, False: 2.79k]
  |  Branch (3152:30): [True: 87, False: 2.70k]
  ------------------
 3153|  2.70k|				((cla_out << 24 | tag_out) != piv_objects[enumtag].resp_tag)) {
  ------------------
  |  Branch (3153:5): [True: 377, False: 2.32k]
  ------------------
 3154|    998|			sc_log(card->ctx, "invalid tag or length r_tag:%d body:%p", r_tag, body);
  ------------------
  |  |   71|    998|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 3155|    998|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    998|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3156|    998|			goto err;
 3157|    998|		}
 3158|  2.32k|		*buf_len = (body - *buf) + bodylen;
 3159|  9.40k|	} else if (r == 0) {
  ------------------
  |  Branch (3159:13): [True: 384, False: 9.01k]
  ------------------
 3160|    384|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|    384|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3161|    384|		goto err;
 3162|  9.01k|	} else {
 3163|  9.01k|		goto err;
 3164|  9.01k|	}
 3165|       |
 3166|  2.32k|	if (alloc_buf && *buf) {
  ------------------
  |  Branch (3166:6): [True: 2.32k, False: 1]
  |  Branch (3166:19): [True: 2.32k, False: 0]
  ------------------
 3167|  2.32k|		tbuf = malloc(r);
 3168|  2.32k|		if (tbuf == NULL) {
  ------------------
  |  Branch (3168:7): [True: 0, False: 2.32k]
  ------------------
 3169|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3170|      0|			goto err;
 3171|      0|		}
 3172|  2.32k|		memcpy(tbuf, *buf, r);
 3173|  2.32k|		free(*buf);
 3174|  2.32k|		alloc_buf = 0;
 3175|  2.32k|		*buf = tbuf;
 3176|  2.32k|	}
 3177|       |
 3178|  12.7k|err:
 3179|  12.7k|	if (alloc_buf) {
  ------------------
  |  Branch (3179:6): [True: 10.3k, False: 2.36k]
  ------------------
 3180|  10.3k|		free(*buf);
 3181|  10.3k|		*buf = NULL;
 3182|  10.3k|	}
 3183|  12.7k|	sc_unlock(card);
 3184|  12.7k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  12.7k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.7k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.7k|	int _ret = r; \
  |  |  |  |  155|  12.7k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10.4k, False: 2.32k]
  |  |  |  |  ------------------
  |  |  |  |  156|  10.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|  10.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  10.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  10.4k|	} else { \
  |  |  |  |  159|  2.32k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  2.32k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  2.32k|	} \
  |  |  |  |  162|  12.7k|	return _ret; \
  |  |  |  |  163|  12.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3185|  12.7k|}
card-piv.c:piv_general_io:
 1782|  15.3k|{
 1783|  15.3k|	int r;
 1784|  15.3k|	sc_apdu_t apdu;
 1785|       |
 1786|  15.3k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.3k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.3k]
  |  |  ------------------
  ------------------
 1787|       |
 1788|  15.3k|	r = sc_lock(card);
 1789|  15.3k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|  15.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1789:6): [True: 0, False: 15.3k]
  ------------------
 1790|  15.3k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1791|       |
 1792|  15.3k|	sc_format_apdu(card, &apdu,
 1793|  15.3k|			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  294|  15.3k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
              			recvbuf ? SC_APDU_CASE_4_SHORT : SC_APDU_CASE_3_SHORT,
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (1793:4): [True: 15.3k, False: 0]
  ------------------
 1794|  15.3k|			ins, p1, p2);
 1795|  15.3k|	apdu.flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|  15.3k|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
 1796|       |#ifdef ENABLE_PIV_SM
 1797|       |	if (card->sm_ctx.sm_mode != SM_MODE_NONE && sendbuflen > 255) {
 1798|       |		/* tell apdu.c to not do the chaining, let the SM get_apdu do it */
 1799|       |		apdu.flags |= SC_APDU_FLAGS_SM_CHAINING;
 1800|       |	}
 1801|       |#endif
 1802|  15.3k|	apdu.lc = sendbuflen;
 1803|  15.3k|	apdu.datalen = sendbuflen;
 1804|  15.3k|	apdu.data = sendbuf;
 1805|       |
 1806|  15.3k|	if (recvbuf && recvbuflen) {
  ------------------
  |  Branch (1806:6): [True: 15.3k, False: 0]
  |  Branch (1806:17): [True: 15.3k, False: 0]
  ------------------
 1807|  15.3k|		apdu.le = (recvbuflen > 256) ? 256 : recvbuflen;
  ------------------
  |  Branch (1807:13): [True: 15.2k, False: 35]
  ------------------
 1808|  15.3k|		apdu.resplen = recvbuflen;
 1809|  15.3k|	} else {
 1810|      0|		apdu.le = 0;
 1811|      0|		apdu.resplen = 0;
 1812|      0|	}
 1813|  15.3k|	apdu.resp = recvbuf;
 1814|       |
 1815|       |	/* with new adpu.c and chaining, this actually reads the whole object */
 1816|  15.3k|	r = sc_transmit_apdu(card, &apdu);
 1817|       |
 1818|       |	/* adpu will not have sw1,sw2 set because sc_sm_single_transmit called sc_sm_stop, */
 1819|  15.3k|	if (r < 0) {
  ------------------
  |  Branch (1819:6): [True: 389, False: 14.9k]
  ------------------
 1820|    389|		sc_log(card->ctx, "Transmit failed");
  ------------------
  |  |   71|    389|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1821|    389|		goto err;
 1822|    389|	}
 1823|       |
 1824|  14.9k|	if (apdu.sw1 == 0x69 && apdu.sw2 == 0x88)
  ------------------
  |  Branch (1824:6): [True: 139, False: 14.7k]
  |  Branch (1824:26): [True: 54, False: 85]
  ------------------
 1825|     54|		r = SC_ERROR_SM_INVALID_SESSION_KEY;
  ------------------
  |  |  119|     54|#define SC_ERROR_SM_INVALID_SESSION_KEY		-1604
  ------------------
 1826|  14.8k|	else
 1827|  14.8k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1828|       |
 1829|  14.9k|	if (r < 0) {
  ------------------
  |  Branch (1829:6): [True: 10.7k, False: 4.17k]
  ------------------
 1830|  10.7k|		sc_log(card->ctx, "Card returned error ");
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
 1831|  10.7k|		goto err;
 1832|  10.7k|	}
 1833|       |
 1834|  4.17k|	r = (int)apdu.resplen;
 1835|       |
 1836|  15.3k|err:
 1837|  15.3k|	sc_unlock(card);
 1838|  15.3k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  15.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  15.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  15.3k|	int _ret = r; \
  |  |  |  |  155|  15.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.5k, False: 3.72k]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.5k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.1k, False: 453]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.5k|	} else { \
  |  |  |  |  159|  3.72k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  3.72k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  3.72k|	} \
  |  |  |  |  162|  15.3k|	return _ret; \
  |  |  |  |  163|  15.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1839|  15.3k|}
card-piv.c:piv_obj_cache_free_entry:
 5355|   305k|{
 5356|   305k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|   305k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5357|       |
 5358|   305k|	if (priv->obj_cache[enumtag].obj_data)
  ------------------
  |  Branch (5358:6): [True: 2.30k, False: 302k]
  ------------------
 5359|  2.30k|		free(priv->obj_cache[enumtag].obj_data);
 5360|   305k|	priv->obj_cache[enumtag].obj_data = NULL;
 5361|   305k|	priv->obj_cache[enumtag].obj_len = 0;
 5362|       |
 5363|   305k|	if (priv->obj_cache[enumtag].internal_obj_data)
  ------------------
  |  Branch (5363:6): [True: 1.49k, False: 303k]
  ------------------
 5364|  1.49k|		free(priv->obj_cache[enumtag].internal_obj_data);
 5365|   305k|	priv->obj_cache[enumtag].internal_obj_data = NULL;
 5366|   305k|	priv->obj_cache[enumtag].internal_obj_len = 0;
 5367|   305k|	priv->obj_cache[enumtag].flags = flags;
 5368|       |
 5369|   305k|	return SC_SUCCESS;
  ------------------
  |  |   28|   305k|#define SC_SUCCESS				0
  ------------------
 5370|   305k|}
card-piv.c:piv_find_aid:
 2890|  5.68k|{
 2891|  5.68k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  5.68k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 2892|  5.68k|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
 2893|  5.68k|	int r, i, j;
 2894|  5.68k|	const u8 *tag;
 2895|  5.68k|	size_t taglen;
 2896|  5.68k|	const u8 *nextac;
 2897|  5.68k|	const u8 *next80;
 2898|  5.68k|	const u8 *pix;
 2899|  5.68k|	size_t pixlen;
 2900|  5.68k|	const u8 *al_label;
 2901|  5.68k|	size_t al_labellen;
 2902|  5.68k|	const u8 *actag; /* Cipher Suite */
 2903|  5.68k|	size_t actaglen;
 2904|  5.68k|	const u8 *csai; /* Cipher Suite Algorithm Identifier */
 2905|  5.68k|	size_t csailen;
 2906|  5.68k|	size_t resplen = sizeof(rbuf);
 2907|       |#ifdef ENABLE_PIV_SM
 2908|       |	int found_csai = 0;
 2909|       |#endif
 2910|       |
 2911|  5.68k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  5.68k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  5.68k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  5.68k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 5.68k]
  |  |  ------------------
  ------------------
 2912|       |
 2913|       |	/* first  see if the default application will return a template
 2914|       |	 * that we know about.
 2915|       |	 */
 2916|       |
 2917|  5.68k|	r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, rbuf, &resplen);
 2918|  5.68k|	if (r > 0 && priv->aid_der.value && resplen == priv->aid_der.len && !memcmp(priv->aid_der.value, rbuf, resplen)) {
  ------------------
  |  Branch (2918:6): [True: 0, False: 5.68k]
  |  Branch (2918:15): [True: 0, False: 0]
  |  Branch (2918:38): [True: 0, False: 0]
  |  Branch (2918:70): [True: 0, False: 0]
  ------------------
 2919|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2920|       |		/* no need to parse again, same as last time */
 2921|      0|	}
 2922|  5.68k|	if (r >= 0 && resplen > 2) {
  ------------------
  |  Branch (2922:6): [True: 733, False: 4.94k]
  |  Branch (2922:16): [True: 654, False: 79]
  ------------------
 2923|    654|		tag = sc_asn1_find_tag(card->ctx, rbuf, resplen, 0x61, &taglen);
 2924|    654|		if (tag != NULL) {
  ------------------
  |  Branch (2924:7): [True: 587, False: 67]
  ------------------
 2925|    587|			priv->init_flags |= PIV_INIT_AID_PARSED;
  ------------------
  |  |  377|    587|#define PIV_INIT_AID_PARSED			0x00000001u
  ------------------
 2926|       |			/* look for 800-73-4 0xAC for Cipher Suite Algorithm Identifier Table 14 */
 2927|       |			/* 800-73-4 only expects 1 0xAC tag len 6 with a 80 01 xx 06 01 00
 2928|       |			 * where xx is the SM csID either 27 or 2E.
 2929|       |			 * Some vendors may include entries for supported Algorithms even when
 2930|       |			 * not required. We will use these if possible
 2931|       |			 * Will look for multiple 0x80 with in 0xAC value too.
 2932|       |			 */
 2933|    587|			nextac = tag;
 2934|    633|			while ((actag = sc_asn1_find_tag(card->ctx, nextac, taglen - (nextac - tag),
  ------------------
  |  Branch (2934:11): [True: 46, False: 587]
  ------------------
 2935|    633|						0xAC, &actaglen)) != NULL) {
 2936|     46|				nextac = actag + actaglen;
 2937|       |
 2938|     46|				next80 = actag;
 2939|     81|				while ((csai = sc_asn1_find_tag(card->ctx, next80, actaglen - (next80 - actag),
  ------------------
  |  Branch (2939:12): [True: 35, False: 46]
  ------------------
 2940|     81|							0x80, &csailen)) != NULL) {
 2941|     35|					next80 = csai + csailen;
 2942|     35|					if (csailen == 1) {
  ------------------
  |  Branch (2942:10): [True: 23, False: 12]
  ------------------
 2943|     23|						sc_log(card->ctx, "0xAC 0x80 entry:0x%2.2x found", *csai);
  ------------------
  |  |   71|     23|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2944|     23|						j = piv_ai_map_find_by_id(card, *csai);
 2945|     23|						if (j >= 0) {
  ------------------
  |  Branch (2945:11): [True: 13, False: 10]
  ------------------
 2946|     13|							priv->alg_ids |= ai_map[j].ai_flag;
 2947|     13|							continue;
 2948|     13|						}
 2949|       |#ifdef ENABLE_PIV_SM
 2950|       |						/* check if id is NIST SM */
 2951|       |						for (i = 0; i < PIV_CSS_SIZE; i++) {
 2952|       |							if (*csai != css[i].id)
 2953|       |								continue;
 2954|       |							if (found_csai) {
 2955|       |								sc_log(card->ctx, "found multiple csIDs, using first");
 2956|       |							} else {
 2957|       |								priv->cs = &css[i];
 2958|       |								priv->csID = *csai;
 2959|       |								found_csai++;
 2960|       |								priv->init_flags |= PIV_INIT_AID_AC_SM;
 2961|       |							}
 2962|       |						}
 2963|       |#endif /* ENABLE_PIV_SM */
 2964|     23|					}
 2965|     35|				}
 2966|     46|			}
 2967|       |
 2968|       |			/* Last chance to distinguish card type based on Application Label '50' */
 2969|    587|			al_label = sc_asn1_find_tag(card->ctx, tag, taglen, 0x50, &al_labellen);
 2970|    587|			if (al_label != NULL) {
  ------------------
  |  Branch (2970:8): [True: 3, False: 584]
  ------------------
 2971|      3|				sc_log_hex(card->ctx, "Application Label", al_label, al_labellen);
  ------------------
  |  |  129|      3|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|      3|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2972|      3|				if ((priv->al_label = malloc(al_labellen)) == NULL) {
  ------------------
  |  Branch (2972:9): [True: 0, False: 3]
  ------------------
 2973|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2974|      0|				}
 2975|      3|				memcpy(priv->al_label, al_label, al_labellen);
 2976|      3|				priv->al_labellen = (int)al_labellen;
 2977|      3|			}
 2978|       |
 2979|    587|			pix = sc_asn1_find_tag(card->ctx, tag, taglen, 0x4F, &pixlen);
 2980|    587|			if (pix != NULL) {
  ------------------
  |  Branch (2980:8): [True: 564, False: 23]
  ------------------
 2981|    564|				sc_log(card->ctx, "found PIX");
  ------------------
  |  |   71|    564|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2982|       |
 2983|       |				/* early cards returned full AID, rather then just the pix */
 2984|    577|				for (i = 0; piv_aids[i].len_long != 0; i++) {
  ------------------
  |  Branch (2984:17): [True: 564, False: 13]
  ------------------
 2985|    564|					if ((pixlen >= 6 && memcmp(pix, piv_aids[i].value + 5, piv_aids[i].len_long - 5) == 0) ||
  ------------------
  |  Branch (2985:11): [True: 561, False: 3]
  |  Branch (2985:26): [True: 330, False: 231]
  ------------------
 2986|    234|							((pixlen >= piv_aids[i].len_short && memcmp(pix, piv_aids[i].value,
  ------------------
  |  Branch (2986:10): [True: 230, False: 4]
  |  Branch (2986:45): [True: 221, False: 9]
  ------------------
 2987|    551|													     piv_aids[i].len_short) == 0))) {
 2988|    551|						free(priv->aid_der.value); /* free previous value if any */
 2989|    551|						if ((priv->aid_der.value = malloc(resplen)) == NULL) {
  ------------------
  |  Branch (2989:11): [True: 0, False: 551]
  ------------------
 2990|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2991|      0|						}
 2992|    551|						memcpy(priv->aid_der.value, rbuf, resplen);
 2993|    551|						priv->aid_der.len = resplen;
 2994|    551|						LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  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: 551, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    551|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 551]
  |  |  |  |  ------------------
  |  |  |  |  157|    551|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    551|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    551|	return _ret; \
  |  |  |  |  163|    551|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2995|    551|					}
 2996|    564|				}
 2997|    564|			}
 2998|    587|		}
 2999|    654|	}
 3000|       |
 3001|  5.13k|	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  164|  5.13k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  5.13k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  5.13k|	int _ret = r; \
  |  |  |  |  155|  5.13k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 5.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  5.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|  5.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 5.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  5.13k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  5.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|  5.13k|	return _ret; \
  |  |  |  |  163|  5.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3002|  5.13k|}
card-piv.c:piv_ai_map_find_by_id:
 2873|     23|{
 2874|       |	/* piv_private_data_t * priv = PIV_DATA(card); */
 2875|     23|	int i;
 2876|       |
 2877|    153|	for (i = 0; ai_map[i].ai_id != 0; i++) {
  ------------------
  |  Branch (2877:14): [True: 143, False: 10]
  ------------------
 2878|    143|		if (ai_map[i].ai_id == id)
  ------------------
  |  Branch (2878:7): [True: 13, False: 130]
  ------------------
 2879|     13|			return i;
 2880|    143|	}
 2881|     10|	return -1;
 2882|     23|}
card-piv.c:piv_process_ccc:
 5038|    356|{
 5039|    356|	int r = 0;
 5040|    356|	u8 *rbuf = NULL;
 5041|    356|	size_t rbuflen = 0;
 5042|       |
 5043|    356|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    356|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    356|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    356|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 356]
  |  |  ------------------
  ------------------
 5044|    356|	r = piv_get_cached_data(card, PIV_OBJ_CCC, &rbuf, &rbuflen);
 5045|       |
 5046|    356|	if (r < 0)
  ------------------
  |  Branch (5046:6): [True: 308, False: 48]
  ------------------
 5047|    308|		goto err;
 5048|       |
 5049|       |	/* the object is now cached, see what we have */
 5050|     48|	r = piv_parse_ccc(card, rbuf, rbuflen);
 5051|    356|err:
 5052|    356|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    356|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    356|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    356|	int _ret = r; \
  |  |  |  |  155|    356|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 356, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    356|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    350|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 350, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|    356|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    356|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    356|	return _ret; \
  |  |  |  |  163|    356|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5053|    356|}
card-piv.c:piv_parse_ccc:
 4974|     48|{
 4975|     48|	int r = 0;
 4976|     48|	const u8 *body;
 4977|     48|	size_t bodylen;
 4978|     48|	unsigned int cla_out, tag_out;
 4979|       |
 4980|     48|	u8 tag;
 4981|     48|	const u8 *end;
 4982|     48|	size_t len;
 4983|       |
 4984|     48|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|     48|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4985|       |
 4986|     48|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 4987|       |
 4988|     48|	if (rbuf == NULL || rbuflen == 0) {
  ------------------
  |  Branch (4988:6): [True: 0, False: 48]
  |  Branch (4988:22): [True: 0, False: 48]
  ------------------
 4989|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 4990|      0|		goto err;
 4991|      0|	}
 4992|       |
 4993|       |	/* Outer layer is a DER tlv */
 4994|     48|	body = rbuf;
 4995|     48|	if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|     96|#define SC_SUCCESS				0
  ------------------
  |  Branch (4995:6): [True: 0, False: 48]
  ------------------
 4996|     48|			body == NULL ||
  ------------------
  |  Branch (4996:4): [True: 0, False: 48]
  ------------------
 4997|     48|			bodylen == 0 ||
  ------------------
  |  Branch (4997:4): [True: 1, False: 47]
  ------------------
 4998|     47|			((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_CCC].resp_tag)) {
  ------------------
  |  Branch (4998:4): [True: 0, False: 47]
  ------------------
 4999|      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__
  |  |  ------------------
  ------------------
 5000|      1|		r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      1|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5001|      1|		goto err;
 5002|      1|	}
 5003|       |
 5004|     47|	priv->ccc_flags |= PIV_CCC_FOUND;
  ------------------
  |  |  167|     47|#define PIV_CCC_FOUND		0x00000001
  ------------------
 5005|       |
 5006|       |	/* CCC  entries are simple tlv */
 5007|     47|	end = body + bodylen;
 5008|    408|	for (; (body < end); body += len) {
  ------------------
  |  Branch (5008:9): [True: 402, False: 6]
  ------------------
 5009|    402|		r = sc_simpletlv_read_tag(&body, end - body, &tag, &len);
 5010|    402|		if (r < 0)
  ------------------
  |  Branch (5010:7): [True: 41, False: 361]
  ------------------
 5011|     41|			goto err;
 5012|    361|		switch (tag) {
  ------------------
  |  Branch (5012:11): [True: 88, False: 273]
  ------------------
 5013|     34|		case PIV_CCC_TAG_F0:
  ------------------
  |  |  173|     34|#define PIV_CCC_TAG_F0		0xF0
  ------------------
  |  Branch (5013:3): [True: 34, False: 327]
  ------------------
 5014|     34|			if (len == 0x15) {
  ------------------
  |  Branch (5014:8): [True: 22, False: 12]
  ------------------
 5015|     22|				if (memcmp(body, "\xA0\x00\x00\x03\08", 5) == 0)
  ------------------
  |  Branch (5015:9): [True: 3, False: 19]
  ------------------
 5016|      3|					priv->ccc_flags |= PIV_CCC_F0_PIV;
  ------------------
  |  |  168|      3|#define PIV_CCC_F0_PIV		0x00000002
  ------------------
 5017|     19|				else if (memcmp(body, "\xA0\x00\x00\x00\x79", 5) == 0)
  ------------------
  |  Branch (5017:14): [True: 0, False: 19]
  ------------------
 5018|      0|					priv->ccc_flags |= PIV_CCC_F0_CAC;
  ------------------
  |  |  169|      0|#define PIV_CCC_F0_CAC		0x00000004
  ------------------
 5019|     22|				if (*(body + 6) == 0x02)
  ------------------
  |  Branch (5019:9): [True: 10, False: 12]
  ------------------
 5020|     10|					priv->ccc_flags |= PIV_CCC_F0_JAVA;
  ------------------
  |  |  170|     10|#define PIV_CCC_F0_JAVA		0x00000008
  ------------------
 5021|     22|			}
 5022|     34|			break;
 5023|     54|		case PIV_CCC_TAG_F3:
  ------------------
  |  |  174|     54|#define PIV_CCC_TAG_F3		0xF3
  ------------------
  |  Branch (5023:3): [True: 54, False: 307]
  ------------------
 5024|     54|			if (len == 0x10) {
  ------------------
  |  Branch (5024:8): [True: 31, False: 23]
  ------------------
 5025|     31|				if (memcmp(body, "\xA0\x00\x00\x00\x79\x04", 6) == 0)
  ------------------
  |  Branch (5025:9): [True: 12, False: 19]
  ------------------
 5026|     12|					priv->ccc_flags |= PIV_CCC_F3_CAC_PKI;
  ------------------
  |  |  171|     12|#define PIV_CCC_F3_CAC_PKI	0x00000010
  ------------------
 5027|     31|			}
 5028|     54|			break;
 5029|    361|		}
 5030|    361|	}
 5031|       |
 5032|     48|err:
 5033|     48|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     48|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     48|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     48|	int _ret = r; \
  |  |  |  |  155|     48|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 48, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     48|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     42|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 42, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  157|     48|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     48|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     48|	return _ret; \
  |  |  |  |  163|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5034|     48|}
card-piv.c:piv_init:
 5912|    786|{
 5913|    786|	int r = 0;
 5914|    786|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    786|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5915|    786|	unsigned long flags;
 5916|    786|	unsigned long flags_eddsa;
 5917|    786|	unsigned long flags_xeddsa;
 5918|    786|	unsigned long ext_flags;
 5919|       |
 5920|    786|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    786|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    786|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    786|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 786]
  |  |  ------------------
  ------------------
 5921|       |
 5922|    786|	r = sc_lock(card); /* hold until match or init is complete */
 5923|    786|	LOG_TEST_RET(card->ctx, r, "sc_lock failed");
  ------------------
  |  |  174|    786|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    786|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    786|	int _ret = (r); \
  |  |  |  |  168|    786|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 786]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|    786|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 786]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5924|       |
 5925|       |	/* piv_match_card_continued called from card match should have left card->drv_data */
 5926|    786|	if (priv == NULL) {
  ------------------
  |  Branch (5926:6): [True: 0, False: 786]
  ------------------
 5927|      0|		r = piv_match_card_continued(card);
 5928|      0|		priv = PIV_DATA(card);
  ------------------
  |  |  432|      0|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5929|      0|		if (r < 0 || !priv) {
  ------------------
  |  Branch (5929:7): [True: 0, False: 0]
  |  Branch (5929:16): [True: 0, False: 0]
  ------------------
 5930|      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__
  |  |  ------------------
  ------------------
 5931|      0|			sc_unlock(card);
 5932|      0|			piv_finish(card);
 5933|       |			/* tell sc_connect_card to try other driver */
 5934|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5935|      0|		}
 5936|      0|	}
 5937|       |
 5938|       |	/* read "card_driver PIV-II" opensc.conf options, and env parameters */
 5939|    786|	piv_load_options(card);
 5940|       |
 5941|    786|	priv->pstate = PIV_STATE_INIT;
 5942|       |
 5943|    786|	sc_log(card->ctx,
  ------------------
  |  |   71|    786|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 5944|    786|			"Max send = %" SC_FORMAT_LEN_SIZE_T "u recv = %" SC_FORMAT_LEN_SIZE_T "u card->type:%d, CI:%08x AI:%08x",
 5945|    786|			card->max_send_size, card->max_recv_size, card->type, priv->card_issues, priv->alg_ids);
 5946|    786|	card->cla = 0x00;
 5947|    786|	if (card->name == NULL)
  ------------------
  |  Branch (5947:6): [True: 786, False: 0]
  ------------------
 5948|    786|		card->name = card->driver->name;
 5949|       |
 5950|    786|	priv->enumtag = piv_aids[0].enumtag;
 5951|       |
 5952|       |	/* PKCS#11 may try to generate session keys, and get confused
 5953|       |	 * if SC_ALGORITHM_ONBOARD_KEY_GEN is present
 5954|       |	 * piv-tool can still do this, just don't tell PKCS#11
 5955|       |	 */
 5956|       |
 5957|    786|	flags = SC_ALGORITHM_RSA_RAW;
  ------------------
  |  |  111|    786|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
 5958|       |
 5959|    786|	if (card->type == SC_CARD_TYPE_PIV_II_SWISSBIT) {
  ------------------
  |  Branch (5959:6): [True: 0, False: 786]
  ------------------
 5960|      0|		flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|      0|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 5961|      0|	}
 5962|       |
 5963|    786|	if (priv->alg_ids & AI_RSA_1024)
  ------------------
  |  |  588|    786|#define AI_RSA_1024			    0x00000001U
  ------------------
  |  Branch (5963:6): [True: 786, False: 0]
  ------------------
 5964|    786|		_sc_card_add_rsa_alg(card, 1024, flags, 0); /* mandatory */
 5965|       |
 5966|    786|	if (priv->alg_ids & AI_RSA_2048)
  ------------------
  |  |  589|    786|#define AI_RSA_2048			    0x00000002U
  ------------------
  |  Branch (5966:6): [True: 786, False: 0]
  ------------------
 5967|    786|		_sc_card_add_rsa_alg(card, 2048, flags, 0); /* optional */
 5968|       |
 5969|    786|	if (priv->alg_ids & AI_RSA_3072)
  ------------------
  |  |  590|    786|#define AI_RSA_3072			    0x00000004U
  ------------------
  |  Branch (5969:6): [True: 786, False: 0]
  ------------------
 5970|    786|		_sc_card_add_rsa_alg(card, 3072, flags, 0); /* optional */
 5971|       |
 5972|    786|	if (priv->alg_ids & AI_RSA_4096)
  ------------------
  |  |  591|    786|#define AI_RSA_4096			    0x00000008U
  ------------------
  |  Branch (5972:6): [True: 80, False: 706]
  ------------------
 5973|     80|		_sc_card_add_rsa_alg(card, 4096, flags, 0); /* non standard */
 5974|       |
 5975|    786|	if (!(priv->card_issues & CI_NO_EC)) {
  ------------------
  |  |  585|    786|#define CI_NO_EC			    0x00000800U /* No EC at all */
  ------------------
  |  Branch (5975:6): [True: 786, False: 0]
  ------------------
 5976|    786|		int i;
 5977|    786|		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  183|    786|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  182|    786|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
              		flags = SC_ALGORITHM_ECDSA_RAW | SC_ALGORITHM_ECDH_CDH_RAW | SC_ALGORITHM_ECDSA_HASH_NONE;
  ------------------
  |  |  184|    786|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    786|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 5978|    786|		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  210|    786|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
              		ext_flags = SC_ALGORITHM_EXT_EC_NAMEDCURVE | SC_ALGORITHM_EXT_EC_UNCOMPRESES;
  ------------------
  |  |  211|    786|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 5979|    786|		flags_eddsa = SC_ALGORITHM_EDDSA_RAW;
  ------------------
  |  |  197|    786|#define SC_ALGORITHM_EDDSA_RAW		0x00400000
  ------------------
 5980|    786|		flags_xeddsa = SC_ALGORITHM_XEDDSA_RAW;
  ------------------
  |  |  198|    786|#define SC_ALGORITHM_XEDDSA_RAW		0x00800000
  ------------------
 5981|       |
 5982|  3.93k|		for (i = 0; ec_curves[i].oid.value[0] >= 0; i++) {
  ------------------
  |  Branch (5982:15): [True: 3.14k, False: 786]
  ------------------
 5983|  3.14k|			if (ec_curves[i].key_type == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|  3.14k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (5983:8): [True: 1.57k, False: 1.57k]
  ------------------
 5984|  1.57k|				if (!(priv->card_issues & CI_NO_EC384 && ec_curves[i].size == 384))
  ------------------
  |  |  584|  3.14k|#define CI_NO_EC384			    0x00000400U /* does not have EC 384 */
  ------------------
  |  Branch (5984:11): [True: 544, False: 1.02k]
  |  Branch (5984:46): [True: 272, False: 272]
  ------------------
 5985|  1.30k|					_sc_card_add_ec_alg(card, ec_curves[i].size, flags, ext_flags, &ec_curves[i].oid);
 5986|  1.57k|			}
 5987|       |
 5988|  1.57k|			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |  594|  3.14k|#define AI_25519			    0x00100000U
  ------------------
              			else if (priv->alg_ids & AI_25519 && ec_curves[i].key_type == SC_ALGORITHM_EDDSA)
  ------------------
  |  |   81|    160|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (5988:13): [True: 160, False: 1.41k]
  |  Branch (5988:41): [True: 80, False: 80]
  ------------------
 5989|     80|				_sc_card_add_eddsa_alg(card, ec_curves[i].size, flags_eddsa, ext_flags, &ec_curves[i].oid);
 5990|       |
 5991|  1.49k|			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |  595|  2.98k|#define AI_X25519			    0x00200000U
  ------------------
              			else if (priv->alg_ids & AI_X25519 && ec_curves[i].key_type == SC_ALGORITHM_XEDDSA)
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (5991:13): [True: 0, False: 1.49k]
  |  Branch (5991:42): [True: 0, False: 0]
  ------------------
 5992|      0|				_sc_card_add_xeddsa_alg(card, ec_curves[i].size, flags_xeddsa, ext_flags, &ec_curves[i].oid);
 5993|  3.14k|		}
 5994|    786|	}
 5995|       |
 5996|    786|	if (!(priv->card_issues & CI_NO_RANDOM))
  ------------------
  |  |  575|    786|#define CI_NO_RANDOM			    0x00000004U /* can not use Challenge to get random data or no 9B key */
  ------------------
  |  Branch (5996:6): [True: 734, False: 52]
  ------------------
 5997|    734|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    734|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
 5998|       |
 5999|       |	/* May turn off SC_CARD_CAP_ISO7816_PIN_INFO later */
 6000|    786|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    786|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 6001|       |
 6002|       |	/*
 6003|       |	 * 800-73-3 cards may have discovery. "piv-like cards may or may not.
 6004|       |	 * 800-73-4 with VCI must have it as it has the pin policy needed for VCI .
 6005|       |	 */
 6006|       |
 6007|       |#ifdef ENABLE_PIV_SM
 6008|       |	/*
 6009|       |	 * 800-73-4
 6010|       |	 * Response of AID says if SM is supported. Look for Cipher Suite
 6011|       |	 */
 6012|       |	if (priv->csID && priv->cs != NULL) {
 6013|       |		/*
 6014|       |		 * Main point in SM and VCI is to allow contactless access
 6015|       |		 */
 6016|       |		/* Only piv_init and piv_reader_lock_obtained should call piv_sm_open */
 6017|       |
 6018|       |		/* If user said PIV_SM_FLAGS_NEVER, dont start SM; implies limited contatless access */
 6019|       |		if (priv->sm_flags & PIV_SM_FLAGS_NEVER) {
 6020|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_NEVER");
 6021|       |			r = SC_SUCCESS; /* Users choice */
 6022|       |
 6023|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6024|       |				!(priv->pin_policy & PIV_PP_VCI_IMPL)) {
 6025|       |			sc_log(card->ctx, "Contactless and no card support for VCI");
 6026|       |			r = SC_SUCCESS; /* User should know VCI is not possible with their card; use like 800-73-3 contactless  */
 6027|       |
 6028|       |		} else if ((priv->init_flags & PIV_INIT_CONTACTLESS) &&
 6029|       |				!(priv->pin_policy & PIV_PP_VCI_WITHOUT_PC) &&
 6030|       |				(priv->pairing_code[0] == 0x00)) {
 6031|       |			sc_log(card->ctx, "Contactless, pairing_code required and no pairing code");
 6032|       |			r = SC_ERROR_PIN_CODE_INCORRECT; /* User should know they need to set pairing code */
 6033|       |
 6034|       |		} else {
 6035|       |			priv->sm_flags |= PIV_SM_FLAGS_DEFER_OPEN; /* tell priv_sm_open, OK to open */
 6036|       |			r = piv_sm_open(card);
 6037|       |			sc_log(card->ctx, "piv_sm_open returned:%d", r);
 6038|       |		}
 6039|       |
 6040|       |		/* If failed, and user said PIV_SM_FLAGS_ALWAYS quit */
 6041|       |		if (priv->sm_flags & PIV_SM_FLAGS_ALWAYS && r < 0) {
 6042|       |			sc_log(card->ctx, "User has requested PIV_SM_FLAGS_ALWAYS, SM has failed to start, don't use the card");
 6043|       |			LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_ALLOWED);
 6044|       |		}
 6045|       |
 6046|       |		/* user has wrong or no required pairing code */
 6047|       |		if (r == SC_ERROR_PIN_CODE_INCORRECT)
 6048|       |			LOG_FUNC_RETURN(card->ctx, r);
 6049|       |
 6050|       |		/* If SM did not start, or is not expected to start, continue on without it */
 6051|       |	}
 6052|       |#endif /* ENABLE_PIV_SM */
 6053|       |
 6054|       |	/*
 6055|       |	 * 800-73-3 cards may have a history object
 6056|       |	 * We want to process it now as this has information on what
 6057|       |	 * keys and certs. "piv like" cards may or may not have history
 6058|       |	 */
 6059|    786|	piv_process_history(card);
 6060|       |
 6061|    786|	priv->pstate = PIV_STATE_NORMAL;
 6062|    786|	sc_unlock(card);
 6063|    786|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    786|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    786|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    786|	int _ret = r; \
  |  |  |  |  155|    786|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 786, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    786|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 786]
  |  |  |  |  ------------------
  |  |  |  |  157|    786|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    786|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    786|	return _ret; \
  |  |  |  |  163|    786|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6064|    786|}
card-piv.c:piv_load_options:
 1674|    786|{
 1675|    786|	int r;
 1676|    786|	size_t i, j;
 1677|    786|	scconf_block **found_blocks, *block;
 1678|       |
 1679|       |#ifdef ENABLE_PIV_SM
 1680|       |	piv_private_data_t *priv = PIV_DATA(card);
 1681|       |	const char *option = NULL;
 1682|       |	int piv_pairing_code_found = 0;
 1683|       |	int piv_use_sm_found = 0;
 1684|       |
 1685|       |	/* pairing code is 8 decimal digits and is card specific */
 1686|       |	if ((option = getenv("PIV_PAIRING_CODE")) != NULL) {
 1687|       |		sc_log(card->ctx, "getenv(\"PIV_PAIRING_CODE\") found");
 1688|       |		if (piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1689|       |			memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1690|       |			piv_pairing_code_found = 1;
 1691|       |		}
 1692|       |	}
 1693|       |
 1694|       |	if ((option = getenv("PIV_USE_SM")) != NULL) {
 1695|       |		sc_log(card->ctx, "getenv(\"PIV_USE_SM\")=\"%s\"", option);
 1696|       |		if (!strcmp(option, "never")) {
 1697|       |			priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1698|       |			piv_use_sm_found = 1;
 1699|       |		} else if (!strcmp(option, "always")) {
 1700|       |			priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1701|       |			piv_use_sm_found = 1;
 1702|       |		} else {
 1703|       |			sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1704|       |		}
 1705|       |	}
 1706|       |#endif
 1707|       |
 1708|  1.57k|	for (i = 0; card->ctx->conf_blocks[i]; i++) {
  ------------------
  |  Branch (1708:14): [True: 786, False: 786]
  ------------------
 1709|    786|		found_blocks = scconf_find_blocks(card->ctx->conf, card->ctx->conf_blocks[i],
 1710|    786|				"card_driver", "PIV-II");
 1711|    786|		if (!found_blocks)
  ------------------
  |  Branch (1711:7): [True: 0, False: 786]
  ------------------
 1712|      0|			continue;
 1713|       |
 1714|    786|		for (j = 0, block = found_blocks[j]; block; j++, block = found_blocks[j]) {
  ------------------
  |  Branch (1714:40): [True: 0, False: 786]
  ------------------
 1715|       |
 1716|       |#ifdef ENABLE_PIV_SM
 1717|       |			/*
 1718|       |			 * "piv_use_sm" if card supports NIST sp800-73-4 sm, when should it be used
 1719|       |			 * never - use card like 800-73-3, i.e. contactless is very limited on
 1720|       |			 * true PIV cards. Some  PIV-like" card may allow this.
 1721|       |			 * this security risk
 1722|       |			 * always - Use even for contact interface.
 1723|       |			 * PINS, crypto and reading of object will not show up in logs
 1724|       |			 * or over network.
 1725|       |			 */
 1726|       |
 1727|       |			if (piv_use_sm_found == 0) {
 1728|       |				option = scconf_get_str(block, "piv_use_sm", "default");
 1729|       |				sc_log(card->ctx, "conf: \"piv_use_sm\"=\"%s\"", option);
 1730|       |				if (!strcmp(option, "default")) {
 1731|       |					/* no new flags */
 1732|       |				} else if (!strcmp(option, "never")) {
 1733|       |					priv->sm_flags |= PIV_SM_FLAGS_NEVER;
 1734|       |				} else if (!strcmp(option, "always")) {
 1735|       |					priv->sm_flags |= PIV_SM_FLAGS_ALWAYS;
 1736|       |				} else {
 1737|       |					sc_log(card->ctx, "Invalid piv_use_sm: \"%s\"", option);
 1738|       |				}
 1739|       |			}
 1740|       |
 1741|       |			/* This is really a card specific value and should not be in the conf file */
 1742|       |			if (piv_pairing_code_found == 0) {
 1743|       |				option = scconf_get_str(block, "piv_pairing_code", NULL);
 1744|       |				if (option && piv_parse_pairing_code(card, option) == SC_SUCCESS) {
 1745|       |					memcpy(priv->pairing_code, option, PIV_PAIRING_CODE_LEN);
 1746|       |				}
 1747|       |			}
 1748|       |#endif
 1749|      0|		}
 1750|    786|		free(found_blocks);
 1751|    786|	}
 1752|    786|	r = SC_SUCCESS;
  ------------------
  |  |   28|    786|#define SC_SUCCESS				0
  ------------------
 1753|    786|	return r;
 1754|    786|}
card-piv.c:piv_process_history:
 5110|    786|{
 5111|    786|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    786|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5112|    786|	int r;
 5113|    786|	int i, tmplen, tmplen2, tmplen3;
 5114|    786|	int enumtag;
 5115|    786|	u8 *rbuf = NULL;
 5116|    786|	size_t rbuflen = 0;
 5117|    786|	const u8 *body;
 5118|    786|	size_t bodylen;
 5119|    786|	const u8 *num;
 5120|    786|	size_t numlen;
 5121|    786|	const u8 *url = NULL;
 5122|    786|	size_t urllen;
 5123|    786|	u8 *ocfhfbuf = NULL;
 5124|    786|	unsigned int cla_out, tag_out;
 5125|    786|	size_t ocfhflen;
 5126|    786|	const u8 *seq;
 5127|    786|	const u8 *seqtag;
 5128|    786|	size_t seqlen;
 5129|    786|	const u8 *keyref;
 5130|    786|	size_t keyreflen;
 5131|    786|	const u8 *cert;
 5132|    786|	size_t certlen;
 5133|    786|	size_t certobjlen, i2;
 5134|    786|	u8 *certobj;
 5135|    786|	u8 *cp;
 5136|       |
 5137|    786|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    786|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    786|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    786|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 786]
  |  |  ------------------
  ------------------
 5138|       |
 5139|    786|	r = piv_get_cached_data(card, PIV_OBJ_HISTORY, &rbuf, &rbuflen);
 5140|    786|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    786|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5140:6): [True: 144, False: 642]
  ------------------
 5141|    144|		r = 0; /* OK if not found */
 5142|    786|	if (r <= 0) {
  ------------------
  |  Branch (5142:6): [True: 595, False: 191]
  ------------------
 5143|    595|		priv->obj_cache[PIV_OBJ_HISTORY].flags |= PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|    595|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5144|    595|		goto err; /* no file, must be pre 800-73-3 card and not on card */
 5145|    595|	}
 5146|       |
 5147|       |	/* the object is now cached, see what we have */
 5148|    191|	if (rbuflen != 0) {
  ------------------
  |  Branch (5148:6): [True: 191, False: 0]
  ------------------
 5149|    191|		body = rbuf;
 5150|    191|		if ((r = sc_asn1_read_tag(&body, rbuflen, &cla_out, &tag_out, &bodylen)) != SC_SUCCESS ||
  ------------------
  |  |   28|    382|#define SC_SUCCESS				0
  ------------------
  |  Branch (5150:7): [True: 0, False: 191]
  ------------------
 5151|    191|				((cla_out << 24 | tag_out) != piv_objects[PIV_OBJ_HISTORY].resp_tag)) {
  ------------------
  |  Branch (5151:5): [True: 0, False: 191]
  ------------------
 5152|      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__
  |  |  ------------------
  ------------------
 5153|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5154|      0|			goto err;
 5155|      0|		}
 5156|       |
 5157|    191|		if (body != NULL && bodylen != 0) {
  ------------------
  |  Branch (5157:7): [True: 191, False: 0]
  |  Branch (5157:23): [True: 188, False: 3]
  ------------------
 5158|    188|			numlen = 0;
 5159|    188|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC1, &numlen);
 5160|    188|			if (num) {
  ------------------
  |  Branch (5160:8): [True: 179, False: 9]
  ------------------
 5161|    179|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5161:9): [True: 1, False: 178]
  |  Branch (5161:24): [True: 2, False: 176]
  ------------------
 5162|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5163|      3|					goto err;
 5164|      3|				}
 5165|       |
 5166|    176|				priv->keysWithOnCardCerts = *num;
 5167|    176|			}
 5168|       |
 5169|    185|			numlen = 0;
 5170|    185|			num = sc_asn1_find_tag(card->ctx, body, bodylen, 0xC2, &numlen);
 5171|    185|			if (num) {
  ------------------
  |  Branch (5171:8): [True: 167, False: 18]
  ------------------
 5172|    167|				if (numlen != 1 || *num > PIV_OBJ_RETIRED_X509_20 - PIV_OBJ_RETIRED_X509_1 + 1) {
  ------------------
  |  Branch (5172:9): [True: 1, False: 166]
  |  Branch (5172:24): [True: 2, False: 164]
  ------------------
 5173|      3|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      3|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5174|      3|					goto err;
 5175|      3|				}
 5176|       |
 5177|    164|				priv->keysWithOffCardCerts = *num;
 5178|    164|			}
 5179|       |
 5180|    182|			url = sc_asn1_find_tag(card->ctx, body, bodylen, 0xF3, &urllen);
 5181|    182|			if (url) {
  ------------------
  |  Branch (5181:8): [True: 166, False: 16]
  ------------------
 5182|    166|				if (urllen > 118) {
  ------------------
  |  Branch (5182:9): [True: 0, False: 166]
  ------------------
 5183|      0|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5184|      0|					goto err;
 5185|      0|				}
 5186|    166|				priv->offCardCertURL = calloc(1, urllen + 1);
 5187|    166|				if (priv->offCardCertURL == NULL)
  ------------------
  |  Branch (5187:9): [True: 0, False: 166]
  ------------------
 5188|    166|					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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5189|    166|				memcpy(priv->offCardCertURL, url, urllen);
 5190|    166|			}
 5191|    182|		} else {
 5192|      3|			sc_log(card->ctx, "Problem with History object\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__
  |  |  ------------------
  ------------------
 5193|      3|			r = SC_SUCCESS; /* OK if not found */
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 5194|      3|			goto err;
 5195|      3|		}
 5196|    191|	}
 5197|    182|	sc_log(card->ctx, "History on=%d off=%d URL=%s",
  ------------------
  |  |   71|    364|#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: 166, False: 16]
  |  |  ------------------
  ------------------
 5198|    182|			priv->keysWithOnCardCerts, priv->keysWithOffCardCerts,
 5199|    182|			priv->offCardCertURL ? priv->offCardCertURL : "NONE");
 5200|       |
 5201|       |	/* now mark what objects are on the card */
 5202|  2.73k|	for (i = 0; i < priv->keysWithOnCardCerts; i++)
  ------------------
  |  Branch (5202:14): [True: 2.54k, False: 182]
  ------------------
 5203|  2.54k|		priv->obj_cache[PIV_OBJ_RETIRED_X509_1 + i].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|  2.73k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5204|       |
 5205|       |	/*
 5206|       |	 * If user has gotten copy of the file from the offCardCertsURL,
 5207|       |	 * we will read in and add the certs to the cache as listed on
 5208|       |	 * the card. some of the certs may be on the card as well.
 5209|       |	 *
 5210|       |	 * Get file name from url. verify that the filename is valid
 5211|       |	 * The URL ends in a SHA-256 string. We will use this as the filename
 5212|       |	 * in the directory used for the  PKCS15 cache
 5213|       |	 * "http://" <DNS name> "/" <ASCII-HEX encoded SHA-256 hash of OffCardKeyHistoryFile>
 5214|       |	 */
 5215|       |
 5216|    182|	r = 0;
 5217|    182|	if (priv->offCardCertURL) {
  ------------------
  |  Branch (5217:6): [True: 166, False: 16]
  ------------------
 5218|    166|		char *fp;
 5219|    166|		char filename[PATH_MAX];
 5220|       |
 5221|    166|		if (strncmp("http://", priv->offCardCertURL, 7)) {
  ------------------
  |  Branch (5221:7): [True: 144, False: 22]
  ------------------
 5222|    144|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|    144|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5223|    144|			goto err;
 5224|    144|		}
 5225|       |		/* find the last /  so we have the filename part */
 5226|     22|		fp = strrchr(priv->offCardCertURL + 7, '/');
 5227|     22|		if (fp == NULL) {
  ------------------
  |  Branch (5227:7): [True: 2, False: 20]
  ------------------
 5228|      2|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      2|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5229|      2|			goto err;
 5230|      2|		}
 5231|     20|		fp++;
 5232|     20|		if (strlen(fp) != 64) { /* ASCII-HEX encoded SHA-256 */
  ------------------
  |  Branch (5232:7): [True: 13, False: 7]
  ------------------
 5233|     13|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     13|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5234|     13|			goto err;
 5235|     13|		}
 5236|    107|		for (i = 0; i < 64; i++) {
  ------------------
  |  Branch (5236:15): [True: 106, False: 1]
  ------------------
 5237|    106|			if (isxdigit((unsigned char)fp[i]) == 0) {
  ------------------
  |  Branch (5237:8): [True: 6, False: 100]
  ------------------
 5238|      6|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      6|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 5239|      6|				goto err;
 5240|      6|			}
 5241|    106|		}
 5242|       |
 5243|       |		/* Use the same directory as used for other OpenSC cached items */
 5244|      1|		r = sc_get_cache_dir(card->ctx, filename, sizeof(filename) - strlen(fp) - 2);
 5245|      1|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
  |  Branch (5245:7): [True: 0, False: 1]
  ------------------
 5246|      0|			goto err;
 5247|       |#ifdef _WIN32
 5248|       |		strlcat(filename, "\\", PATH_MAX);
 5249|       |#else
 5250|      1|		strlcat(filename, "/", PATH_MAX);
 5251|      1|#endif
 5252|      1|		strlcat(filename, fp, PATH_MAX);
 5253|       |
 5254|      1|		r = piv_read_obj_from_file(card, filename,
 5255|      1|				&ocfhfbuf, &ocfhflen);
 5256|      1|		if (r == SC_ERROR_FILE_NOT_FOUND) {
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (5256:7): [True: 1, False: 0]
  ------------------
 5257|      1|			r = 0;
 5258|      1|			goto err;
 5259|      1|		}
 5260|       |
 5261|       |		/*
 5262|       |		 * Its a seq of seq of a key ref and cert
 5263|       |		 */
 5264|       |
 5265|      0|		body = ocfhfbuf;
 5266|      0|		if (sc_asn1_read_tag(&body, ocfhflen, &cla_out, &tag_out, &bodylen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5266:7): [True: 0, False: 0]
  ------------------
 5267|      0|				body == NULL ||
  ------------------
  |  Branch (5267:5): [True: 0, False: 0]
  ------------------
 5268|      0|				bodylen == 0 ||
  ------------------
  |  Branch (5268:5): [True: 0, False: 0]
  ------------------
 5269|      0|				(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5269:5): [True: 0, False: 0]
  ------------------
 5270|      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__
  |  |  ------------------
  ------------------
 5271|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5272|      0|			goto err;
 5273|      0|		}
 5274|      0|		seq = body;
 5275|      0|		while (bodylen > 0) {
  ------------------
  |  Branch (5275:10): [True: 0, False: 0]
  ------------------
 5276|      0|			seqtag = seq;
 5277|      0|			if (sc_asn1_read_tag(&seq, bodylen, &cla_out, &tag_out, &seqlen) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5277:8): [True: 0, False: 0]
  ------------------
 5278|      0|					seq == 0 ||
  ------------------
  |  Branch (5278:6): [True: 0, False: 0]
  ------------------
 5279|      0|					seqlen == 0 ||
  ------------------
  |  Branch (5279:6): [True: 0, False: 0]
  ------------------
 5280|      0|					(cla_out | tag_out) != 0x30) {
  ------------------
  |  Branch (5280:6): [True: 0, False: 0]
  ------------------
 5281|      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__
  |  |  ------------------
  ------------------
 5282|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5283|      0|				goto err;
 5284|      0|			}
 5285|      0|			keyref = sc_asn1_find_tag(card->ctx, seq, seqlen, 0x04, &keyreflen);
 5286|      0|			if (!keyref || keyreflen != 1 ||
  ------------------
  |  Branch (5286:8): [True: 0, False: 0]
  |  Branch (5286:19): [True: 0, False: 0]
  ------------------
 5287|      0|					(*keyref < 0x82 || *keyref > 0x95)) {
  ------------------
  |  Branch (5287:7): [True: 0, False: 0]
  |  Branch (5287:25): [True: 0, False: 0]
  ------------------
 5288|      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__
  |  |  ------------------
  ------------------
 5289|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5290|      0|				goto err;
 5291|      0|			}
 5292|      0|			cert = keyref + keyreflen;
 5293|      0|			certlen = seqlen - (cert - seq);
 5294|       |
 5295|      0|			enumtag = PIV_OBJ_RETIRED_X509_1 + *keyref - 0x82;
 5296|       |			/* now add the cert like another object */
 5297|       |
 5298|      0|			if ((tmplen = sc_asn1_put_tag(0x70, NULL, certlen, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5298:8): [True: 0, False: 0]
  ------------------
 5299|      0|					(tmplen2 = sc_asn1_put_tag(0x71, NULL, 1, NULL, 0, NULL)) <= 0 ||
  ------------------
  |  Branch (5299:6): [True: 0, False: 0]
  ------------------
 5300|      0|					(tmplen3 = sc_asn1_put_tag(0xFE, NULL, 0, NULL, 0, NULL)) <= 0) {
  ------------------
  |  Branch (5300:6): [True: 0, False: 0]
  ------------------
 5301|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5302|      0|				goto err;
 5303|      0|			}
 5304|      0|			i2 = tmplen + tmplen2 + tmplen3;
 5305|      0|			tmplen = sc_asn1_put_tag(0x53, NULL, i2, NULL, 0, NULL);
 5306|      0|			if (tmplen <= 0) {
  ------------------
  |  Branch (5306:8): [True: 0, False: 0]
  ------------------
 5307|      0|				r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 5308|      0|				goto err;
 5309|      0|			}
 5310|       |
 5311|      0|			certobjlen = tmplen;
 5312|      0|			certobj = malloc(certobjlen);
 5313|      0|			if (certobj == NULL) {
  ------------------
  |  Branch (5313:8): [True: 0, False: 0]
  ------------------
 5314|      0|				r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 5315|      0|				goto err;
 5316|      0|			}
 5317|      0|			cp = certobj;
 5318|      0|			if ((r = sc_asn1_put_tag(0x53, NULL, i2, cp, certobjlen, &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5318:8): [True: 0, False: 0]
  ------------------
 5319|      0|					(r = sc_asn1_put_tag(0x70, cert, certlen, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS ||
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5319:6): [True: 0, False: 0]
  ------------------
 5320|      0|					(r = sc_asn1_put_tag(0x71, NULL, 1, cp, certobjlen - (cp - certobj), &cp)) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5320:6): [True: 0, False: 0]
  ------------------
 5321|      0|				goto err;
 5322|      0|			}
 5323|      0|			*cp++ = 0x00;
 5324|      0|			r = sc_asn1_put_tag(0xFE, NULL, 0, cp, certobjlen - (cp - certobj), &cp);
 5325|      0|			if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (5325:8): [True: 0, False: 0]
  ------------------
 5326|      0|				goto err;
 5327|      0|			}
 5328|       |
 5329|      0|			priv->obj_cache[enumtag].obj_data = certobj;
 5330|      0|			priv->obj_cache[enumtag].obj_len = certobjlen;
 5331|      0|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_VALID;
  ------------------
  |  |  148|      0|#define PIV_OBJ_CACHE_VALID		1
  ------------------
 5332|      0|			priv->obj_cache[enumtag].flags &= ~PIV_OBJ_CACHE_NOT_PRESENT;
  ------------------
  |  |  150|      0|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
 5333|       |
 5334|      0|			r = piv_cache_internal_data(card, enumtag);
 5335|      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__
  |  |  ------------------
  ------------------
 5336|       |
 5337|      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__
  |  |  ------------------
  ------------------
 5338|      0|					"Added from off card file #%d %p:%" SC_FORMAT_LEN_SIZE_T "u 0x%02X",
 5339|      0|					enumtag,
 5340|      0|					priv->obj_cache[enumtag].obj_data,
 5341|      0|					priv->obj_cache[enumtag].obj_len, *keyref);
 5342|       |
 5343|      0|			bodylen -= (seqlen + seq - seqtag);
 5344|      0|			seq += seqlen;
 5345|      0|		}
 5346|      0|	}
 5347|    786|err:
 5348|    786|	if (ocfhfbuf)
  ------------------
  |  Branch (5348:6): [True: 0, False: 786]
  ------------------
 5349|      0|		free(ocfhfbuf);
 5350|    786|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    786|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    786|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    786|	int _ret = r; \
  |  |  |  |  155|    786|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 786, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    786|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    622|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 622, False: 164]
  |  |  |  |  ------------------
  |  |  |  |  157|    786|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    786|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    786|	return _ret; \
  |  |  |  |  163|    786|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 5351|    786|}
card-piv.c:piv_read_obj_from_file:
 3013|      1|{
 3014|      1|	int r;
 3015|      1|	int r_tag;
 3016|      1|	int f = -1;
 3017|      1|	size_t len;
 3018|      1|	u8 tagbuf[16];
 3019|      1|	size_t rbuflen;
 3020|      1|	const u8 *body;
 3021|      1|	unsigned int cla_out, tag_out;
 3022|      1|	size_t bodylen;
 3023|       |
 3024|      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]
  |  |  ------------------
  ------------------
 3025|       |
 3026|      1|	*buf = NULL;
 3027|      1|	*buf_len = 0;
 3028|      1|	f = open(filename, O_RDONLY);
 3029|      1|	if (f < 0) {
  ------------------
  |  Branch (3029:6): [True: 1, False: 0]
  ------------------
 3030|      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__
  |  |  ------------------
  ------------------
 3031|      1|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      1|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3032|      1|		goto err;
 3033|      1|	}
 3034|      0|	len = read(f, tagbuf, sizeof(tagbuf)); /* get tag and length */
 3035|      0|	if (len < 2 || len > sizeof(tagbuf)) {
  ------------------
  |  Branch (3035:6): [True: 0, False: 0]
  |  Branch (3035:17): [True: 0, False: 0]
  ------------------
 3036|      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__
  |  |  ------------------
  ------------------
 3037|      0|		r = SC_ERROR_DATA_OBJECT_NOT_FOUND;
  ------------------
  |  |   66|      0|#define SC_ERROR_DATA_OBJECT_NOT_FOUND		-1216
  ------------------
 3038|      0|		goto err;
 3039|      0|	}
 3040|      0|	body = tagbuf;
 3041|       |	/* accept any tag for now, just get length */
 3042|      0|	r_tag = sc_asn1_read_tag(&body, len, &cla_out, &tag_out, &bodylen);
 3043|      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 (3043:7): [True: 0, False: 0]
  |  Branch (3043:30): [True: 0, False: 0]
  ------------------
 3044|      0|			body == NULL) {
  ------------------
  |  Branch (3044:4): [True: 0, False: 0]
  ------------------
 3045|      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__
  |  |  ------------------
  ------------------
 3046|      0|		r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3047|      0|		goto err;
 3048|      0|	}
 3049|      0|	rbuflen = body - tagbuf + bodylen;
 3050|      0|	*buf = malloc(rbuflen);
 3051|      0|	if (!*buf) {
  ------------------
  |  Branch (3051:6): [True: 0, False: 0]
  ------------------
 3052|      0|		r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 3053|      0|		goto err;
 3054|      0|	}
 3055|      0|	memcpy(*buf, tagbuf, len); /* copy first or only part */
 3056|       |	/* read rest of file */
 3057|      0|	if (rbuflen > len + sizeof(tagbuf)) {
  ------------------
  |  Branch (3057:6): [True: 0, False: 0]
  ------------------
 3058|      0|		len = read(f, *buf + sizeof(tagbuf), rbuflen - sizeof(tagbuf)); /* read rest */
 3059|      0|		if (len != rbuflen - sizeof(tagbuf)) {
  ------------------
  |  Branch (3059:7): [True: 0, False: 0]
  ------------------
 3060|      0|			r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|      0|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 3061|      0|			free(*buf);
 3062|      0|			*buf = NULL;
 3063|      0|			goto err;
 3064|      0|		}
 3065|      0|	}
 3066|      0|	r = (int)rbuflen;
 3067|      0|	*buf_len = rbuflen;
 3068|      1|err:
 3069|      1|	if (f >= 0)
  ------------------
  |  Branch (3069:6): [True: 0, False: 1]
  ------------------
 3070|      0|		close(f);
 3071|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3072|      1|}
card-piv.c:piv_cache_internal_data:
 3275|  3.07k|{
 3276|  3.07k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  3.07k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3277|  3.07k|	const u8 *tag;
 3278|  3.07k|	const u8 *body;
 3279|  3.07k|	size_t taglen;
 3280|  3.07k|	size_t bodylen;
 3281|  3.07k|	int compressed = 0;
 3282|  3.07k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|  3.07k|#define SC_SUCCESS				0
  ------------------
 3283|       |#ifdef ENABLE_PIV_SM
 3284|       |	u8 *cvc_start = NULL;
 3285|       |	size_t cvc_len = 0;
 3286|       |#endif
 3287|       |
 3288|       |	/* if already cached */
 3289|  3.07k|	if (priv->obj_cache[enumtag].internal_obj_data && priv->obj_cache[enumtag].internal_obj_len) {
  ------------------
  |  Branch (3289:6): [True: 1.49k, False: 1.57k]
  |  Branch (3289:52): [True: 1.49k, False: 0]
  ------------------
 3290|  1.49k|		sc_log(card->ctx,
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 3291|  1.49k|				"#%d found internal %p:%" SC_FORMAT_LEN_SIZE_T "u",
 3292|  1.49k|				enumtag,
 3293|  1.49k|				priv->obj_cache[enumtag].internal_obj_data,
 3294|  1.49k|				priv->obj_cache[enumtag].internal_obj_len);
 3295|  1.49k|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.49k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.49k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.49k|	int _ret = r; \
  |  |  |  |  155|  1.49k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.49k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.49k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.49k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.49k|	} else { \
  |  |  |  |  159|      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.49k|	return _ret; \
  |  |  |  |  163|  1.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3296|  1.49k|	}
 3297|       |
 3298|  1.57k|	body = sc_asn1_find_tag(card->ctx,
 3299|  1.57k|			priv->obj_cache[enumtag].obj_data,
 3300|  1.57k|			priv->obj_cache[enumtag].obj_len,
 3301|  1.57k|			0x53, &bodylen);
 3302|       |
 3303|  1.57k|	if (body == NULL || priv->obj_cache[enumtag].obj_data[0] != 0x53)
  ------------------
  |  Branch (3303:6): [True: 0, False: 1.57k]
  |  Branch (3303:22): [True: 0, False: 1.57k]
  ------------------
 3304|  1.57k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3305|       |
 3306|       |	/* get the certificate out */
 3307|  1.57k|	if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CERT) {
  ------------------
  |  |  632|  1.57k|#define PIV_OBJECT_TYPE_CERT		0x01
  ------------------
  |  Branch (3307:6): [True: 1.57k, False: 0]
  ------------------
 3308|       |
 3309|  1.57k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x71, &taglen);
 3310|       |		/* 800-72-1 not clear if this is 80 or 01 Sent comment to NIST for 800-72-2 */
 3311|       |		/* 800-73-3 says it is 01, keep dual test so old cards still work */
 3312|  1.57k|		if (tag && taglen > 0 && (((*tag) & 0x80) || ((*tag) & 0x01)))
  ------------------
  |  Branch (3312:7): [True: 1.10k, False: 473]
  |  Branch (3312:14): [True: 1.09k, False: 7]
  |  Branch (3312:29): [True: 6, False: 1.09k]
  |  Branch (3312:48): [True: 11, False: 1.08k]
  ------------------
 3313|     17|			compressed = 1;
 3314|       |
 3315|       |#ifdef ENABLE_PIV_SM
 3316|       |		cvc_start = (u8 *)tag + taglen; /* save for later as cvs (if present) follows  0x71 */
 3317|       |#endif
 3318|       |
 3319|  1.57k|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x70, &taglen);
 3320|  1.57k|		if (tag == NULL)
  ------------------
  |  Branch (3320:7): [True: 70, False: 1.50k]
  ------------------
 3321|  1.57k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_VALID);
  ------------------
  |  |  164|     70|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     70|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     70|	int _ret = r; \
  |  |  |  |  155|     70|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     70|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     70|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 70, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     70|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     70|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     70|	return _ret; \
  |  |  |  |  163|     70|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3322|       |
 3323|  1.50k|		if (taglen == 0)
  ------------------
  |  Branch (3323:7): [True: 10, False: 1.49k]
  ------------------
 3324|  1.50k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|     10|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     10|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     10|	int _ret = r; \
  |  |  |  |  155|     10|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     10|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     10|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 10, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|     10|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     10|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     10|	return _ret; \
  |  |  |  |  163|     10|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3325|       |
 3326|  1.49k|		if (compressed) {
  ------------------
  |  Branch (3326:7): [True: 17, False: 1.48k]
  ------------------
 3327|     17|			priv->obj_cache[enumtag].flags |= PIV_OBJ_CACHE_COMPRESSED;
  ------------------
  |  |  149|     17|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
 3328|     17|		}
 3329|       |		/* internal certificate remains compressed */
 3330|  1.49k|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3330:7): [True: 0, False: 1.49k]
  ------------------
 3331|  1.49k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3332|       |
 3333|  1.49k|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3334|  1.49k|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3335|       |
 3336|       |#ifdef ENABLE_PIV_SM
 3337|       |		/* PIV_OBJ_SM_CERT_SIGNER  CERT OBJECT may also have a intermediate CVC */
 3338|       |		if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_CVC) {
 3339|       |			/* cvc if present should be at cvc_start.
 3340|       |			 * find the tag(T) and get value(V) and len(L) from TLV.
 3341|       |			 * Could reconstruct ASN1 of (T)(L) stating location from length and known tag.
 3342|       |			 * as the size of (L) depends on the length of value
 3343|       |			 */
 3344|       |			if ((tag = sc_asn1_find_tag(card->ctx, body, bodylen, 0x7F21, &taglen)) != NULL &&
 3345|       |					cvc_start &&
 3346|       |					cvc_start < tag &&
 3347|       |					cvc_start[0] == 0x7f && cvc_start[1] == 0x21) {
 3348|       |				cvc_len = tag - cvc_start + taglen;
 3349|       |				/* decode the intermediate CVC */
 3350|       |				r = piv_decode_cvc(card, &cvc_start, &cvc_len, &priv->sm_in_cvc);
 3351|       |				if (r < 0) {
 3352|       |					sc_log(card->ctx, "unable to parse intermediate CVC: %d skipping", r);
 3353|       |				}
 3354|       |				priv->sm_flags |= PIV_SM_FLAGS_SM_IN_CVC_PRESENT;
 3355|       |			}
 3356|       |		}
 3357|       |#endif /* ENABLE_PIV_SM */
 3358|       |
 3359|       |		/* convert pub key to internal */
 3360|  1.49k|	} else if (piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  633|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3360:13): [True: 0, False: 0]
  ------------------
 3361|      0|		tag = sc_asn1_find_tag(card->ctx, body, bodylen, *body, &taglen);
 3362|      0|		if (tag == NULL)
  ------------------
  |  Branch (3362:7): [True: 0, False: 0]
  ------------------
 3363|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3364|       |
 3365|      0|		if (taglen == 0)
  ------------------
  |  Branch (3365:7): [True: 0, False: 0]
  ------------------
 3366|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3367|       |
 3368|      0|		if (!(priv->obj_cache[enumtag].internal_obj_data = malloc(taglen)))
  ------------------
  |  Branch (3368:7): [True: 0, False: 0]
  ------------------
 3369|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3370|       |
 3371|      0|		memcpy(priv->obj_cache[enumtag].internal_obj_data, tag, taglen);
 3372|      0|		priv->obj_cache[enumtag].internal_obj_len = taglen;
 3373|      0|	} else {
 3374|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3375|      0|	}
 3376|       |
 3377|  1.49k|	sc_log(card->ctx, "added #%d internal %p:%" SC_FORMAT_LEN_SIZE_T "u",
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 3378|  1.49k|			enumtag,
 3379|  1.49k|			priv->obj_cache[enumtag].internal_obj_data,
 3380|  1.49k|			priv->obj_cache[enumtag].internal_obj_len);
 3381|       |
 3382|  1.49k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.49k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.49k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.49k|	int _ret = r; \
  |  |  |  |  155|  1.49k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.49k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.49k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.49k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.49k|	} else { \
  |  |  |  |  159|      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.49k|	return _ret; \
  |  |  |  |  163|  1.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3383|  1.49k|}
card-piv.c:piv_finish:
 5374|  9.35k|{
 5375|  9.35k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  9.35k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 5376|  9.35k|	int i;
 5377|       |
 5378|  9.35k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  9.35k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  9.35k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  9.35k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 9.35k]
  |  |  ------------------
  ------------------
 5379|  9.35k|	if (priv) {
  ------------------
  |  Branch (5379:6): [True: 5.07k, False: 4.28k]
  ------------------
 5380|  5.07k|		if (priv->context_specific) {
  ------------------
  |  Branch (5380:7): [True: 0, False: 5.07k]
  ------------------
 5381|      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__
  |  |  ------------------
  ------------------
 5382|      0|			priv->context_specific = 0;
 5383|      0|			sc_unlock(card);
 5384|      0|		}
 5385|  5.07k|		free(priv->aid_der.value);
 5386|  5.07k|		free(priv->al_label);
 5387|  5.07k|		if (priv->w_buf)
  ------------------
  |  Branch (5387:7): [True: 0, False: 5.07k]
  ------------------
 5388|      0|			free(priv->w_buf);
 5389|  5.07k|		if (priv->offCardCertURL)
  ------------------
  |  Branch (5389:7): [True: 166, False: 4.90k]
  ------------------
 5390|    166|			free(priv->offCardCertURL);
 5391|   309k|		for (i = 0; i < PIV_OBJ_LAST_ENUM - 1; i++) {
  ------------------
  |  Branch (5391:15): [True: 304k, False: 5.07k]
  ------------------
 5392|   304k|			piv_obj_cache_free_entry(card, i, 0);
 5393|   304k|		}
 5394|       |#ifdef ENABLE_PIV_SM
 5395|       |		piv_clear_cvc_content(&priv->sm_cvc);
 5396|       |		piv_clear_cvc_content(&priv->sm_in_cvc);
 5397|       |		piv_clear_sm_session(&priv->sm_session);
 5398|       |#endif /* ENABLE_PIV_SM */
 5399|       |
 5400|  5.07k|		free(priv);
 5401|       |		card->drv_data = NULL; /* priv */
 5402|  5.07k|	}
 5403|  9.35k|	return 0;
 5404|  9.35k|}
card-piv.c:piv_select_file:
 4806|  7.45k|{
 4807|  7.45k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  7.45k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4808|  7.45k|	int r;
 4809|  7.45k|	int i;
 4810|  7.45k|	const u8 *path;
 4811|  7.45k|	size_t pathlen;
 4812|  7.45k|	sc_file_t *file = NULL;
 4813|  7.45k|	u8 *rbuf = NULL;
 4814|  7.45k|	size_t rbuflen = 0;
 4815|       |
 4816|  7.45k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  7.45k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  7.45k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  7.45k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 7.45k]
  |  |  ------------------
  ------------------
 4817|       |
 4818|  7.45k|	path = in_path->value;
 4819|  7.45k|	pathlen = in_path->len;
 4820|       |
 4821|       |	/* only support single EF in current application */
 4822|       |	/*
 4823|       |	 * PIV emulates files, and only does so because sc_pkcs15_* uses
 4824|       |	 * select_file and read_binary. The emulation adds path emulated structures
 4825|       |	 * so piv_select_file will find it.
 4826|       |	 * there is no dir. Only direct access to emulated files
 4827|       |	 * thus opensc-tool and opensc-explorer can not read the emulated files
 4828|       |	 */
 4829|       |
 4830|  7.45k|	if (memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (4830:6): [True: 960, False: 6.49k]
  ------------------
 4831|    960|		if (pathlen > 2) {
  ------------------
  |  Branch (4831:7): [True: 960, False: 0]
  ------------------
 4832|    960|			path += 2;
 4833|    960|			pathlen -= 2;
 4834|    960|		}
 4835|    960|	}
 4836|       |
 4837|  7.45k|	i = piv_find_obj_by_containerid(card, path);
 4838|       |
 4839|  7.45k|	if (i < 0)
  ------------------
  |  Branch (4839:6): [True: 980, False: 6.47k]
  ------------------
 4840|  7.45k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|    980|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    980|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    980|	int _ret = r; \
  |  |  |  |  155|    980|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 980, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    980|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    980|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 980, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    980|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    980|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    980|	return _ret; \
  |  |  |  |  163|    980|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4841|       |
 4842|       |	/*
 4843|       |	 * pkcs15 will use a 2 byte path or a 4 byte path
 4844|       |	 * with cece added to path to request only the cert from the cert obj
 4845|       |	 * PIV "Container ID" is used as the path, and are two bytes long
 4846|       |	 */
 4847|  6.47k|	priv->return_only_cert = (pathlen == 4 && path[2] == 0xce && path[3] == 0xce);
  ------------------
  |  Branch (4847:28): [True: 6.47k, False: 0]
  |  Branch (4847:44): [True: 6.47k, False: 0]
  |  Branch (4847:63): [True: 6.47k, False: 0]
  ------------------
 4848|       |
 4849|  6.47k|	priv->selected_obj = i;
 4850|  6.47k|	priv->rwb_state = -1;
 4851|       |
 4852|       |	/* make it look like the file was found. */
 4853|       |	/* We don't want to read it now  unless we need the length */
 4854|       |
 4855|  6.47k|	if (file_out) {
  ------------------
  |  Branch (4855:6): [True: 6.47k, False: 0]
  ------------------
 4856|       |		/* we need to read it now, to get length into cache */
 4857|  6.47k|		r = piv_get_cached_data(card, i, &rbuf, &rbuflen);
 4858|       |
 4859|  6.47k|		if (r < 0)
  ------------------
  |  Branch (4859:7): [True: 4.90k, False: 1.57k]
  ------------------
 4860|  6.47k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_FILE_NOT_FOUND);
  ------------------
  |  |  164|  4.90k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  4.90k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  4.90k|	int _ret = r; \
  |  |  |  |  155|  4.90k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.90k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  4.90k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.90k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.90k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.90k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  4.90k|	return _ret; \
  |  |  |  |  163|  4.90k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4861|       |
 4862|       |		/* get the cert or the pub key out and into the cache too */
 4863|  1.57k|		if (priv->return_only_cert || piv_objects[i].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  633|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (4863:7): [True: 1.57k, False: 0]
  |  Branch (4863:33): [True: 0, False: 0]
  ------------------
 4864|  1.57k|			r = piv_cache_internal_data(card, i);
 4865|  1.57k|			if (r < 0)
  ------------------
  |  Branch (4865:8): [True: 80, False: 1.49k]
  ------------------
 4866|  1.57k|				LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|     80|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     80|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     80|	int _ret = r; \
  |  |  |  |  155|     80|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 80, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     80|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4867|  1.57k|		}
 4868|       |
 4869|  1.49k|		file = sc_file_new();
 4870|  1.49k|		if (file == NULL)
  ------------------
  |  Branch (4870:7): [True: 0, False: 1.49k]
  ------------------
 4871|  1.49k|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4872|       |
 4873|  1.49k|		file->path = *in_path;
 4874|       |		/* this could be like the FCI */
 4875|  1.49k|		file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|  1.49k|#define SC_FILE_TYPE_DF			0x04
  ------------------
 4876|  1.49k|		file->shareable = 0;
 4877|  1.49k|		file->ef_structure = 0;
 4878|  1.49k|		if (priv->return_only_cert)
  ------------------
  |  Branch (4878:7): [True: 1.49k, False: 0]
  ------------------
 4879|  1.49k|			file->size = priv->obj_cache[i].internal_obj_len;
 4880|      0|		else
 4881|      0|			file->size = priv->obj_cache[i].obj_len;
 4882|       |
 4883|  1.49k|		file->id = (piv_objects[i].containerid[0] << 8) + piv_objects[i].containerid[1];
 4884|       |
 4885|  1.49k|		*file_out = file;
 4886|  1.49k|	}
 4887|       |
 4888|  1.49k|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.49k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.49k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.49k|	int _ret = r; \
  |  |  |  |  155|  1.49k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.49k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.49k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.49k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.49k|	} else { \
  |  |  |  |  159|      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.49k|	return _ret; \
  |  |  |  |  163|  1.49k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4889|  1.49k|}
card-piv.c:piv_find_obj_by_containerid:
 1758|  56.1k|{
 1759|  56.1k|	int i;
 1760|       |
 1761|  56.1k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  56.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  56.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  56.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  56.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 56.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1762|  56.1k|	sc_log(card->ctx, "str=0x%02X%02X\n", str[0], str[1]);
  ------------------
  |  |   71|  56.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__
  |  |  ------------------
  ------------------
 1763|       |
 1764|  1.13M|	for (i = 0; piv_objects[i].enumtag < PIV_OBJ_LAST_ENUM; i++) {
  ------------------
  |  Branch (1764:14): [True: 1.13M, False: 1.76k]
  ------------------
 1765|  1.13M|		if (str[0] == piv_objects[i].containerid[0] && str[1] == piv_objects[i].containerid[1])
  ------------------
  |  Branch (1765:7): [True: 488k, False: 646k]
  |  Branch (1765:50): [True: 54.4k, False: 434k]
  ------------------
 1766|  1.13M|			LOG_FUNC_RETURN(card->ctx, i);
  ------------------
  |  |  164|  54.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  54.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  54.4k|	int _ret = r; \
  |  |  |  |  155|  54.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 786, False: 53.6k]
  |  |  |  |  ------------------
  |  |  |  |  156|    786|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 786]
  |  |  |  |  ------------------
  |  |  |  |  157|    786|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  53.6k|	} else { \
  |  |  |  |  159|  53.6k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  53.6k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  53.6k|	} \
  |  |  |  |  162|  54.4k|	return _ret; \
  |  |  |  |  163|  54.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1767|  1.13M|	}
 1768|       |
 1769|  1.76k|	LOG_FUNC_RETURN(card->ctx, -1);
  ------------------
  |  |  164|  1.76k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.76k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.76k|	int _ret = r; \
  |  |  |  |  155|  1.76k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.76k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.76k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.76k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.76k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.76k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.76k|	return _ret; \
  |  |  |  |  163|  1.76k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1770|  1.76k|}
card-piv.c:piv_read_binary:
 3392|  1.58k|{
 3393|  1.58k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  1.58k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 3394|  1.58k|	int enumtag;
 3395|  1.58k|	int r;
 3396|  1.58k|	u8 *rbuf = NULL;
 3397|  1.58k|	size_t rbuflen = 0;
 3398|  1.58k|	const u8 *body;
 3399|  1.58k|	size_t bodylen;
 3400|       |
 3401|  1.58k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.58k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.58k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.58k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.58k]
  |  |  ------------------
  ------------------
 3402|  1.58k|	if (priv->selected_obj < 0)
  ------------------
  |  Branch (3402:6): [True: 0, False: 1.58k]
  ------------------
 3403|  1.58k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3404|  1.58k|	enumtag = piv_objects[priv->selected_obj].enumtag;
 3405|       |
 3406|  1.58k|	if (priv->rwb_state == -1) {
  ------------------
  |  Branch (3406:6): [True: 1.49k, False: 86]
  ------------------
 3407|  1.49k|		r = piv_get_cached_data(card, enumtag, &rbuf, &rbuflen);
 3408|       |
 3409|  1.49k|		if (r >= 0) {
  ------------------
  |  Branch (3409:7): [True: 1.49k, False: 0]
  ------------------
 3410|       |			/* an object with no data will be considered not found */
 3411|       |			/* Discovery tag = 0x73, all others are 0x53 */
 3412|  1.49k|			if (!rbuf || rbuf[0] == 0x00 || ((rbuf[0] & 0xDF) == 0x53 && rbuf[1] == 0x00)) {
  ------------------
  |  Branch (3412:8): [True: 0, False: 1.49k]
  |  Branch (3412:17): [True: 0, False: 1.49k]
  |  Branch (3412:37): [True: 1.49k, False: 0]
  |  Branch (3412:65): [True: 0, False: 1.49k]
  ------------------
 3413|      0|				r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      0|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
 3414|      0|				goto err;
 3415|      0|			}
 3416|       |
 3417|  1.49k|			body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, rbuf[0], &bodylen);
 3418|  1.49k|			if (body == NULL) {
  ------------------
  |  Branch (3418:8): [True: 0, False: 1.49k]
  ------------------
 3419|       |				/* if missing, assume its the body */
 3420|       |				/* DEE bug in the beta card */
 3421|      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__
  |  |  ------------------
  ------------------
 3422|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3423|      0|				goto err;
 3424|      0|			}
 3425|  1.49k|			if (bodylen > body - rbuf + rbuflen) {
  ------------------
  |  Branch (3425:8): [True: 0, False: 1.49k]
  ------------------
 3426|      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__
  |  |  ------------------
  ------------------
 3427|      0|						" ***** tag length > then data: %" SC_FORMAT_LEN_SIZE_T "u>%" SC_FORMAT_LEN_PTRDIFF_T "u+%" SC_FORMAT_LEN_SIZE_T "u",
 3428|      0|						bodylen, body - rbuf, rbuflen);
 3429|      0|				r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 3430|      0|				goto err;
 3431|      0|			}
 3432|       |			/* if cached obj has internal interesting data (cert or pub key) */
 3433|  1.49k|			if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  633|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3433:8): [True: 1.49k, False: 0]
  |  Branch (3433:34): [True: 0, False: 0]
  ------------------
 3434|  1.49k|				r = piv_cache_internal_data(card, enumtag);
 3435|  1.49k|				if (r < 0)
  ------------------
  |  Branch (3435:9): [True: 0, False: 1.49k]
  ------------------
 3436|      0|					goto err;
 3437|  1.49k|			}
 3438|  1.49k|		}
 3439|  1.49k|		priv->rwb_state = 0;
 3440|  1.49k|	}
 3441|       |
 3442|  1.58k|	if (priv->return_only_cert || piv_objects[enumtag].flags & PIV_OBJECT_TYPE_PUBKEY) {
  ------------------
  |  |  633|      0|#define PIV_OBJECT_TYPE_PUBKEY		0x02
  ------------------
  |  Branch (3442:6): [True: 1.58k, False: 0]
  |  Branch (3442:32): [True: 0, False: 0]
  ------------------
 3443|  1.58k|		rbuf = priv->obj_cache[enumtag].internal_obj_data;
 3444|  1.58k|		rbuflen = priv->obj_cache[enumtag].internal_obj_len;
 3445|  1.58k|		if ((priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_COMPRESSED) && flags) {
  ------------------
  |  |  149|  1.58k|#define PIV_OBJ_CACHE_COMPRESSED	2
  ------------------
  |  Branch (3445:7): [True: 21, False: 1.56k]
  |  Branch (3445:70): [True: 21, False: 0]
  ------------------
 3446|     21|			*flags |= SC_FILE_FLAG_COMPRESSED_AUTO;
  ------------------
  |  |  230|     21|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
 3447|     21|		}
 3448|  1.58k|	} else {
 3449|      0|		rbuf = priv->obj_cache[enumtag].obj_data;
 3450|      0|		rbuflen = priv->obj_cache[enumtag].obj_len;
 3451|      0|	}
 3452|       |	/* rbuf rbuflen has pointer and length to cached data */
 3453|       |
 3454|  1.58k|	if (rbuflen < idx + count)
  ------------------
  |  Branch (3454:6): [True: 0, False: 1.58k]
  ------------------
 3455|      0|		count = rbuflen - idx;
 3456|  1.58k|	if (count <= 0) {
  ------------------
  |  Branch (3456:6): [True: 0, False: 1.58k]
  ------------------
 3457|      0|		r = 0;
 3458|      0|		priv->rwb_state = 1;
 3459|  1.58k|	} else {
 3460|  1.58k|		memcpy(buf, rbuf + idx, count);
 3461|  1.58k|		r = (int)count;
 3462|  1.58k|	}
 3463|       |
 3464|  1.58k|err:
 3465|  1.58k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.58k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.58k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.58k|	int _ret = r; \
  |  |  |  |  155|  1.58k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 1.58k]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define 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.58k|	} else { \
  |  |  |  |  159|  1.58k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.58k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.58k|	} \
  |  |  |  |  162|  1.58k|	return _ret; \
  |  |  |  |  163|  1.58k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 3466|  1.58k|}
card-piv.c:piv_set_security_env:
 4583|  2.87k|{
 4584|  2.87k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  2.87k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4585|  2.87k|	int r = 0;
 4586|       |
 4587|  2.87k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.87k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.87k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.87k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.87k]
  |  |  ------------------
  ------------------
 4588|       |
 4589|  2.87k|	sc_log(card->ctx,
  ------------------
  |  |   71|  2.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__
  |  |  ------------------
  ------------------
 4590|  2.87k|			"flags=%08lx op=%d alg=%lu algf=%08lx algr=%08lx kr0=%02x, krfl=%" SC_FORMAT_LEN_SIZE_T "u",
 4591|  2.87k|			env->flags, env->operation, env->algorithm, env->algorithm_flags,
 4592|  2.87k|			env->algorithm_ref, env->key_ref[0], env->key_ref_len);
 4593|       |
 4594|  2.87k|	priv->operation = env->operation;
 4595|  2.87k|	priv->algorithm = env->algorithm;
 4596|       |
 4597|  2.87k|	if (env->algorithm == SC_ALGORITHM_RSA) {
  ------------------
  |  |   78|  2.87k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (4597:6): [True: 191, False: 2.68k]
  ------------------
 4598|    191|		priv->alg_id = 0x06; /* Say it is RSA, set 5, 6, 7 later */
 4599|  2.68k|	} else if (env->algorithm == SC_ALGORITHM_EC) {
  ------------------
  |  |   79|  2.68k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (4599:13): [True: 2.68k, False: 0]
  ------------------
 4600|  2.68k|		if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   65|  2.68k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (4600:7): [True: 2.68k, False: 0]
  ------------------
 4601|  2.68k|			switch (env->algorithm_ref) {
 4602|  2.58k|			case 256:
  ------------------
  |  Branch (4602:4): [True: 2.58k, False: 100]
  ------------------
 4603|  2.58k|				priv->alg_id = 0x11; /* Say it is EC 256 */
 4604|  2.58k|				priv->key_size = 256;
 4605|  2.58k|				break;
 4606|    100|			case 384:
  ------------------
  |  Branch (4606:4): [True: 100, False: 2.58k]
  ------------------
 4607|    100|				priv->alg_id = 0x14;
 4608|    100|				priv->key_size = 384;
 4609|    100|				break;
 4610|      0|			default:
  ------------------
  |  Branch (4610:4): [True: 0, False: 2.68k]
  ------------------
 4611|      0|				r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4612|  2.68k|			}
 4613|  2.68k|		} else
 4614|      0|			r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4615|  2.68k|	} else if (env->algorithm == SC_ALGORITHM_EDDSA) {
  ------------------
  |  |   81|      0|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (4615:13): [True: 0, False: 0]
  ------------------
 4616|      0|		priv->alg_id = 0xE0;
 4617|      0|		priv->key_size = 255;
 4618|      0|	} else if (env->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4618:13): [True: 0, False: 0]
  ------------------
 4619|      0|		priv->alg_id = 0xE1;
 4620|      0|		priv->key_size = 255;
 4621|      0|	} else
 4622|      0|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|      0|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 4623|  2.87k|	priv->key_ref = env->key_ref[0];
 4624|       |
 4625|  2.87k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.87k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.87k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.87k|	int _ret = r; \
  |  |  |  |  155|  2.87k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.87k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.87k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.87k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.87k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.87k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  2.87k|	return _ret; \
  |  |  |  |  163|  2.87k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4626|  2.87k|}
card-piv.c:piv_compute_signature:
 4736|  2.27k|{
 4737|  2.27k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  2.27k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4738|  2.27k|	int r;
 4739|  2.27k|	size_t nLen;
 4740|  2.27k|	u8 rbuf[128]; /* For EC conversions  384 will fit */
 4741|       |
 4742|  2.27k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.27k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.27k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.27k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.27k]
  |  |  ------------------
  ------------------
 4743|       |	/* The PIV returns a DER SEQUENCE{INTEGER, INTEGER}
 4744|       |	 * Which may have leading 00 to force a positive integer
 4745|       |	 * But PKCS11 just wants 2* field_length in bytes
 4746|       |	 * So we have to strip out the integers
 4747|       |	 * and pad on left if too short.
 4748|       |	 */
 4749|       |
 4750|  2.27k|	if (priv->alg_id == 0x11 || priv->alg_id == 0x14) {
  ------------------
  |  Branch (4750:6): [True: 2.12k, False: 147]
  |  Branch (4750:30): [True: 88, False: 59]
  ------------------
 4751|  2.21k|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|  2.21k|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4752|  2.21k|		if (outlen < 2 * nLen) {
  ------------------
  |  Branch (4752:7): [True: 0, False: 2.21k]
  ------------------
 4753|      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__
  |  |  ------------------
  ------------------
 4754|      0|					" output too small for EC signature %" SC_FORMAT_LEN_SIZE_T "u < %" SC_FORMAT_LEN_SIZE_T "u",
 4755|      0|					outlen, 2 * nLen);
 4756|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4757|      0|			goto err;
 4758|      0|		}
 4759|       |
 4760|  2.21k|		r = piv_validate_general_authentication(card, data, datalen, rbuf, sizeof rbuf);
 4761|  2.21k|		if (r < 0)
  ------------------
  |  Branch (4761:7): [True: 1.99k, False: 224]
  ------------------
 4762|  1.99k|			goto err;
 4763|       |
 4764|    224|		r = sc_asn1_decode_ecdsa_signature(card->ctx, rbuf, r, nLen, &out, outlen);
 4765|       |		/* Yubikey 5.7.x supports ED25519 */
 4766|    224|	} else if (priv->alg_id == 0xE0) {
  ------------------
  |  Branch (4766:13): [True: 0, False: 59]
  ------------------
 4767|      0|		nLen = BYTES4BITS(priv->key_size);
  ------------------
  |  |  146|      0|#define BYTES4BITS(num)  (((num) + 7) / 8)    /* number of bytes necessary to hold 'num' bits */
  ------------------
 4768|      0|		if (outlen < nLen) {
  ------------------
  |  Branch (4768:7): [True: 0, False: 0]
  ------------------
 4769|      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__
  |  |  ------------------
  ------------------
 4770|      0|					" output too small for ED signature %" SC_FORMAT_LEN_SIZE_T "u < %" SC_FORMAT_LEN_SIZE_T "u",
 4771|      0|					outlen, nLen);
 4772|      0|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      0|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 4773|      0|			goto err;
 4774|      0|		}
 4775|      0|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4776|       |
 4777|     59|	} else { /* RSA is all set */
 4778|     59|		r = piv_validate_general_authentication(card, data, datalen, out, outlen);
 4779|     59|	}
 4780|       |
 4781|  2.27k|err:
 4782|  2.27k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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: 2.27k, False: 0]
  |  |  ------------------
  |  |  156|  2.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|  2.27k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 2.27k, False: 0]
  |  |  ------------------
  |  |  157|  2.27k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  2.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|  2.27k|	return _ret; \
  |  |  163|  2.27k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4783|  2.27k|}
card-piv.c:piv_validate_general_authentication:
 4640|  2.70k|{
 4641|  2.70k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  2.70k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4642|  2.70k|	int r, tmplen, tmplen2;
 4643|  2.70k|	u8 *p;
 4644|  2.70k|	const unsigned char *p2;
 4645|  2.70k|	size_t taglen;
 4646|  2.70k|	size_t bodylen;
 4647|  2.70k|	unsigned int cla, tag;
 4648|  2.70k|	unsigned int real_alg_id, op_tag;
 4649|       |
 4650|  2.70k|	u8 sbuf[4096]; /* needs work. for 4096 needs 512+10 or so */
 4651|  2.70k|	size_t sbuflen = sizeof(sbuf);
 4652|  2.70k|	u8 rbuf[4096];
 4653|       |
 4654|  2.70k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  2.70k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  2.70k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  2.70k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 2.70k]
  |  |  ------------------
  ------------------
 4655|       |
 4656|       |	/* should assume large send data */
 4657|  2.70k|	p = sbuf;
 4658|  2.70k|	tmplen = sc_asn1_put_tag(0xff, NULL, datalen, NULL, 0, NULL);
 4659|  2.70k|	tmplen2 = sc_asn1_put_tag(0x82, NULL, 0, NULL, 0, NULL);
 4660|  2.70k|	if (tmplen <= 0 || tmplen2 <= 0) {
  ------------------
  |  Branch (4660:6): [True: 0, False: 2.70k]
  |  Branch (4660:21): [True: 0, False: 2.70k]
  ------------------
 4661|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4662|      0|	}
 4663|  2.70k|	tmplen += tmplen2;
 4664|  2.70k|	if ((r = sc_asn1_put_tag(0x7c, NULL, tmplen, p, sbuflen, &p)) != SC_SUCCESS ||
  ------------------
  |  |   28|  5.41k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4664:6): [True: 33, False: 2.67k]
  ------------------
 4665|  2.67k|			(r = sc_asn1_put_tag(0x82, NULL, 0, p, sbuflen - (p - sbuf), &p)) != SC_SUCCESS) {
  ------------------
  |  |   28|  2.67k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4665:4): [True: 0, False: 2.67k]
  ------------------
 4666|     33|		LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4667|     33|	}
 4668|  2.67k|	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   59|  5.35k|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   79|    578|#define SC_ALGORITHM_EC		2
  ------------------
              	if (priv->operation == SC_SEC_OPERATION_DERIVE && (priv->algorithm == SC_ALGORITHM_EC || priv->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   82|      0|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (4668:6): [True: 289, False: 2.38k]
  |  Branch (4668:53): [True: 289, False: 0]
  |  Branch (4668:91): [True: 0, False: 0]
  ------------------
 4669|    289|		op_tag = 0x85;
 4670|  2.38k|	} else {
 4671|  2.38k|		op_tag = 0x81;
 4672|  2.38k|	}
 4673|  2.67k|	r = sc_asn1_put_tag(op_tag, data, datalen, p, sbuflen - (p - sbuf), &p);
 4674|  2.67k|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|  2.67k|#define SC_SUCCESS				0
  ------------------
  |  Branch (4674:6): [True: 0, False: 2.67k]
  ------------------
 4675|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4676|      0|	}
 4677|       |
 4678|       |	/*
 4679|       |	 * alg_id=06 is a place holder for all RSA keys.
 4680|       |	 * Derive the real alg_id based on the size of the
 4681|       |	 * the data, as we are always using raw mode.
 4682|       |	 * Non RSA keys needs some work in this area.
 4683|       |	 */
 4684|       |
 4685|  2.67k|	real_alg_id = priv->alg_id;
 4686|  2.67k|	if (priv->alg_id == 0x06) {
  ------------------
  |  Branch (4686:6): [True: 169, False: 2.50k]
  ------------------
 4687|    169|		switch (datalen) {
 4688|     71|		case 128:
  ------------------
  |  Branch (4688:3): [True: 71, False: 98]
  ------------------
 4689|     71|			real_alg_id = 0x06;
 4690|     71|			break;
 4691|      6|		case 256:
  ------------------
  |  Branch (4691:3): [True: 6, False: 163]
  ------------------
 4692|      6|			real_alg_id = 0x07;
 4693|      6|			break;
 4694|      6|		case 384:
  ------------------
  |  Branch (4694:3): [True: 6, False: 163]
  ------------------
 4695|      6|			real_alg_id = 0x05;
 4696|      6|			break;
 4697|      6|		case 512:
  ------------------
  |  Branch (4697:3): [True: 6, False: 163]
  ------------------
 4698|      6|			real_alg_id = 0x16;
 4699|      6|			break;
 4700|     80|		default:
  ------------------
  |  Branch (4700:3): [True: 80, False: 89]
  ------------------
 4701|     80|			SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NO_CARD_SUPPORT);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
 4702|    169|		}
 4703|    169|	}
 4704|       |	/* EC and ED alg_id was already set */
 4705|       |
 4706|  2.59k|	r = piv_general_io(card, 0x87, real_alg_id, priv->key_ref,
 4707|  2.59k|			sbuf, p - sbuf, rbuf, sizeof rbuf);
 4708|  2.59k|	if (r < 0)
  ------------------
  |  Branch (4708:6): [True: 2.12k, False: 469]
  ------------------
 4709|  2.12k|		goto err;
 4710|       |
 4711|    469|	p2 = rbuf;
 4712|    469|	r = sc_asn1_read_tag(&p2, r, &cla, &tag, &bodylen);
 4713|    469|	if (p2 == NULL || r < 0 || bodylen == 0 || (cla | tag) != 0x7C) {
  ------------------
  |  Branch (4713:6): [True: 134, False: 335]
  |  Branch (4713:20): [True: 125, False: 210]
  |  Branch (4713:29): [True: 111, False: 99]
  |  Branch (4713:45): [True: 86, False: 13]
  ------------------
 4714|    456|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x7C");
  ------------------
  |  |  184|    456|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    456|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    456|	int _ret = (r); \
  |  |  |  |  178|    456|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 456, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|    456|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    456|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|    456|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|    456|		goto err; \
  |  |  |  |  182|    456|	} \
  |  |  |  |  183|    456|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4715|    456|	}
 4716|       |
 4717|     13|	r = sc_asn1_read_tag(&p2, bodylen, &cla, &tag, &taglen);
 4718|     13|	if (p2 == NULL || r < 0 || taglen == 0 || (cla | tag) != 0x82) {
  ------------------
  |  Branch (4718:6): [True: 1, False: 12]
  |  Branch (4718:20): [True: 1, False: 11]
  |  Branch (4718:29): [True: 1, False: 10]
  |  Branch (4718:44): [True: 1, False: 9]
  ------------------
 4719|      4|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "Can't find 0x82");
  ------------------
  |  |  184|      4|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      4|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      4|	int _ret = (r); \
  |  |  |  |  178|      4|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 4, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      4|		goto err; \
  |  |  |  |  182|      4|	} \
  |  |  |  |  183|      4|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4720|      4|	}
 4721|       |
 4722|      9|	if (taglen > outlen) {
  ------------------
  |  Branch (4722:6): [True: 0, False: 9]
  ------------------
 4723|      0|		LOG_TEST_GOTO_ERR(card->ctx, SC_ERROR_INVALID_DATA, "data read longer then buffer");
  ------------------
  |  |  184|      0|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|      0|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|      0|	int _ret = (r); \
  |  |  |  |  178|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4724|      0|	}
 4725|       |
 4726|      9|	memcpy(out, p2, taglen);
 4727|      9|	r = (int)taglen;
 4728|       |
 4729|  2.59k|err:
 4730|  2.59k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  2.59k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.59k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.59k|	int _ret = r; \
  |  |  |  |  155|  2.59k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.58k, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.58k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.35k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.35k, False: 234]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.58k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.58k|	} 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|  2.59k|	return _ret; \
  |  |  |  |  163|  2.59k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4731|  2.59k|}
card-piv.c:piv_decipher:
 4787|    432|{
 4788|    432|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    432|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    432|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    432|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 432]
  |  |  ------------------
  ------------------
 4789|       |
 4790|    432|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, piv_validate_general_authentication(card, data, datalen, out, outlen));
  ------------------
  |  |  153|    432|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    432|	int _ret = r; \
  |  |  155|    432|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 431, False: 1]
  |  |  ------------------
  |  |  156|    431|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 18]
  |  |  ------------------
  |  |  157|    431|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    431|	} 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|    432|	return _ret; \
  |  |  163|    432|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
 4791|    432|}
card-piv.c:piv_check_sw:
 6068|  29.1k|{
 6069|  29.1k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6070|       |
 6071|  29.1k|	int r;
 6072|       |#ifdef ENABLE_PIV_SM
 6073|       |	int i;
 6074|       |#endif
 6075|  29.1k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  29.1k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6076|       |
 6077|  29.1k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  29.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  29.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  29.1k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 29.1k]
  |  |  ------------------
  ------------------
 6078|       |
 6079|       |	/* may be called before piv_init has allocated priv */
 6080|  29.1k|	if (priv) {
  ------------------
  |  Branch (6080:6): [True: 29.1k, False: 0]
  ------------------
 6081|       |		/* need to save sw1 and sw2 if trying to determine card_state from pin_cmd */
 6082|       |
 6083|  29.1k|		if (priv->pin_cmd_verify) {
  ------------------
  |  Branch (6083:7): [True: 2.65k, False: 26.5k]
  ------------------
 6084|  2.65k|			priv->pin_cmd_verify_sw1 = sw1;
 6085|  2.65k|			priv->pin_cmd_verify_sw2 = sw2;
 6086|  26.5k|		} else {
 6087|       |			/* a command has completed and it is not verify
 6088|       |			 * If we are in a context_specific sequence, unlock
 6089|       |			 * This just decrements the extra lock count
 6090|       |			 */
 6091|  26.5k|			if (priv->context_specific) {
  ------------------
  |  Branch (6091:8): [True: 0, False: 26.5k]
  ------------------
 6092|      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__
  |  |  ------------------
  ------------------
 6093|      0|				priv->context_specific = 0;
 6094|      0|				sc_unlock(card);
 6095|      0|			}
 6096|  26.5k|		}
 6097|       |
 6098|  29.1k|		if (priv->card_issues & CI_VERIFY_630X) {
  ------------------
  |  |  572|  29.1k|#define CI_VERIFY_630X			    0x00000001U /* VERIFY tries left returns 630X rather then 63CX */
  ------------------
  |  Branch (6098:7): [True: 11.1k, False: 18.0k]
  ------------------
 6099|       |
 6100|       |			/* Handle the Yubikey NEO or any other PIV card which returns in response to a verify
 6101|       |			 * 63 0X rather than 63 CX indicate the number of remaining PIN retries.
 6102|       |			 * Perhaps they misread the spec and thought 0xCX meant "clear" or "don't care", not a literal 0xC!
 6103|       |			 */
 6104|  11.1k|			if (priv->pin_cmd_verify && sw1 == 0x63U) {
  ------------------
  |  Branch (6104:8): [True: 1.36k, False: 9.77k]
  |  Branch (6104:32): [True: 44, False: 1.32k]
  ------------------
 6105|     44|				priv->pin_cmd_verify_sw2 |= 0xC0U; /* make it easier to test in other code */
 6106|     44|				if ((sw2 & ~0x0fU) == 0x00U) {
  ------------------
  |  Branch (6106:9): [True: 22, False: 22]
  ------------------
 6107|     22|					sc_log(card->ctx, "Verification failed (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   71|     22|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6108|     22|					return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|     22|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6109|       |					/* this is what the iso_check_sw returns for 63 C0 */
 6110|     22|				}
 6111|     44|			}
 6112|  11.1k|		}
 6113|  29.1k|	}
 6114|       |#ifdef ENABLE_PIV_SM
 6115|       |	/* Note 6982 is map to SC_ERROR_SM_NO_SESSION_KEYS but iso maps it to SC_ERROR_SECURITY_STATUS_NOT_SATISFIED */
 6116|       |	/* we do this because 6982 could also mean a verify is not allowed over contactless without VCI */
 6117|       |	/* we stashed the sw1 and sw2 above for verify */
 6118|       |	/* Check specific NIST sp800-73-4 SM  errors */
 6119|       |	for (i = 0; piv_sm_errors[i].SWs != 0; i++) {
 6120|       |		if (piv_sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
 6121|       |			sc_log(card->ctx, "%s", piv_sm_errors[i].errorstr);
 6122|       |			return piv_sm_errors[i].errorno;
 6123|       |		}
 6124|       |	}
 6125|       |#endif
 6126|  29.1k|	r = iso_drv->ops->check_sw(card, sw1, sw2);
 6127|  29.1k|	return r;
 6128|  29.1k|}
card-piv.c:piv_card_ctl:
 4482|  50.3k|{
 4483|  50.3k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  50.3k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4484|  50.3k|	u8 *opts; /*  A or M, key_ref, alg_id */
 4485|       |
 4486|  50.3k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  50.3k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  50.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  50.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  50.3k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 50.3k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4487|       |
 4488|  50.3k|	if (priv == NULL) {
  ------------------
  |  Branch (4488:6): [True: 0, False: 50.3k]
  ------------------
 4489|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4490|      0|	}
 4491|  50.3k|	switch (cmd) {
  ------------------
  |  Branch (4491:10): [True: 50.3k, False: 0]
  ------------------
 4492|      0|	case SC_CARDCTL_PIV_AUTHENTICATE:
  ------------------
  |  Branch (4492:2): [True: 0, False: 50.3k]
  ------------------
 4493|      0|		opts = (u8 *)ptr;
 4494|      0|		switch (*opts) {
  ------------------
  |  Branch (4494:11): [True: 0, False: 0]
  ------------------
 4495|      0|		case 'A':
  ------------------
  |  Branch (4495:3): [True: 0, False: 0]
  ------------------
 4496|      0|			return piv_general_external_authenticate(card,
 4497|      0|					*(opts + 1), *(opts + 2));
 4498|      0|			break;
 4499|      0|		case 'M':
  ------------------
  |  Branch (4499:3): [True: 0, False: 0]
  ------------------
 4500|      0|			return piv_general_mutual_authenticate(card,
 4501|      0|					*(opts + 1), *(opts + 2));
 4502|      0|			break;
 4503|      0|		}
 4504|      0|		break;
 4505|      0|	case SC_CARDCTL_PIV_GENERATE_KEY:
  ------------------
  |  Branch (4505:2): [True: 0, False: 50.3k]
  ------------------
 4506|      0|		return piv_generate_key(card,
 4507|      0|				(sc_cardctl_piv_genkey_info_t *)ptr);
 4508|      0|		break;
 4509|    786|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (4509:2): [True: 786, False: 49.5k]
  ------------------
 4510|    786|		return piv_get_serial_nr_from_CHUI(card, (sc_serial_number_t *)ptr);
 4511|      0|		break;
 4512|    786|	case SC_CARDCTL_PIV_PIN_PREFERENCE:
  ------------------
  |  Branch (4512:2): [True: 786, False: 49.5k]
  ------------------
 4513|    786|		return piv_get_pin_preference(card, ptr);
 4514|      0|		break;
 4515|  48.7k|	case SC_CARDCTL_PIV_OBJECT_PRESENT:
  ------------------
  |  Branch (4515:2): [True: 48.7k, False: 1.57k]
  ------------------
 4516|  48.7k|		return piv_is_object_present(card, ptr);
 4517|      0|		break;
 4518|  50.3k|	}
 4519|       |
 4520|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4521|      0|}
card-piv.c:piv_get_serial_nr_from_CHUI:
 4361|    786|{
 4362|    786|	int r;
 4363|    786|	int i;
 4364|    786|	u8 gbits = 0; /* 0 not present or wrong length or all zeros */
 4365|    786|	u8 fbits = 0; /* 0 not present or wrong length or all zeros */
 4366|    786|	u8 *rbuf = NULL;
 4367|    786|	const u8 *body;
 4368|    786|	const u8 *fascn;
 4369|    786|	const u8 *guid;
 4370|    786|	size_t rbuflen = 0, bodylen, fascnlen, guidlen;
 4371|       |
 4372|    786|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    786|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    786|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    786|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 786]
  |  |  ------------------
  ------------------
 4373|    786|	if (card->serialnr.len) {
  ------------------
  |  Branch (4373:6): [True: 0, False: 786]
  ------------------
 4374|      0|		*serial = card->serialnr;
 4375|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4376|      0|	}
 4377|       |
 4378|       |	/*
 4379|       |	 * 800-73-3 Part 1 and CIO Council docs say for PIV Compatible cards
 4380|       |	 * the FASC-N Agency code should be 9999 and there should be a GUID
 4381|       |	 * based on RFC 4122. If GUID present and not zero
 4382|       |	 * we will use the GUID as the serial number.
 4383|       |	 */
 4384|       |
 4385|    786|	r = piv_get_cached_data(card, PIV_OBJ_CHUI, &rbuf, &rbuflen);
 4386|    786|	LOG_TEST_RET(card->ctx, r, "Failure retrieving CHUI");
  ------------------
  |  |  174|    786|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    786|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    786|	int _ret = (r); \
  |  |  |  |  168|    786|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 665, False: 121]
  |  |  |  |  ------------------
  |  |  |  |  169|    665|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    665|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    665|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    665|		return _ret; \
  |  |  |  |  172|    665|	} \
  |  |  |  |  173|    786|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 121]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4387|       |
 4388|    121|	r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|    121|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4389|    121|	if (rbuflen != 0) {
  ------------------
  |  Branch (4389:6): [True: 121, False: 0]
  ------------------
 4390|    121|		body = sc_asn1_find_tag(card->ctx, rbuf, rbuflen, 0x53, &bodylen); /* Pass the outer wrapper asn1 */
 4391|    121|		if (body != NULL && bodylen != 0 && rbuf[0] == 0x53) {
  ------------------
  |  Branch (4391:7): [True: 121, False: 0]
  |  Branch (4391:23): [True: 118, False: 3]
  |  Branch (4391:39): [True: 118, False: 0]
  ------------------
 4392|    118|			fascn = sc_asn1_find_tag(card->ctx, body, bodylen, 0x30, &fascnlen); /* Find the FASC-N data */
 4393|       |
 4394|    118|			if (fascn && fascnlen == 25) {
  ------------------
  |  Branch (4394:8): [True: 46, False: 72]
  |  Branch (4394:17): [True: 42, False: 4]
  ------------------
 4395|  1.09k|				for (i = 0; i < 25; i++) {
  ------------------
  |  Branch (4395:17): [True: 1.05k, False: 42]
  ------------------
 4396|  1.05k|					fbits = fbits || fascn[i]; /* if all are zero, gbits will be zero */
  ------------------
  |  Branch (4396:14): [True: 885, False: 165]
  |  Branch (4396:23): [True: 41, False: 124]
  ------------------
 4397|  1.05k|				}
 4398|     42|			}
 4399|       |
 4400|    118|			guid = sc_asn1_find_tag(card->ctx, body, bodylen, 0x34, &guidlen);
 4401|       |
 4402|    118|			if (guid && guidlen == 16) {
  ------------------
  |  Branch (4402:8): [True: 30, False: 88]
  |  Branch (4402:16): [True: 27, False: 3]
  ------------------
 4403|    459|				for (i = 0; i < 16; i++) {
  ------------------
  |  Branch (4403:17): [True: 432, False: 27]
  ------------------
 4404|    432|					gbits = gbits | guid[i]; /* if all are zero, gbits will be zero */
 4405|    432|				}
 4406|     27|			}
 4407|    118|			sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 4408|    118|					"fascn=%p,fascnlen=%" SC_FORMAT_LEN_SIZE_T "u,guid=%p,guidlen=%" SC_FORMAT_LEN_SIZE_T "u,gbits=%2.2x",
 4409|    118|					fascn, fascnlen, guid, guidlen, gbits);
 4410|       |
 4411|    118|			if (fascn && fascnlen == 25 && fbits) {
  ------------------
  |  Branch (4411:8): [True: 46, False: 72]
  |  Branch (4411:17): [True: 42, False: 4]
  |  Branch (4411:35): [True: 41, False: 1]
  ------------------
 4412|       |				/* test if guid and the fascn starts with ;9999 (in ISO 4bit + parity code) */
 4413|       |				/* ;9999 is non-gov issued FASC-N, will use FASC-N for gov issued if no guid */
 4414|     41|				if (!(gbits && fascn[0] == 0xD4 && fascn[1] == 0xE7 &&
  ------------------
  |  Branch (4414:11): [True: 25, False: 16]
  |  Branch (4414:20): [True: 5, False: 20]
  |  Branch (4414:40): [True: 4, False: 1]
  ------------------
 4415|     40|						    fascn[2] == 0x39 && (fascn[3] | 0x7F) == 0xFF)) {
  ------------------
  |  Branch (4415:11): [True: 2, False: 2]
  |  Branch (4415:31): [True: 1, False: 1]
  ------------------
 4416|       |					/* fascnlen is 25 */
 4417|     40|					serial->len = fascnlen;
 4418|     40|					memcpy(serial->value, fascn, serial->len);
 4419|     40|					r = SC_SUCCESS;
  ------------------
  |  |   28|     40|#define SC_SUCCESS				0
  ------------------
 4420|     40|					gbits = 0; /* set to skip using guid below */
 4421|     40|				}
 4422|     41|			}
 4423|    118|			if (guid && guidlen == 16 && gbits) {
  ------------------
  |  Branch (4423:8): [True: 30, False: 88]
  |  Branch (4423:16): [True: 27, False: 3]
  |  Branch (4423:33): [True: 3, False: 24]
  ------------------
 4424|      3|				serial->len = guidlen;
 4425|      3|				memcpy(serial->value, guid, serial->len);
 4426|      3|				r = SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 4427|      3|			}
 4428|    118|		}
 4429|    121|	}
 4430|       |
 4431|    121|	if (fbits == 0 && gbits == 0) { /* were not able to set the serial number */
  ------------------
  |  Branch (4431:6): [True: 80, False: 41]
  |  Branch (4431:20): [True: 78, False: 2]
  ------------------
 4432|     78|		serial->len = 16;
 4433|     78|		memset(serial->value, 0x00, serial->len);
 4434|     78|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|     78|#define SC_ERROR_INTERNAL			-1400
  ------------------
 4435|     78|	}
 4436|       |
 4437|    121|	card->serialnr = *serial;
 4438|    121|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    121|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    121|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    121|	int _ret = r; \
  |  |  |  |  155|    121|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 121, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    121|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     78|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 78, False: 43]
  |  |  |  |  ------------------
  |  |  |  |  157|    121|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    121|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    121|	return _ret; \
  |  |  |  |  163|    121|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4439|    121|}
card-piv.c:piv_get_pin_preference:
 4473|    786|{
 4474|    786|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|    786|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4475|       |
 4476|    786|	*pin_ref = priv->pin_preference;
 4477|    786|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    786|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    786|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    786|	int _ret = r; \
  |  |  |  |  155|    786|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 786, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    786|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 786]
  |  |  |  |  ------------------
  |  |  |  |  157|    786|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    786|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    786|	return _ret; \
  |  |  |  |  163|    786|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4478|    786|}
card-piv.c:piv_is_object_present:
 4454|  48.7k|{
 4455|  48.7k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  48.7k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 4456|  48.7k|	int r = 0;
 4457|  48.7k|	int enumtag;
 4458|       |
 4459|  48.7k|	enumtag = piv_find_obj_by_containerid(card, ptr);
 4460|  48.7k|	if (enumtag >= 0 && priv->obj_cache[enumtag].flags & PIV_OBJ_CACHE_NOT_PRESENT)
  ------------------
  |  |  150|  47.9k|#define PIV_OBJ_CACHE_NOT_PRESENT	8
  ------------------
  |  Branch (4460:6): [True: 47.9k, False: 786]
  |  Branch (4460:22): [True: 27.4k, False: 20.5k]
  ------------------
 4461|  27.4k|		r = 1;
 4462|       |
 4463|  48.7k|	LOG_FUNC_RETURN(card->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: 21.3k, False: 27.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|  21.3k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 21.3k]
  |  |  |  |  ------------------
  |  |  |  |  157|  21.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  27.4k|	} else { \
  |  |  |  |  159|  27.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  27.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  27.4k|	} \
  |  |  |  |  162|  48.7k|	return _ret; \
  |  |  |  |  163|  48.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 4464|  48.7k|}
card-piv.c:piv_pin_cmd:
 6201|  1.92k|{
 6202|  1.92k|	int r = 0;
 6203|  1.92k|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|  1.92k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6204|       |
 6205|       |	/* Extra validation of (new) PIN during a PIN change request, to
 6206|       |	 * ensure it's not outside the FIPS 201 4.1.6.1 (numeric only) and
 6207|       |	 * FIPS 140-2 (6 character minimum) requirements.
 6208|       |	 */
 6209|  1.92k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 6210|       |
 6211|  1.92k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  1.92k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  1.92k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  1.92k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 1.92k]
  |  |  ------------------
  ------------------
 6212|  1.92k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 6213|  1.92k|	if (data->cmd == SC_PIN_CMD_CHANGE) {
  ------------------
  |  |  423|  1.92k|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (6213:6): [True: 108, False: 1.82k]
  ------------------
 6214|    108|		size_t i = 0;
 6215|    108|		if (data->pin2.len < 6) {
  ------------------
  |  Branch (6215:7): [True: 30, False: 78]
  ------------------
 6216|     30|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|     30|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 6217|     30|		}
 6218|    380|		for (i = 0; i < data->pin2.len; ++i) {
  ------------------
  |  Branch (6218:15): [True: 344, False: 36]
  ------------------
 6219|    344|			if (!isdigit(data->pin2.data[i])) {
  ------------------
  |  Branch (6219:8): [True: 42, False: 302]
  ------------------
 6220|     42|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     42|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
 6221|     42|			}
 6222|    344|		}
 6223|     78|	}
 6224|       |
 6225|  1.85k|	priv->pin_cmd_verify_sw1 = 0x00U;
 6226|       |
 6227|  1.85k|	if (data->cmd == SC_PIN_CMD_GET_INFO) { /* fill in what we think it should be */
  ------------------
  |  |  425|  1.85k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6227:6): [True: 1.55k, False: 304]
  ------------------
 6228|  1.55k|		data->pin1.logged_in = priv->logged_in;
 6229|  1.55k|		data->pin1.tries_left = priv->tries_left;
 6230|  1.55k|		if (tries_left)
  ------------------
  |  Branch (6230:7): [True: 0, False: 1.55k]
  ------------------
 6231|      0|			*tries_left = priv->tries_left;
 6232|       |
 6233|       |		/*
 6234|       |		 * If called to check on the login state for a context specific login
 6235|       |		 * return not logged in. Needed because of logic in e6f7373ef066
 6236|       |		 */
 6237|  1.55k|		if (data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|  1.55k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6237:7): [True: 0, False: 1.55k]
  ------------------
 6238|      0|			data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      0|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6239|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6240|      0|		}
 6241|       |
 6242|  1.55k|		if (priv->logged_in & SC_PIN_STATE_LOGGED_IN) {
  ------------------
  |  |  439|  1.55k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
  |  Branch (6242:7): [True: 45, False: 1.50k]
  ------------------
 6243|       |			/* Avoid status requests when the user is logged in to handle NIST
 6244|       |			 * 800-73-4 Part 2:
 6245|       |			 * The PKI cryptographic function (see Table 4b) is protected with
 6246|       |			 * a “PIN Always” or “OCC Always” access rule. In other words, the
 6247|       |			 * PIN or OCC data must be submitted and verified every time
 6248|       |			 * immediately before a digital signature key operation.  This
 6249|       |			 * ensures cardholder participation every time the private key is
 6250|       |			 * used for digital signature generation */
 6251|     45|			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|     45|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|     45|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|     45|	int _ret = r; \
  |  |  |  |  155|     45|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 45, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|     45|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 45]
  |  |  |  |  ------------------
  |  |  |  |  157|     45|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     45|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|     45|	return _ret; \
  |  |  |  |  163|     45|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6252|     45|		}
 6253|  1.55k|	}
 6254|       |
 6255|       |	/*
 6256|       |	 * If this was for a CKU_CONTEXT_SPECFIC login, lock the card one more time.
 6257|       |	 * to avoid any interference from other applications.
 6258|       |	 * Sc_unlock will be called at a later time after the next card command
 6259|       |	 * that should be a crypto operation. If its not then it is a error by the
 6260|       |	 * calling application.
 6261|       |	 */
 6262|  1.81k|	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  422|  3.62k|#define SC_PIN_CMD_VERIFY	0
  ------------------
              	if (data->cmd == SC_PIN_CMD_VERIFY && data->pin_type == SC_AC_CONTEXT_SPECIFIC) {
  ------------------
  |  |  160|    160|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (6262:6): [True: 160, False: 1.65k]
  |  Branch (6262:40): [True: 0, False: 160]
  ------------------
 6263|      0|		priv->context_specific = 1;
 6264|      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__
  |  |  ------------------
  ------------------
 6265|      0|		r = sc_lock(card);
 6266|      0|		if (r != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (6266:7): [True: 0, False: 0]
  ------------------
 6267|      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__
  |  |  ------------------
  ------------------
 6268|      0|			return r;
 6269|      0|		}
 6270|      0|	}
 6271|       |
 6272|  1.81k|	priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6273|  1.81k|	r = iso_drv->ops->pin_cmd(card, data, tries_left);
 6274|  1.81k|	priv->pin_cmd_verify = 0;
 6275|       |
 6276|       |	/* tell user verify not supported on contactless without VCI */
 6277|  1.81k|	if (priv->pin_cmd_verify_sw1 == 0x69 && priv->pin_cmd_verify_sw2 == 0x82 &&
  ------------------
  |  Branch (6277:6): [True: 21, False: 1.79k]
  |  Branch (6277:42): [True: 17, False: 4]
  ------------------
 6278|     17|			priv->init_flags & PIV_INIT_CONTACTLESS &&
  ------------------
  |  |  382|  1.82k|#define PIV_INIT_CONTACTLESS			0x00000020u
  ------------------
  |  Branch (6278:4): [True: 0, False: 17]
  ------------------
 6279|      0|			card->type == SC_CARD_TYPE_PIV_II_800_73_4) {
  ------------------
  |  Branch (6279:4): [True: 0, False: 0]
  ------------------
 6280|      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__
  |  |  ------------------
  ------------------
 6281|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 6282|      0|	}
 6283|       |
 6284|       |	/* if verify failed, release the lock */
 6285|  1.81k|	if (data->cmd == SC_PIN_CMD_VERIFY && r < 0 && priv->context_specific) {
  ------------------
  |  |  422|  3.62k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6285:6): [True: 160, False: 1.65k]
  |  Branch (6285:40): [True: 131, False: 29]
  |  Branch (6285:49): [True: 0, False: 131]
  ------------------
 6286|      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__
  |  |  ------------------
  ------------------
 6287|      0|		priv->context_specific = 0;
 6288|      0|		sc_unlock(card);
 6289|      0|	}
 6290|       |
 6291|       |	/* if access to applet is know to be reset by other driver  we select_aid and try again */
 6292|  1.81k|	if (priv->card_issues & CI_OTHER_AID_LOSE_STATE && priv->pin_cmd_verify_sw1 == 0x6DU) {
  ------------------
  |  |  581|  3.62k|#define CI_OTHER_AID_LOSE_STATE		    0x00000100U /* Other drivers match routines may reset our security state and lose AID!!! */
  ------------------
  |  Branch (6292:6): [True: 967, False: 844]
  |  Branch (6292:53): [True: 847, False: 120]
  ------------------
 6293|    847|		sc_log(card->ctx, "AID may be lost doing piv_find_aid and retry pin_cmd");
  ------------------
  |  |   71|    847|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6294|    847|		piv_find_aid(card);
 6295|       |
 6296|    847|		priv->pin_cmd_verify = 1; /* tell piv_check_sw its a verify to save sw1, sw2 */
 6297|    847|		r = iso_drv->ops->pin_cmd(card, data, tries_left);
 6298|    847|		priv->pin_cmd_verify = 0;
 6299|    847|	}
 6300|       |
 6301|       |	/* If verify worked, we are logged_in */
 6302|  1.81k|	if (data->cmd == SC_PIN_CMD_VERIFY) {
  ------------------
  |  |  422|  1.81k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (6302:6): [True: 160, False: 1.65k]
  ------------------
 6303|    160|		if (r >= 0)
  ------------------
  |  Branch (6303:7): [True: 32, False: 128]
  ------------------
 6304|     32|			priv->logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|     32|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6305|    128|		else
 6306|    128|			priv->logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|    128|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6307|    160|	}
 6308|       |
 6309|       |	/* Some cards never return 90 00  for SC_PIN_CMD_GET_INFO even if the card state is verified */
 6310|       |	/* PR 797 has changed the return codes from pin_cmd, and added a data->pin1.logged_in flag */
 6311|       |
 6312|  1.81k|	if (data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  425|  1.81k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (6312:6): [True: 1.50k, False: 304]
  ------------------
 6313|  1.50k|		if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) {
  ------------------
  |  |  576|  1.50k|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6313:7): [True: 7, False: 1.50k]
  ------------------
 6314|      7|			sc_log(card->ctx, "CI_CANT_USE_GETDATA_FOR_STATE set, assume logged_in=%d", priv->logged_in);
  ------------------
  |  |   71|      7|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6315|      7|			data->pin1.logged_in = priv->logged_in; /* use what ever we saw last */
 6316|  1.50k|		} else if (priv->card_issues & CI_VERIFY_LC0_FAIL &&
  ------------------
  |  |  573|  3.00k|#define CI_VERIFY_LC0_FAIL		    0x00000002U /* VERIFY Lc=0 never returns 90 00 if PIN not needed */
  ------------------
  |  Branch (6316:14): [True: 468, False: 1.03k]
  ------------------
 6317|    468|				priv->pin_cmd_verify_sw1 == 0x63U) { /* can not use modified return codes from iso->drv->pin_cmd */
  ------------------
  |  Branch (6317:5): [True: 18, False: 450]
  ------------------
 6318|       |			/* try another method, looking at a protected object this may require adding one of these to NEO */
 6319|     18|			r = piv_check_protected_objects(card);
 6320|     18|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|     18|#define SC_SUCCESS				0
  ------------------
  |  Branch (6320:8): [True: 1, False: 17]
  ------------------
 6321|      1|				data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|      1|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 6322|     17|			else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|     17|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (6322:13): [True: 15, False: 2]
  ------------------
 6323|     15|				if (priv->card_issues & CI_CANT_USE_GETDATA_FOR_STATE) { /* we still can not determine login state */
  ------------------
  |  |  576|     15|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
  |  Branch (6323:9): [True: 7, False: 8]
  ------------------
 6324|       |
 6325|      7|					data->pin1.logged_in = priv->logged_in; /* may have be set from SC_PIN_CMD_VERIFY */
 6326|      8|				} else {
 6327|      8|					data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      8|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 6328|      8|				}
 6329|     15|				r = SC_SUCCESS;
  ------------------
  |  |   28|     15|#define SC_SUCCESS				0
  ------------------
 6330|     15|			}
 6331|     18|		}
 6332|  1.50k|		priv->logged_in = data->pin1.logged_in;
 6333|  1.50k|		priv->tries_left = data->pin1.tries_left;
 6334|  1.50k|	}
 6335|       |
 6336|  1.81k|	sc_log(card->ctx, "piv_pin_cmd tries_left=%d, logged_in=%d", priv->tries_left, priv->logged_in);
  ------------------
  |  |   71|  1.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__
  |  |  ------------------
  ------------------
 6337|  1.81k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.81k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.81k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.81k|	int _ret = r; \
  |  |  |  |  155|  1.81k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.81k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.81k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.70k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.70k, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.81k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.81k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  1.81k|	return _ret; \
  |  |  |  |  163|  1.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6338|  1.81k|}
card-piv.c:piv_check_protected_objects:
 6132|     18|{
 6133|     18|	int r = 0;
 6134|     18|	int i;
 6135|     18|	piv_private_data_t *priv = PIV_DATA(card);
  ------------------
  |  |  432|     18|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6136|     18|	u8 buf[8]; /* tag of 53 with 82 xx xx  will fit in 4 */
 6137|     18|	u8 *rbuf;
 6138|     18|	size_t buf_len;
 6139|     18|	static int protected_objects[] = {PIV_OBJ_PI, PIV_OBJ_CHF, PIV_OBJ_IRIS_IMAGE};
 6140|       |
 6141|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6142|       |	/*
 6143|       |	 * routine only called from piv_pin_cmd after verify lc=0 did not return 90 00
 6144|       |	 * We will test for a protected object using GET DATA.
 6145|       |	 *
 6146|       |	 * Based on observations, of cards using the GET DATA APDU,
 6147|       |	 * SC_ERROR_SECURITY_STATUS_NOT_SATISFIED  means the PIN not verified,
 6148|       |	 * SC_SUCCESS means PIN has been verified even if it has length 0
 6149|       |	 * SC_ERROR_FILE_NOT_FOUND (which is the bug) does not tell us anything
 6150|       |	 * about the state of the PIN and we will try the next object.
 6151|       |	 *
 6152|       |	 * If we can't determine the security state from this process,
 6153|       |	 * set card_issues CI_CANT_USE_GETDATA_FOR_STATE
 6154|       |	 * and return SC_ERROR_PIN_CODE_INCORRECT
 6155|       |	 * The circumvention is to add a dummy Printed Info object in the card.
 6156|       |	 * so we will have an object to test.
 6157|       |	 *
 6158|       |	 * We save the object's number to use in the future.
 6159|       |	 *
 6160|       |	 */
 6161|     18|	if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6161:6): [True: 14, False: 4]
  ------------------
 6162|     38|		for (i = 0; i < (int)(sizeof(protected_objects) / sizeof(int)); i++) {
  ------------------
  |  Branch (6162:15): [True: 31, False: 7]
  ------------------
 6163|     31|			buf_len = sizeof(buf);
 6164|     31|			rbuf = buf;
 6165|     31|			r = piv_get_data(card, protected_objects[i], &rbuf, &buf_len);
 6166|     31|			if (r >= 0 || r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED) {
  ------------------
  |  |   61|     30|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6166:8): [True: 1, False: 30]
  |  Branch (6166:18): [True: 6, False: 24]
  ------------------
 6167|       |
 6168|       |				/* we can use this object next time if needed */
 6169|      7|				priv->object_test_verify = protected_objects[i];
 6170|      7|				break;
 6171|      7|			}
 6172|     31|		}
 6173|     14|		if (priv->object_test_verify == 0) {
  ------------------
  |  Branch (6173:7): [True: 7, False: 7]
  ------------------
 6174|       |			/*
 6175|       |			 * none of the objects returned acceptable sw1, sw2
 6176|       |			 */
 6177|      7|			sc_log(card->ctx, "No protected objects found, setting CI_CANT_USE_GETDATA_FOR_STATE");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 6178|      7|			priv->card_issues |= CI_CANT_USE_GETDATA_FOR_STATE;
  ------------------
  |  |  576|      7|#define CI_CANT_USE_GETDATA_FOR_STATE	    0x00000008U /* No object to test verification inplace of VERIFY Lc=0 */
  ------------------
 6179|      7|			r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      7|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6180|      7|		}
 6181|     14|	} else {
 6182|       |		/* use the one object we found earlier. Test is security status has changed */
 6183|      4|		buf_len = sizeof(buf);
 6184|      4|		rbuf = buf;
 6185|      4|		r = piv_get_data(card, priv->object_test_verify, &rbuf, &buf_len);
 6186|      4|	}
 6187|     18|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|     18|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (6187:6): [True: 1, False: 17]
  ------------------
 6188|      1|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      1|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6189|     17|	else if (r == SC_ERROR_SECURITY_STATUS_NOT_SATISFIED)
  ------------------
  |  |   61|     17|#define SC_ERROR_SECURITY_STATUS_NOT_SATISFIED	-1211
  ------------------
  |  Branch (6189:11): [True: 7, False: 10]
  ------------------
 6190|      7|		r = SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|      7|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
 6191|     10|	else if (r > 0)
  ------------------
  |  Branch (6191:11): [True: 1, False: 9]
  ------------------
 6192|      1|		r = SC_SUCCESS;
  ------------------
  |  |   28|      1|#define SC_SUCCESS				0
  ------------------
 6193|       |
 6194|     18|	sc_log(card->ctx, "card->type:%d CI:%08x r:%d AI:%08x\n",
  ------------------
  |  |   71|     18|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6195|     18|			card->type, priv->card_issues, r, priv->alg_ids);
 6196|     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|     17|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 17, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6197|     18|}
card-piv.c:piv_card_reader_lock_obtained:
 6377|  11.4k|{
 6378|  11.4k|	int r = 0;
 6379|  11.4k|	u8 temp[SC_MAX_APDU_BUFFER_SIZE];
 6380|  11.4k|	size_t templen = sizeof(temp);
 6381|  11.4k|	piv_private_data_t *priv = PIV_DATA(card); /* may be null */
  ------------------
  |  |  432|  11.4k|#define PIV_DATA(card) ((piv_private_data_t*)card->drv_data)
  ------------------
 6382|       |
 6383|  11.4k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  11.4k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.4k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.4k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.4k]
  |  |  ------------------
  ------------------
 6384|       |
 6385|       |	/* We have a PCSC transaction and sc_lock */
 6386|  11.4k|	if (priv == NULL || priv->pstate == PIV_STATE_MATCH) {
  ------------------
  |  Branch (6386:6): [True: 5.07k, False: 6.35k]
  |  Branch (6386:22): [True: 786, False: 5.57k]
  ------------------
 6387|  5.85k|		sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE,
  ------------------
  |  |   70|  11.7k|#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: 786, False: 5.07k]
  |  |  ------------------
  ------------------
 6388|  5.85k|				priv ? "PIV_STATE_MATCH" : "priv==NULL");
 6389|  5.85k|		r = 0; /* do nothing, piv_match will take care of it */
 6390|  5.85k|		goto err;
 6391|  5.85k|	}
 6392|       |
 6393|  5.57k|	priv->init_flags |= PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  381|  5.57k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6394|       |
 6395|       |	/* make sure our application is active */
 6396|       |
 6397|       |	/* first see if AID is active AID by reading discovery object '7E' */
 6398|       |	/* If not try selecting AID */
 6399|       |
 6400|       |	/* but if card does not support DISCOVERY object we can not use it */
 6401|  5.57k|	if (priv->card_issues & CI_DISCOVERY_USELESS) {
  ------------------
  |  |  578|  5.57k|#define CI_DISCOVERY_USELESS		    0x00000020U /* Discovery can not be used to query active AID invalid or no data returned */
  ------------------
  |  Branch (6401:6): [True: 2.49k, False: 3.07k]
  ------------------
 6402|  2.49k|		r = SC_ERROR_NO_CARD_SUPPORT;
  ------------------
  |  |   58|  2.49k|#define SC_ERROR_NO_CARD_SUPPORT		-1208
  ------------------
 6403|  3.07k|	} else {
 6404|  3.07k|		r = piv_find_discovery(card);
 6405|       |#ifdef ENABLE_PIV_SM
 6406|       |		/*
 6407|       |		 * All 800-73-4 cards that support SM, also have a discovery object with
 6408|       |		 * the pin_policy, so can not have CI_DISCOVERY_USELESS
 6409|       |		 * Discovery object can be read with contact or contactless
 6410|       |		 * If read with SM and fails with 69 88  SC_ERROR_SM_INVALID_SESSION_KEY
 6411|       |		 * sm.c will close the SM connectrion, and set defer
 6412|       |		 */
 6413|       |		if (was_reset == 0 && (r == SC_ERROR_SM_INVALID_SESSION_KEY || priv->sm_flags & PIV_SM_FLAGS_DEFER_OPEN)) {
 6414|       |			sc_log(card->ctx, "SC_ERROR_SM_INVALID_SESSION_KEY || PIV_SM_FLAGS_DEFER_OPEN");
 6415|       |			piv_sm_open(card);
 6416|       |			r = piv_find_discovery(card);
 6417|       |		}
 6418|       |#endif /* ENABLE_PIV_SM */
 6419|  3.07k|	}
 6420|       |
 6421|  5.57k|	if (r < 0) {
  ------------------
  |  Branch (6421:6): [True: 5.56k, False: 9]
  ------------------
 6422|  5.56k|		if (was_reset > 0 || !(priv->card_issues & CI_PIV_AID_LOSE_STATE)) {
  ------------------
  |  |  579|  5.56k|#define CI_PIV_AID_LOSE_STATE		    0x00000040U /* PIV AID can lose the login state run with out it*/
  ------------------
  |  Branch (6422:7): [True: 0, False: 5.56k]
  |  Branch (6422:24): [True: 5.38k, False: 179]
  ------------------
 6423|  5.38k|			r = iso7816_select_aid(card, piv_aids[0].value, piv_aids[0].len_short, temp, &templen);
 6424|  5.38k|			sc_debug(card->ctx, SC_LOG_DEBUG_MATCH, "iso7816_select_aid card->type:%d r:%d\n", card->type, r);
  ------------------
  |  |   70|  5.38k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 6425|  5.38k|		} else {
 6426|    179|			r = 0; /* can't do anything with this card, hope there was no interference */
 6427|    179|		}
 6428|  5.56k|	}
 6429|       |
 6430|  5.57k|	if (r < 0) /* bad error return will show up in sc_lock as error*/
  ------------------
  |  Branch (6430:6): [True: 4.81k, False: 754]
  ------------------
 6431|  4.81k|		goto err;
 6432|       |
 6433|    754|	if (was_reset > 0)
  ------------------
  |  Branch (6433:6): [True: 0, False: 754]
  ------------------
 6434|      0|		priv->logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|      0|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
 6435|       |
 6436|    754|	r = 0;
 6437|       |
 6438|  11.4k|err:
 6439|  11.4k|	if (priv)
  ------------------
  |  Branch (6439:6): [True: 6.35k, False: 5.07k]
  ------------------
 6440|  6.35k|		priv->init_flags &= ~PIV_INIT_IN_READER_LOCK_OBTAINED;
  ------------------
  |  |  381|  6.35k|#define PIV_INIT_IN_READER_LOCK_OBTAINED	0x00000010u
  ------------------
 6441|  11.4k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  11.4k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  11.4k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  11.4k|	int _ret = r; \
  |  |  |  |  155|  11.4k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11.4k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  11.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|  4.81k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 4.81k, False: 6.61k]
  |  |  |  |  ------------------
  |  |  |  |  157|  11.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  11.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|  11.4k|	return _ret; \
  |  |  |  |  163|  11.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 6442|  11.4k|}

sc_get_rtecp_driver:
  869|  15.3k|{
  870|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (870:6): [True: 1, False: 15.3k]
  ------------------
  871|      1|		iso_ops = sc_get_iso7816_driver()->ops;
  872|  15.3k|	rtecp_ops = *iso_ops;
  873|       |
  874|  15.3k|	rtecp_ops.match_card = rtecp_match_card;
  875|  15.3k|	rtecp_ops.init = rtecp_init;
  876|       |	/* read_binary */
  877|  15.3k|	rtecp_ops.write_binary = NULL;
  878|       |	/* update_binary */
  879|  15.3k|	rtecp_ops.read_record = NULL;
  880|  15.3k|	rtecp_ops.write_record = NULL;
  881|  15.3k|	rtecp_ops.append_record = NULL;
  882|  15.3k|	rtecp_ops.update_record = NULL;
  883|  15.3k|	rtecp_ops.select_file = rtecp_select_file;
  884|       |	/* get_response */
  885|       |	/* get_challenge */
  886|  15.3k|	rtecp_ops.verify = rtecp_verify;
  887|  15.3k|	rtecp_ops.logout = rtecp_logout;
  888|       |	/* restore_security_env */
  889|  15.3k|	rtecp_ops.set_security_env = rtecp_set_security_env;
  890|  15.3k|	rtecp_ops.decipher = rtecp_decipher;
  891|  15.3k|	rtecp_ops.compute_signature = rtecp_compute_signature;
  892|  15.3k|	rtecp_ops.change_reference_data = rtecp_change_reference_data;
  893|  15.3k|	rtecp_ops.reset_retry_counter = rtecp_reset_retry_counter;
  894|  15.3k|	rtecp_ops.create_file = rtecp_create_file;
  895|       |	/* delete_file */
  896|  15.3k|	rtecp_ops.list_files = rtecp_list_files;
  897|       |	/* check_sw */
  898|  15.3k|	rtecp_ops.card_ctl = rtecp_card_ctl;
  899|       |	/* process_fci */
  900|  15.3k|	rtecp_ops.construct_fci = rtecp_construct_fci;
  901|       |	rtecp_ops.pin_cmd = NULL;
  902|  15.3k|	return &rtecp_drv;
  903|  15.3k|}
card-rtecp.c:rtecp_match_card:
   73|  8.28k|{
   74|  8.28k|	int i = -1;
   75|  8.28k|	i = _sc_match_atr(card, rtecp_atrs, &card->type);
   76|  8.28k|	if (i >= 0) {
  ------------------
  |  Branch (76:6): [True: 81, False: 8.19k]
  ------------------
   77|     81|		card->name = rtecp_atrs[i].name;
   78|     81|		LOG_FUNC_RETURN(card->ctx, 1);
  ------------------
  |  |  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: 0, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"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|     81|	return _ret; \
  |  |  |  |  163|     81|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   79|     81|	}
   80|  8.19k|	LOG_FUNC_RETURN(card->ctx, 0);
  ------------------
  |  |  164|  8.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.19k|	int _ret = r; \
  |  |  |  |  155|  8.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.19k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.19k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 8.19k]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.19k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.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|  8.19k|	return _ret; \
  |  |  |  |  163|  8.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   81|  8.19k|}
card-rtecp.c:rtecp_init:
   84|     81|{
   85|     81|	sc_algorithm_info_t info;
   86|     81|	unsigned long flags;
   87|       |
   88|     81|	if (!card || !card->ctx)
  ------------------
  |  Branch (88:6): [True: 0, False: 81]
  |  Branch (88:15): [True: 0, False: 81]
  ------------------
   89|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   90|       |
   91|     81|	card->cla = 0;
   92|       |
   93|     81|	if (card->type == SC_CARD_TYPE_RUTOKEN_LITE
  ------------------
  |  Branch (93:6): [True: 1, False: 80]
  ------------------
   94|     80|			|| card->type == SC_CARD_TYPE_RUTOKEN_LITE_SC)
  ------------------
  |  Branch (94:7): [True: 1, False: 79]
  ------------------
   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|     79|	card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     79|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
   98|       |
   99|     79|	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  111|     79|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|     79|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  100|     79|		| SC_ALGORITHM_RSA_PAD_NONE | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  113|     79|#define SC_ALGORITHM_RSA_PAD_NONE	0x00000001
  ------------------
              		| SC_ALGORITHM_RSA_PAD_NONE | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  142|     79|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  101|       |
  102|     79|	_sc_card_add_rsa_alg(card, 256, flags, 0);
  103|     79|	_sc_card_add_rsa_alg(card, 512, flags, 0);
  104|     79|	_sc_card_add_rsa_alg(card, 768, flags, 0);
  105|     79|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
  106|     79|	_sc_card_add_rsa_alg(card, 1280, flags, 0);
  107|     79|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
  108|     79|	_sc_card_add_rsa_alg(card, 1792, flags, 0);
  109|     79|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
  110|     79|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
  111|       |
  112|     79|	memset(&info, 0, sizeof(info));
  113|     79|	info.algorithm = SC_ALGORITHM_GOSTR3410;
  ------------------
  |  |   80|     79|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  114|     79|	info.key_length = 256;
  115|     79|	info.flags = SC_ALGORITHM_GOSTR3410_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  165|     79|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  ------------------
              	info.flags = SC_ALGORITHM_GOSTR3410_RAW | SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  102|     79|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  116|     79|		| SC_ALGORITHM_GOSTR3410_HASH_NONE;
  ------------------
  |  |  166|     79|#define SC_ALGORITHM_GOSTR3410_HASH_NONE	SC_ALGORITHM_GOSTR3410_RAW /*XXX*/
  |  |  ------------------
  |  |  |  |  165|     79|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  |  |  ------------------
  ------------------
  117|     79|	_sc_card_add_algorithm(card, &info);
  118|       |
  119|     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]
  |  |  ------------------
  ------------------
  120|     79|}
card-rtecp.c:rtecp_select_file:
  285|    403|{
  286|    403|	sc_file_t *file = NULL;
  287|    403|	int r = SC_SUCCESS;
  ------------------
  |  |   28|    403|#define SC_SUCCESS				0
  ------------------
  288|       |
  289|    403|	if (!card || !card->ctx || !in_path)
  ------------------
  |  Branch (289:6): [True: 0, False: 403]
  |  Branch (289:15): [True: 0, False: 403]
  |  Branch (289:29): [True: 0, False: 403]
  ------------------
  290|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  291|       |
  292|    403|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    403|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    403|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    403|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 403]
  |  |  ------------------
  ------------------
  293|       |
  294|    403|	switch (in_path->type)
  ------------------
  |  Branch (294:10): [True: 134, False: 269]
  ------------------
  295|    403|	{
  296|    134|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|    134|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (296:2): [True: 134, False: 269]
  ------------------
  297|    134|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    134|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (297:2): [True: 0, False: 403]
  ------------------
  298|    134|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    134|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (298:2): [True: 0, False: 403]
  ------------------
  299|    134|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  153|    134|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    134|	int _ret = r; \
  |  |  155|    134|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 134, False: 0]
  |  |  ------------------
  |  |  156|    134|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    134|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 134, False: 0]
  |  |  ------------------
  |  |  157|    134|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    134|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    134|	return _ret; \
  |  |  163|    134|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  300|    403|	}
  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|    269|	r = iso_ops->select_file(card, in_path, &file);
  305|    269|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|    269|#define SC_SUCCESS				0
  ------------------
  |  Branch (305:6): [True: 164, False: 105]
  ------------------
  306|    164|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|    164|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|    164|	int _ret = r; \
  |  |  155|    164|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 164, False: 0]
  |  |  ------------------
  |  |  156|    164|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|    164|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 164, False: 0]
  |  |  ------------------
  |  |  157|    164|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|    164|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|    164|	return _ret; \
  |  |  163|    164|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  307|       |
  308|    105|	if (file->sec_attr && file->sec_attr_len == SC_RTECP_SEC_ATTR_SIZE)
  ------------------
  |  |  779|     97|#define SC_RTECP_SEC_ATTR_SIZE 15
  ------------------
  |  Branch (308:6): [True: 97, False: 8]
  |  Branch (308:24): [True: 91, False: 6]
  ------------------
  309|     91|		set_acl_from_sec_attr(card, file);
  310|     14|	else
  311|     14|	{
  312|     14|		sc_file_free(file);
  313|     14|		SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  314|     14|	}
  315|       |
  316|     91|	if (file_out)
  ------------------
  |  Branch (316:6): [True: 82, False: 9]
  ------------------
  317|     82|		*file_out = file;
  318|      9|	else
  319|      9|		sc_file_free(file);
  320|       |
  321|     91|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     91|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     91|	int _ret = r; \
  |  |  155|     91|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 91, False: 0]
  |  |  ------------------
  |  |  156|     91|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 0, False: 91]
  |  |  ------------------
  |  |  157|     91|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     91|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     91|	return _ret; \
  |  |  163|     91|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  322|     91|}
card-rtecp.c:set_acl_from_sec_attr:
  167|     91|{
  168|     91|	unsigned int method;
  169|     91|	unsigned long key_ref;
  170|       |
  171|     91|	if (!card || !card->ctx || !file || !file->sec_attr
  ------------------
  |  Branch (171:6): [True: 0, False: 91]
  |  Branch (171:15): [True: 0, False: 91]
  |  Branch (171:29): [True: 0, False: 91]
  |  Branch (171:38): [True: 0, False: 91]
  ------------------
  172|     91|		|| file->sec_attr_len != SC_RTECP_SEC_ATTR_SIZE
  ------------------
  |  |  779|    182|#define SC_RTECP_SEC_ATTR_SIZE 15
  ------------------
  |  Branch (172:6): [True: 0, False: 91]
  ------------------
  173|      0|		|| 1 + 6 >= SC_RTECP_SEC_ATTR_SIZE)
  ------------------
  |  |  779|      0|#define SC_RTECP_SEC_ATTR_SIZE 15
  ------------------
  |  Branch (173:6): [Folded, False: 0]
  ------------------
  174|      0|	{
  175|      0|		return;
  176|      0|	}
  177|       |
  178|     91|	sc_file_add_acl_entry(file, SC_AC_OP_SELECT, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  166|     91|#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|     91|#define SC_AC_NONE			0x00000000
  ------------------
              	sc_file_add_acl_entry(file, SC_AC_OP_SELECT, SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|     91|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  179|     91|	if (file->sec_attr[0] & 0x40) /* if AccessMode.6 */
  ------------------
  |  Branch (179:6): [True: 46, False: 45]
  ------------------
  180|     46|	{
  181|     46|		method = sec_attr_to_method(file->sec_attr[1 + 6]);
  182|     46|		key_ref = sec_attr_to_key_ref(file->sec_attr[1 + 6]);
  183|     46|		sc_log(card->ctx,
  ------------------
  |  |   71|     46|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  184|     46|			"SC_AC_OP_DELETE %i %lu\n",
  185|     46|			(int)method, key_ref);
  186|     46|		sc_file_add_acl_entry(file, SC_AC_OP_DELETE, method, key_ref);
  ------------------
  |  |  168|     46|#define SC_AC_OP_DELETE			2
  ------------------
  187|     46|	}
  188|     91|	if (file->sec_attr[0] & 0x01) /* if AccessMode.0 */
  ------------------
  |  Branch (188:6): [True: 61, False: 30]
  ------------------
  189|     61|	{
  190|     61|		method = sec_attr_to_method(file->sec_attr[1 + 0]);
  191|     61|		key_ref = sec_attr_to_key_ref(file->sec_attr[1 + 0]);
  192|     61|		sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  |  |  |  Branch (71:110): [True: 5, False: 56]
  |  |  ------------------
  ------------------
  193|     61|			(file->type == SC_FILE_TYPE_DF) ?
  194|     61|				"SC_AC_OP_CREATE %i %lu\n"
  195|     61|				: "SC_AC_OP_READ %i %lu\n",
  196|     61|			(int)method, key_ref);
  197|     61|		sc_file_add_acl_entry(file, (file->type == SC_FILE_TYPE_DF) ?
  ------------------
  |  |  214|     61|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (197:31): [True: 5, False: 56]
  ------------------
  198|     56|				SC_AC_OP_CREATE : SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  169|      5|#define SC_AC_OP_CREATE			3
  ------------------
              				SC_AC_OP_CREATE : SC_AC_OP_READ, method, key_ref);
  ------------------
  |  |  188|    117|#define SC_AC_OP_READ			22
  ------------------
  199|     61|	}
  200|     91|	if (file->type == SC_FILE_TYPE_DF)
  ------------------
  |  |  214|     91|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (200:6): [True: 6, False: 85]
  ------------------
  201|      6|	{
  202|      6|		sc_file_add_acl_entry(file, SC_AC_OP_LIST_FILES,
  ------------------
  |  |  172|      6|#define SC_AC_OP_LIST_FILES		6
  ------------------
  203|      6|				SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  150|      6|#define SC_AC_NONE			0x00000000
  ------------------
              				SC_AC_NONE, SC_AC_KEY_REF_NONE);
  ------------------
  |  |  204|      6|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  204|      6|	}
  205|     85|	else
  206|     85|		if (file->sec_attr[0] & 0x02) /* if AccessMode.1 */
  ------------------
  |  Branch (206:7): [True: 41, False: 44]
  ------------------
  207|     41|		{
  208|     41|			method = sec_attr_to_method(file->sec_attr[1 + 1]);
  209|     41|			key_ref = sec_attr_to_key_ref(file->sec_attr[1 + 1]);
  210|     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__
  |  |  ------------------
  ------------------
  211|     41|				"SC_AC_OP_UPDATE %i %lu\n",
  212|     41|				(int)method, key_ref);
  213|     41|			sc_file_add_acl_entry(file, SC_AC_OP_UPDATE, method, key_ref);
  ------------------
  |  |  189|     41|#define SC_AC_OP_UPDATE			23
  ------------------
  214|     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__
  |  |  ------------------
  ------------------
  215|     41|				"SC_AC_OP_WRITE %i %lu\n",
  216|     41|				(int)method, key_ref);
  217|     41|			sc_file_add_acl_entry(file, SC_AC_OP_WRITE, method, key_ref);
  ------------------
  |  |  190|     41|#define SC_AC_OP_WRITE			24
  ------------------
  218|     41|		}
  219|     91|}
card-rtecp.c:sec_attr_to_method:
  139|    148|{
  140|    148|	if (attr == 0xFF)
  ------------------
  |  Branch (140:6): [True: 30, False: 118]
  ------------------
  141|     30|		return SC_AC_NEVER;
  ------------------
  |  |  163|     30|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  142|    118|	else if (attr == 0)
  ------------------
  |  Branch (142:11): [True: 32, False: 86]
  ------------------
  143|     32|		return SC_AC_NONE;
  ------------------
  |  |  150|     32|#define SC_AC_NONE			0x00000000
  ------------------
  144|     86|	else if (attr & 0x03)
  ------------------
  |  Branch (144:11): [True: 55, False: 31]
  ------------------
  145|     55|		return SC_AC_CHV;
  ------------------
  |  |  151|     55|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  146|     31|	else
  147|     31|		return SC_AC_UNKNOWN;
  ------------------
  |  |  162|     31|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  148|    148|}
card-rtecp.c:sec_attr_to_key_ref:
  151|    148|{
  152|    148|	if (attr == 1 || attr == 2)
  ------------------
  |  Branch (152:6): [True: 13, False: 135]
  |  Branch (152:19): [True: 13, False: 122]
  ------------------
  153|     26|		return attr;
  154|    122|	return 0;
  155|    148|}
card-rtecp.c:rtecp_card_ctl:
  705|     12|{
  706|     12|	sc_apdu_t apdu;
  707|     12|	u8 buf[512];
  708|     12|	sc_rtecp_genkey_data_t *genkey_data = data;
  709|     12|	sc_serial_number_t *serial = data;
  710|     12|	int r;
  711|       |
  712|     12|	const unsigned char rsa_prop[] = {0xA6, 0x06, 0x94, 0x04, 0x01, 0x00, 0x01, 0x00};
  713|       |
  714|     12|	if (!card || !card->ctx)
  ------------------
  |  Branch (714:6): [True: 0, False: 12]
  |  Branch (714:15): [True: 0, False: 12]
  ------------------
  715|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  716|       |
  717|     12|	switch (request)
  718|     12|	{
  719|      0|	case SC_CARDCTL_RTECP_INIT:
  ------------------
  |  Branch (719:2): [True: 0, False: 12]
  ------------------
  720|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x8A, 0, 0);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  721|      0|		apdu.cla = 0x80;
  722|      0|		break;
  723|      0|	case SC_CARDCTL_RTECP_INIT_END:
  ------------------
  |  Branch (723:2): [True: 0, False: 12]
  ------------------
  724|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x84, 0x4E, 0x19);
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
  725|      0|		apdu.cla = 0x80;
  726|      0|		break;
  727|     12|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (727:2): [True: 12, False: 0]
  ------------------
  728|     12|		if (!serial)
  ------------------
  |  Branch (728:7): [True: 0, False: 12]
  ------------------
  729|     12|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  730|     12|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0x01, 0x81);
  ------------------
  |  |  292|     12|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  731|     12|		apdu.resp = buf;
  732|     12|		apdu.resplen = sizeof(buf);
  733|     12|		apdu.le = 256;
  734|     12|		serial->len = sizeof(serial->value);
  735|     12|		break;
  736|      0|	case SC_CARDCTL_RTECP_GENERATE_KEY:
  ------------------
  |  Branch (736:2): [True: 0, False: 12]
  ------------------
  737|      0|		if (!genkey_data)
  ------------------
  |  Branch (737:7): [True: 0, False: 0]
  ------------------
  738|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  739|      0|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x46, 0x80,
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  740|      0|				genkey_data->key_id);
  741|      0|		apdu.resp = buf;
  742|      0|		apdu.resplen = sizeof(buf);
  743|      0|		apdu.le = 256;
  744|      0|		if (genkey_data->type == SC_ALGORITHM_RSA) {
  ------------------
  |  |   78|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (744:7): [True: 0, False: 0]
  ------------------
  745|      0|			apdu.cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|      0|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  746|      0|			apdu.data = rsa_prop;
  747|      0|			apdu.datalen = sizeof(rsa_prop);
  748|      0|			apdu.lc = sizeof(rsa_prop);
  749|      0|		}
  750|      0|		break;
  751|      0|	case SC_CARDCTL_LIFECYCLE_SET:
  ------------------
  |  Branch (751:2): [True: 0, False: 12]
  ------------------
  752|      0|		sc_log(card->ctx,  "%s\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__
  |  |  ------------------
  ------------------
  753|      0|				"SC_CARDCTL_LIFECYCLE_SET not supported");
  754|       |		/* no call sc_debug (SC_FUNC_RETURN) */
  755|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  756|      0|	default:
  ------------------
  |  Branch (756:2): [True: 0, False: 12]
  ------------------
  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|			"request = 0x%lx\n", request);
  759|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  760|     12|	}
  761|     12|	r = sc_transmit_apdu(card, &apdu);
  762|     12|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 11]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 11]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  763|     11|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  764|     11|	if (!r && request == SC_CARDCTL_RTECP_GENERATE_KEY)
  ------------------
  |  Branch (764:6): [True: 8, False: 3]
  |  Branch (764:12): [True: 0, False: 8]
  ------------------
  765|      0|	{
  766|      0|		if (genkey_data->type == SC_ALGORITHM_RSA &&
  ------------------
  |  |   78|      0|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (766:7): [True: 0, False: 0]
  ------------------
  767|      0|				genkey_data->u.rsa.modulus_len >= apdu.resplen &&
  ------------------
  |  Branch (767:5): [True: 0, False: 0]
  ------------------
  768|      0|				genkey_data->u.rsa.exponent_len >= 3)
  ------------------
  |  Branch (768:5): [True: 0, False: 0]
  ------------------
  769|      0|		{
  770|      0|			memcpy(genkey_data->u.rsa.modulus, apdu.resp, apdu.resplen);
  771|      0|			genkey_data->u.rsa.modulus_len = apdu.resplen;
  772|      0|			reverse(genkey_data->u.rsa.modulus,
  773|      0|					genkey_data->u.rsa.modulus_len);
  774|      0|			memcpy(genkey_data->u.rsa.exponent, "\x01\x00\x01", 3);
  775|      0|			genkey_data->u.rsa.exponent_len = 3;
  776|      0|		}
  777|      0|		else if (genkey_data->type == SC_ALGORITHM_GOSTR3410 &&
  ------------------
  |  |   80|      0|#define SC_ALGORITHM_GOSTR3410		3
  ------------------
  |  Branch (777:12): [True: 0, False: 0]
  ------------------
  778|      0|				genkey_data->u.gostr3410.xy_len >= apdu.resplen)
  ------------------
  |  Branch (778:5): [True: 0, False: 0]
  ------------------
  779|      0|		{
  780|      0|			memcpy(genkey_data->u.gostr3410.xy, apdu.resp, apdu.resplen);
  781|      0|			genkey_data->u.gostr3410.xy_len = apdu.resplen;
  782|      0|		}
  783|      0|		else
  784|      0|			r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  785|      0|	}
  786|     11|	else if (!r && request == SC_CARDCTL_GET_SERIALNR)
  ------------------
  |  Branch (786:11): [True: 8, False: 3]
  |  Branch (786:17): [True: 8, False: 0]
  ------------------
  787|      8|	{
  788|      8|		if (apdu.resplen <= sizeof(serial->value))
  ------------------
  |  Branch (788:7): [True: 7, False: 1]
  ------------------
  789|      7|		{
  790|      7|			memcpy(serial->value, apdu.resp, apdu.resplen);
  791|      7|			serial->len = apdu.resplen;
  792|      7|		}
  793|      1|		else
  794|      1|			r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      1|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  795|      8|	}
  796|     11|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|     11|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     11|	int _ret = r; \
  |  |  155|     11|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 11, False: 0]
  |  |  ------------------
  |  |  156|     11|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4, False: 7]
  |  |  ------------------
  |  |  157|     11|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     11|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     11|	return _ret; \
  |  |  163|     11|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  797|     11|}

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

sc_get_sc_hsm_driver:
 1980|  15.3k|{
 1981|  15.3k|	return sc_get_driver();
 1982|  15.3k|}
card-sc-hsm.c:sc_get_driver:
 1944|  15.3k|{
 1945|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1946|       |
 1947|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1947:6): [True: 1, False: 15.3k]
  ------------------
 1948|      1|		iso_ops = iso_drv->ops;
 1949|       |
 1950|  15.3k|	sc_hsm_ops                   = *iso_drv->ops;
 1951|  15.3k|	sc_hsm_ops.match_card        = sc_hsm_match_card;
 1952|  15.3k|	sc_hsm_ops.select_file       = sc_hsm_select_file;
 1953|  15.3k|	sc_hsm_ops.get_challenge     = sc_hsm_get_challenge;
 1954|  15.3k|	sc_hsm_ops.read_binary       = sc_hsm_read_binary;
 1955|  15.3k|	sc_hsm_ops.update_binary     = sc_hsm_update_binary;
 1956|  15.3k|	sc_hsm_ops.list_files        = sc_hsm_list_files;
 1957|  15.3k|	sc_hsm_ops.create_file       = sc_hsm_create_file;
 1958|  15.3k|	sc_hsm_ops.delete_file       = sc_hsm_delete_file;
 1959|  15.3k|	sc_hsm_ops.set_security_env  = sc_hsm_set_security_env;
 1960|  15.3k|	sc_hsm_ops.compute_signature = sc_hsm_compute_signature;
 1961|  15.3k|	sc_hsm_ops.decipher          = sc_hsm_decipher;
 1962|  15.3k|	sc_hsm_ops.init              = sc_hsm_init;
 1963|  15.3k|	sc_hsm_ops.finish            = sc_hsm_finish;
 1964|  15.3k|	sc_hsm_ops.card_ctl          = sc_hsm_card_ctl;
 1965|  15.3k|	sc_hsm_ops.pin_cmd           = sc_hsm_pin_cmd;
 1966|  15.3k|	sc_hsm_ops.logout            = sc_hsm_logout;
 1967|       |
 1968|       |	/* no record oriented file services */
 1969|  15.3k|	sc_hsm_ops.read_record       = NULL;
 1970|  15.3k|	sc_hsm_ops.write_record      = NULL;
 1971|  15.3k|	sc_hsm_ops.append_record     = NULL;
 1972|  15.3k|	sc_hsm_ops.update_record     = NULL;
 1973|       |
 1974|  15.3k|	return &sc_hsm_drv;
 1975|  15.3k|}
card-sc-hsm.c:sc_hsm_match_card:
  266|  5.51k|{
  267|  5.51k|	sc_path_t path;
  268|  5.51k|	int i, r, type = 0;
  269|  5.51k|	sc_file_t *file = NULL;
  270|       |
  271|  5.51k|	i = _sc_match_atr(card, sc_hsm_atrs, &type);
  272|  5.51k|	if (i >= 0 && type != SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (272:6): [True: 237, False: 5.28k]
  |  Branch (272:16): [True: 236, False: 1]
  ------------------
  273|    236|		card->type = type;
  274|    236|		return 1;
  275|    236|	}
  276|       |
  277|  5.28k|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|  5.28k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  278|  5.28k|	r = sc_hsm_select_file(card, &path, &file);
  279|  5.28k|	LOG_TEST_RET(card->ctx, r, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  5.28k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  5.28k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  5.28k|	int _ret = (r); \
  |  |  |  |  168|  5.28k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.02k, False: 262]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.02k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.02k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.02k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.02k|		return _ret; \
  |  |  |  |  172|  5.02k|	} \
  |  |  |  |  173|  5.28k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 262]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|       |
  281|       |	// Validate that card returns a FCP with a proprietary tag 85 with value longer than 2 byte (Fixes #1377)
  282|    262|	if (file != NULL) {
  ------------------
  |  Branch (282:6): [True: 262, False: 0]
  ------------------
  283|    262|		size_t sz = file->prop_attr_len;
  284|    262|		sc_file_free(file);
  285|    262|		if (sz < 2) {
  ------------------
  |  Branch (285:7): [True: 261, False: 1]
  ------------------
  286|    261|			return 0;
  287|    261|		}
  288|    262|	}
  289|       |
  290|      1|	if (type == SC_CARD_TYPE_SC_HSM_SOC) {
  ------------------
  |  Branch (290:6): [True: 0, False: 1]
  ------------------
  291|      0|		card->type = SC_CARD_TYPE_SC_HSM_SOC;
  292|      1|	} else {
  293|      1|		card->type = SC_CARD_TYPE_SC_HSM;
  294|      1|	}
  295|       |
  296|      1|	return 1;
  297|    262|}
card-sc-hsm.c:sc_hsm_select_file:
  246|  7.37k|{
  247|  7.37k|	return sc_hsm_select_file_ex(card, in_path, 0, file_out);
  248|  7.37k|}
card-sc-hsm.c:sc_hsm_select_file_ex:
  148|  8.79k|{
  149|  8.79k|	int rv;
  150|  8.79k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  151|  8.79k|	sc_file_t *file = NULL;
  152|  8.79k|	sc_path_t cpath;
  153|  8.79k|	size_t card_max_recv_size = card->max_recv_size;
  154|  8.79k|	size_t reader_max_recv_size = card->reader->max_recv_size;
  155|       |
  156|  8.79k|	if (file_out == NULL) {				// Versions before 0.16 of the SmartCard-HSM do not support P2='0C'
  ------------------
  |  Branch (156:6): [True: 1.19k, False: 7.60k]
  ------------------
  157|  1.19k|		rv = sc_hsm_select_file_ex(card, in_path, forceselect, &file);
  158|  1.19k|		sc_file_free(file);
  159|  1.19k|		return rv;
  160|  1.19k|	}
  161|       |
  162|  7.60k|	if ((in_path->type == SC_PATH_TYPE_FILE_ID) && in_path->aid.len) {
  ------------------
  |  |  117|  7.60k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (162:6): [True: 85, False: 7.52k]
  |  Branch (162:49): [True: 0, False: 85]
  ------------------
  163|       |		// Split applet selection and file selection into two separate calls
  164|      0|		cpath = *in_path;
  165|      0|		cpath.len = 0;
  166|      0|		cpath.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  167|      0|		rv = sc_hsm_select_file_ex(card, &cpath, forceselect, NULL);
  168|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  169|       |
  170|      0|		if (in_path->len) {
  ------------------
  |  Branch (170:7): [True: 0, False: 0]
  ------------------
  171|      0|			cpath = *in_path;
  172|      0|			cpath.aid.len = 0;
  173|      0|			rv = sc_hsm_select_file_ex(card, &cpath, forceselect, file_out);
  174|      0|		}
  175|      0|		return rv;
  176|      0|	}
  177|       |
  178|       |	// Prevent selection of applet unless this is the first time, selection is forced or the device is not authenticated
  179|  7.60k|	if (in_path->type == SC_PATH_TYPE_DF_NAME
  ------------------
  |  |  118|  15.2k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (179:6): [True: 6.31k, False: 1.29k]
  ------------------
  180|  1.29k|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  2.58k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (180:8): [True: 1.20k, False: 85]
  ------------------
  181|  1.20k|				&& in_path->len == sc_hsm_aid.len
  ------------------
  |  Branch (181:8): [True: 0, False: 1.20k]
  ------------------
  182|      0|				&& !memcmp(in_path->value, sc_hsm_aid.value, sc_hsm_aid.len))
  ------------------
  |  Branch (182:8): [True: 0, False: 0]
  ------------------
  183|  1.29k|			|| (in_path->type == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|  2.58k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (183:8): [True: 1.20k, False: 85]
  ------------------
  184|  1.20k|				&& in_path->len == 0
  ------------------
  |  Branch (184:8): [True: 0, False: 1.20k]
  ------------------
  185|      0|				&& in_path->aid.len == sc_hsm_aid.len
  ------------------
  |  Branch (185:8): [True: 0, False: 0]
  ------------------
  186|  6.31k|				&& !memcmp(in_path->aid.value, sc_hsm_aid.value, sc_hsm_aid.len))) {
  ------------------
  |  Branch (186:8): [True: 0, False: 0]
  ------------------
  187|  6.31k|		if (!priv || (priv->dffcp == NULL) || forceselect) {
  ------------------
  |  Branch (187:7): [True: 5.28k, False: 1.03k]
  |  Branch (187:16): [True: 782, False: 253]
  |  Branch (187:41): [True: 0, False: 253]
  ------------------
  188|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  189|  6.06k|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  391|  6.06k|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  190|  6.06k|			rv = (*iso_ops->select_file)(card, in_path, file_out);
  191|  6.06k|			card->max_recv_size = card_max_recv_size;
  192|  6.06k|			card->reader->max_recv_size = reader_max_recv_size;
  193|  6.06k|			LOG_TEST_RET(card->ctx, rv, "Could not select SmartCard-HSM application");
  ------------------
  |  |  174|  6.06k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.06k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.06k|	int _ret = (r); \
  |  |  |  |  168|  6.06k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5.58k, False: 478]
  |  |  |  |  ------------------
  |  |  |  |  169|  5.58k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  5.58k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  5.58k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  5.58k|		return _ret; \
  |  |  |  |  172|  5.58k|	} \
  |  |  |  |  173|  6.06k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 478]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  194|       |
  195|    478|			if (priv) {
  ------------------
  |  Branch (195:8): [True: 216, False: 262]
  ------------------
  196|    216|				sc_file_free(priv->dffcp);
  197|       |				// Cache the FCP returned when selecting the applet
  198|    216|				sc_file_dup(&priv->dffcp, *file_out);
  199|    216|			}
  200|    478|		} else {
  201|    253|			sc_file_dup(file_out, priv->dffcp);
  202|    253|			rv = SC_SUCCESS;
  ------------------
  |  |   28|    253|#define SC_SUCCESS				0
  ------------------
  203|    253|		}
  204|    731|		return rv;
  205|  6.31k|	}
  206|       |
  207|  1.29k|	if ((in_path->len >= 2) && (in_path->value[0] == 0x3F) && (in_path->value[1] == 0x00)) {
  ------------------
  |  Branch (207:6): [True: 1.29k, False: 0]
  |  Branch (207:29): [True: 709, False: 581]
  |  Branch (207:60): [True: 709, False: 0]
  ------------------
  208|       |		// The SmartCard-HSM is an applet that is not default selected. Simulate selection of the MF
  209|    709|		if (in_path->len == 2) {
  ------------------
  |  Branch (209:7): [True: 0, False: 709]
  ------------------
  210|      0|			file = sc_file_new();
  211|      0|			if (file == NULL)
  ------------------
  |  Branch (211:8): [True: 0, False: 0]
  ------------------
  212|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|      0|			file->path = *in_path;
  214|      0|			file->id = 0x3F00;
  215|      0|			file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|      0|#define SC_FILE_TYPE_DF			0x04
  ------------------
  216|      0|			file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|      0|#define SC_FILE_MAGIC			0x14426950
  ------------------
  217|       |
  218|      0|			*file_out = file;
  219|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  220|    709|		} else {
  221|       |			/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  222|    709|			card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  391|    709|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  223|    709|			sc_path_t truncated;
  224|    709|			memcpy(&truncated, in_path, sizeof truncated);
  225|    709|			truncated.len = in_path->len - 2;
  226|    709|			memcpy(truncated.value, in_path->value+2, truncated.len);
  227|    709|			rv = (*iso_ops->select_file)(card, &truncated, file_out);
  228|    709|			card->max_recv_size = card_max_recv_size;
  229|    709|			card->reader->max_recv_size = reader_max_recv_size;
  230|    709|			return rv;
  231|    709|		}
  232|    709|	}
  233|       |	/* Force use of Le = 0x00 in iso7816_select_file as required by SC-HSM */
  234|    581|	card->max_recv_size = card->reader->max_recv_size = SC_READER_SHORT_APDU_MAX_RECV_SIZE;
  ------------------
  |  |  391|    581|#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
  ------------------
  235|    581|	rv = (*iso_ops->select_file)(card, in_path, file_out);
  236|    581|	card->max_recv_size = card_max_recv_size;
  237|    581|	card->reader->max_recv_size = reader_max_recv_size;
  238|    581|	return rv;
  239|  1.29k|}
card-sc-hsm.c:sc_hsm_read_binary:
  799|    401|{
  800|    401|	sc_context_t *ctx = card->ctx;
  801|    401|	sc_apdu_t apdu;
  802|    401|	u8 cmdbuff[4];
  803|    401|	int r;
  804|       |
  805|    401|	if (idx > 0xffff) {
  ------------------
  |  Branch (805:6): [True: 0, False: 401]
  ------------------
  806|      0|		sc_log(ctx,  "invalid EF offset: 0x%X > 0xFFFF", idx);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  807|      0|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  808|      0|	}
  809|       |
  810|    401|	cmdbuff[0] = 0x54;
  811|    401|	cmdbuff[1] = 0x02;
  812|    401|	cmdbuff[2] = (idx >> 8) & 0xFF;
  813|    401|	cmdbuff[3] = idx & 0xFF;
  814|       |
  815|    401|	if (count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (815:6): [True: 0, False: 401]
  ------------------
  816|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  817|    401|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB1, 0x00, 0x00);
  ------------------
  |  |  303|    401|#define SC_APDU_CASE_4			0x24
  ------------------
  818|    401|	apdu.data = cmdbuff;
  819|    401|	apdu.datalen = 4;
  820|    401|	apdu.lc = 4;
  821|    401|	apdu.le = count;
  822|    401|	apdu.resplen = count;
  823|    401|	apdu.resp = buf;
  824|       |
  825|    401|	r = sc_transmit_apdu(card, &apdu);
  826|    401|	LOG_TEST_RET(ctx, r, "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: 3, False: 398]
  |  |  |  |  ------------------
  |  |  |  |  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|    401|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 398]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|       |
  828|    398|	r =  sc_check_sw(card, apdu.sw1, apdu.sw2);
  829|    398|	if (r != SC_ERROR_FILE_END_REACHED) {
  ------------------
  |  |   69|    398|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (829:6): [True: 313, False: 85]
  ------------------
  830|    313|		LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|    313|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    313|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    313|	int _ret = (r); \
  |  |  |  |  168|    313|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 61, False: 252]
  |  |  |  |  ------------------
  |  |  |  |  169|     61|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     61|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     61|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     61|		return _ret; \
  |  |  |  |  172|     61|	} \
  |  |  |  |  173|    313|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 252]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  831|    313|	}
  832|       |
  833|    337|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|    337|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    337|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    337|	int _ret = r; \
  |  |  |  |  155|    337|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 11, False: 326]
  |  |  |  |  ------------------
  |  |  |  |  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|    326|	} else { \
  |  |  |  |  159|    326|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    326|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    326|	} \
  |  |  |  |  162|    337|	return _ret; \
  |  |  |  |  163|    337|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  834|    337|}
card-sc-hsm.c:sc_hsm_set_security_env:
 1004|  1.67k|{
 1005|  1.67k|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1006|       |
 1007|  1.67k|	priv->env = env;
 1008|       |
 1009|  1.67k|	switch(env->algorithm) {
 1010|  1.67k|	case SC_ALGORITHM_RSA:
  ------------------
  |  |   78|  1.67k|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (1010:2): [True: 1.67k, False: 0]
  ------------------
 1011|  1.67k|		if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PKCS1) {
  ------------------
  |  |  120|  1.67k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  1.67k|#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) */
  |  |  ------------------
  |  |  |  |  119|  1.67k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  |  Branch (1011:7): [True: 0, False: 1.67k]
  ------------------
 1012|      0|			if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA1) {
  ------------------
  |  |  143|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  |  Branch (1012:8): [True: 0, False: 0]
  ------------------
 1013|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA1;
  ------------------
  |  |   41|      0|#define ALGO_RSA_PKCS1_SHA1		0x31		/* RSA signature with SHA-1 hash and PKCS#1 V1.5 padding */
  ------------------
 1014|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA256) {
  ------------------
  |  |  147|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  ------------------
  |  Branch (1014:15): [True: 0, False: 0]
  ------------------
 1015|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA256;
  ------------------
  |  |   42|      0|#define ALGO_RSA_PKCS1_SHA256	0x33		/* RSA signature with SHA-256 hash and PKCS#1 V1.5 padding */
  ------------------
 1016|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA384) {
  ------------------
  |  |  148|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  ------------------
  |  Branch (1016:15): [True: 0, False: 0]
  ------------------
 1017|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA384;
  ------------------
  |  |   43|      0|#define ALGO_RSA_PKCS1_SHA384	0x34		/* RSA signature with SHA-384 hash and PKCS#1 V1.5 padding */
  ------------------
 1018|      0|			} else if (env->algorithm_flags & SC_ALGORITHM_RSA_HASH_SHA512) {
  ------------------
  |  |  149|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
  |  Branch (1018:15): [True: 0, False: 0]
  ------------------
 1019|      0|				priv->algorithm = ALGO_RSA_PKCS1_SHA512;
  ------------------
  |  |   44|      0|#define ALGO_RSA_PKCS1_SHA512	0x35		/* RSA signature with SHA-512 hash and PKCS#1 V1.5 padding */
  ------------------
 1020|      0|			} else {
 1021|      0|				priv->algorithm = ALGO_RSA_PKCS1;
  ------------------
  |  |   40|      0|#define ALGO_RSA_PKCS1			0x30		/* RSA signature with DigestInfo input and PKCS#1 V1.5 padding */
  ------------------
 1022|      0|			}
 1023|  1.67k|		} else if (env->algorithm_flags & SC_ALGORITHM_RSA_PAD_PSS) {
  ------------------
  |  |  116|  1.67k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
  |  Branch (1023:14): [True: 710, False: 968]
  ------------------
 1024|    710|			if ((env->algorithm_flags & SC_ALGORITHM_RSA_HASHES) &&
  ------------------
  |  |  151|    710|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1024:8): [True: 0, False: 710]
  ------------------
 1025|      0|					(((env->algorithm_flags & SC_ALGORITHM_MGF1_HASHES) >> 8) != (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES))) {
  ------------------
  |  |  159|      0|#define SC_ALGORITHM_MGF1_HASHES	0x01F00000
  ------------------
              					(((env->algorithm_flags & SC_ALGORITHM_MGF1_HASHES) >> 8) != (env->algorithm_flags & SC_ALGORITHM_RSA_HASHES))) {
  ------------------
  |  |  151|      0|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  |  Branch (1025:6): [True: 0, False: 0]
  ------------------
 1026|      0|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1027|      0|			}
 1028|    710|			priv->algorithm = ALGO_RSA_PSS;
  ------------------
  |  |   46|    710|#define ALGO_RSA_PSS			0x40		/* RSA signature with external hash and PKCS#1 PSS padding*/
  ------------------
 1029|    968|		} else {
 1030|    968|			if (env->operation == SC_SEC_OPERATION_DECIPHER) {
  ------------------
  |  |   56|    968|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (1030:8): [True: 258, False: 710]
  ------------------
 1031|    258|				priv->algorithm = ALGO_RSA_DECRYPT;
  ------------------
  |  |   39|    258|#define ALGO_RSA_DECRYPT		0x21		/* RSA decrypt */
  ------------------
 1032|    710|			} else {
 1033|    710|				priv->algorithm = ALGO_RSA_RAW;
  ------------------
  |  |   38|    710|#define ALGO_RSA_RAW			0x20		/* RSA signature with external padding */
  ------------------
 1034|    710|			}
 1035|    968|		}
 1036|  1.67k|		break;
 1037|  1.67k|	case SC_ALGORITHM_EC:
  ------------------
  |  |   79|      0|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1037:2): [True: 0, False: 1.67k]
  ------------------
 1038|      0|		if (env->operation == SC_SEC_OPERATION_DERIVE) {
  ------------------
  |  |   59|      0|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (1038:7): [True: 0, False: 0]
  ------------------
 1039|      0|			priv->algorithm = ALGO_EC_DH;
  ------------------
  |  |   58|      0|#define ALGO_EC_DH				0x80		/* ECDH key derivation */
  ------------------
 1040|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_NONE) {
  ------------------
  |  |  184|      0|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|      0|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
  |  Branch (1040:14): [True: 0, False: 0]
  ------------------
 1041|      0|			priv->algorithm = ALGO_EC_RAW;
  ------------------
  |  |   52|      0|#define ALGO_EC_RAW				0x70		/* ECDSA signature with hash input */
  ------------------
 1042|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA1) {
  ------------------
  |  |  185|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  143|      0|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  |  Branch (1042:14): [True: 0, False: 0]
  ------------------
 1043|      0|			priv->algorithm = ALGO_EC_SHA1;
  ------------------
  |  |   53|      0|#define ALGO_EC_SHA1			0x71		/* ECDSA signature with SHA-1 hash */
  ------------------
 1044|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA224) {
  ------------------
  |  |  186|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  150|      0|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
  |  Branch (1044:14): [True: 0, False: 0]
  ------------------
 1045|      0|			priv->algorithm = ALGO_EC_SHA224;
  ------------------
  |  |   54|      0|#define ALGO_EC_SHA224			0x72		/* ECDSA signature with SHA-224 hash */
  ------------------
 1046|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA256) {
  ------------------
  |  |  187|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  147|      0|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  |  Branch (1046:14): [True: 0, False: 0]
  ------------------
 1047|      0|			priv->algorithm = ALGO_EC_SHA256;
  ------------------
  |  |   55|      0|#define ALGO_EC_SHA256			0x73		/* ECDSA signature with SHA-256 hash */
  ------------------
 1048|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA384) {
  ------------------
  |  |  188|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  148|      0|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
  |  Branch (1048:14): [True: 0, False: 0]
  ------------------
 1049|      0|			priv->algorithm = ALGO_EC_SHA384;
  ------------------
  |  |   56|      0|#define ALGO_EC_SHA384			0x74		/* ECDSA signature with SHA-384 hash */
  ------------------
 1050|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_HASH_SHA512) {
  ------------------
  |  |  189|      0|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  149|      0|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
  |  Branch (1050:14): [True: 0, False: 0]
  ------------------
 1051|      0|			priv->algorithm = ALGO_EC_SHA512;
  ------------------
  |  |   57|      0|#define ALGO_EC_SHA512			0x75		/* ECDSA signature with SHA-512 hash */
  ------------------
 1052|      0|		} else if (env->algorithm_flags & SC_ALGORITHM_ECDSA_RAW) {
  ------------------
  |  |  183|      0|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
  |  Branch (1052:14): [True: 0, False: 0]
  ------------------
 1053|      0|			priv->algorithm = ALGO_EC_RAW;
  ------------------
  |  |   52|      0|#define ALGO_EC_RAW				0x70		/* ECDSA signature with hash input */
  ------------------
 1054|      0|		} else {
 1055|      0|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1056|      0|		}
 1057|      0|		break;
 1058|      0|	default:
  ------------------
  |  Branch (1058:2): [True: 0, False: 1.67k]
  ------------------
 1059|      0|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1060|      0|		break;
 1061|  1.67k|	}
 1062|  1.67k|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1063|  1.67k|}
card-sc-hsm.c:sc_hsm_compute_signature:
 1088|  1.42k|{
 1089|  1.42k|	int r;
 1090|  1.42k|	sc_apdu_t apdu;
 1091|  1.42k|	u8 rbuf[514];
 1092|  1.42k|	sc_hsm_private_data_t *priv;
 1093|       |
 1094|  1.42k|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1094:6): [True: 0, False: 1.42k]
  |  Branch (1094:22): [True: 0, False: 1.42k]
  |  Branch (1094:38): [True: 0, False: 1.42k]
  ------------------
 1095|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1096|      0|	}
 1097|  1.42k|	priv = (sc_hsm_private_data_t *) card->drv_data;
 1098|       |
 1099|  1.42k|	if (priv->env == NULL) {
  ------------------
  |  Branch (1099:6): [True: 0, False: 1.42k]
  ------------------
 1100|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|      0|	}
 1102|       |
 1103|  1.42k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_EXT, 0x68, priv->env->key_ref[0], priv->algorithm);
  ------------------
  |  |  299|  1.42k|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|  1.42k|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|  1.42k|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1104|  1.42k|	apdu.cla = 0x80;
 1105|  1.42k|	apdu.resp = rbuf;
 1106|  1.42k|	apdu.resplen = sizeof(rbuf);
 1107|  1.42k|	apdu.le = 512;
 1108|       |
 1109|  1.42k|	apdu.data = data;
 1110|  1.42k|	apdu.lc = datalen;
 1111|  1.42k|	apdu.datalen = datalen;
 1112|  1.42k|	r = sc_transmit_apdu(card, &apdu);
 1113|       |
 1114|  1.42k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  1.42k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.42k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.42k|	int _ret = (r); \
  |  |  |  |  168|  1.42k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 157, False: 1.26k]
  |  |  |  |  ------------------
  |  |  |  |  169|    157|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    157|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    157|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    157|		return _ret; \
  |  |  |  |  172|    157|	} \
  |  |  |  |  173|  1.42k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.26k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1115|  1.26k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1115:6): [True: 165, False: 1.09k]
  |  Branch (1115:26): [True: 125, False: 40]
  ------------------
 1116|    125|		int len;
 1117|       |
 1118|    125|		if ((priv->algorithm & 0xF0) == ALGO_EC_RAW) {
  ------------------
  |  |   52|    125|#define ALGO_EC_RAW				0x70		/* ECDSA signature with hash input */
  ------------------
  |  Branch (1118:7): [True: 0, False: 125]
  ------------------
 1119|      0|			len = sc_hsm_decode_ecdsa_signature(card, apdu.resp, apdu.resplen, out, outlen, priv->env->key_size_bits);
 1120|      0|			if (len < 0) {
  ------------------
  |  Branch (1120:8): [True: 0, False: 0]
  ------------------
 1121|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1122|      0|			}
 1123|    125|		} else {
 1124|    125|			len = (int)(apdu.resplen > outlen ? outlen : apdu.resplen);
  ------------------
  |  Branch (1124:16): [True: 0, False: 125]
  ------------------
 1125|    125|			memcpy(out, apdu.resp, len);
 1126|    125|		}
 1127|    125|		LOG_FUNC_RETURN(card->ctx, len);
  ------------------
  |  |  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: 50, False: 75]
  |  |  |  |  ------------------
  |  |  |  |  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|     75|	} else { \
  |  |  |  |  159|     75|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     75|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     75|	} \
  |  |  |  |  162|    125|	return _ret; \
  |  |  |  |  163|    125|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1128|    125|	}
 1129|  1.13k|	LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  1.13k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.13k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.13k|	int _ret = r; \
  |  |  |  |  155|  1.13k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|  1.13k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.13k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.13k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.13k|	return _ret; \
  |  |  |  |  163|  1.13k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|  1.13k|}
card-sc-hsm.c:sc_hsm_decipher:
 1135|    248|{
 1136|    248|	int r;
 1137|    248|	size_t len;
 1138|    248|	sc_apdu_t apdu;
 1139|    248|	u8 rbuf[514];
 1140|    248|	sc_hsm_private_data_t *priv;
 1141|       |
 1142|    248|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1142:6): [True: 0, False: 248]
  |  Branch (1142:22): [True: 0, False: 248]
  |  Branch (1142:40): [True: 0, False: 248]
  ------------------
 1143|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1144|      0|	}
 1145|    248|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    248|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    248|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    248|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    248|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 248]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1146|    248|	priv = (sc_hsm_private_data_t *) card->drv_data;
 1147|       |
 1148|    248|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_EXT, 0x62, priv->env->key_ref[0], priv->algorithm);
  ------------------
  |  |  299|    248|#define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  294|    248|#define SC_APDU_CASE_4_SHORT		0x04
  |  |  ------------------
  |  |               #define SC_APDU_CASE_4_EXT		SC_APDU_CASE_4_SHORT | SC_APDU_EXT
  |  |  ------------------
  |  |  |  |  296|    248|#define SC_APDU_EXT			0x10
  |  |  ------------------
  ------------------
 1149|    248|	apdu.cla = 0x80;
 1150|    248|	apdu.resp = rbuf;
 1151|    248|	apdu.resplen = sizeof(rbuf);
 1152|    248|	apdu.le = 512;
 1153|       |
 1154|    248|	apdu.data = (u8 *)crgram;
 1155|    248|	apdu.lc = crgram_len;
 1156|    248|	apdu.datalen = crgram_len;
 1157|       |
 1158|    248|	r = sc_transmit_apdu(card, &apdu);
 1159|       |
 1160|    248|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    248|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    248|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    248|	int _ret = (r); \
  |  |  |  |  168|    248|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 17, False: 231]
  |  |  |  |  ------------------
  |  |  |  |  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|    248|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 231]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1161|    231|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
  ------------------
  |  Branch (1161:6): [True: 67, False: 164]
  |  Branch (1161:26): [True: 56, False: 11]
  ------------------
 1162|     56|		if (priv->algorithm == ALGO_EC_DH) {
  ------------------
  |  |   58|     56|#define ALGO_EC_DH				0x80		/* ECDH key derivation */
  ------------------
  |  Branch (1162:7): [True: 0, False: 56]
  ------------------
 1163|       |			//
 1164|       |			// The SmartCard-HSM returns the point result of the DH operation
 1165|       |			// with a leading '04'
 1166|      0|			if (apdu.resplen <= 0)
  ------------------
  |  Branch (1166:8): [True: 0, False: 0]
  ------------------
 1167|      0|				return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
 1168|      0|			len = apdu.resplen - 1 > outlen ? outlen : apdu.resplen - 1;
  ------------------
  |  Branch (1168:10): [True: 0, False: 0]
  ------------------
 1169|      0|			memcpy(out, apdu.resp + 1, len);
 1170|      0|			LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1171|     56|		} else {
 1172|     56|			len = apdu.resplen > outlen ? outlen : apdu.resplen;
  ------------------
  |  Branch (1172:10): [True: 0, False: 56]
  ------------------
 1173|     56|			memcpy(out, apdu.resp, len);
 1174|     56|			LOG_FUNC_RETURN(card->ctx, (int)len);
  ------------------
  |  |  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: 8, False: 48]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|	} else { \
  |  |  |  |  159|     48|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     48|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     48|	} \
  |  |  |  |  162|     56|	return _ret; \
  |  |  |  |  163|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1175|     56|		}
 1176|     56|	}
 1177|    175|	else
 1178|    231|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|    175|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    175|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    175|	int _ret = r; \
  |  |  |  |  155|    175|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 175, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    175|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    175|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 175, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    175|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    175|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    175|	return _ret; \
  |  |  |  |  163|    175|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1179|    231|}
card-sc-hsm.c:sc_hsm_init:
 1779|    237|{
 1780|       |#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE) && defined(_WIN32)
 1781|       |	char expanded_val[PATH_MAX];
 1782|       |	size_t expanded_len = PATH_MAX;
 1783|       |#endif
 1784|    237|	int flags,ext_flags;
 1785|    237|	sc_file_t *file = NULL;
 1786|    237|	sc_path_t path;
 1787|    237|	sc_hsm_private_data_t *priv = NULL;
 1788|       |
 1789|    237|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    237|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    237|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    237|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    237|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 237]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1790|       |
 1791|    237|	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  111|    237|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	flags = SC_ALGORITHM_RSA_RAW|SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_ONBOARD_KEY_GEN
  ------------------
  |  |  116|    237|#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
  ------------------
  |  |  102|    237|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1792|    237|			|SC_ALGORITHM_RSA_HASH_SHA1|SC_ALGORITHM_RSA_HASH_SHA256|SC_ALGORITHM_RSA_HASH_SHA384|SC_ALGORITHM_RSA_HASH_SHA512
  ------------------
  |  |  143|    237|#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
  ------------------
  |  |  147|    237|#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
  ------------------
  |  |  148|    237|#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
  ------------------
  |  |  149|    237|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  ------------------
 1793|    237|			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  155|    237|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  156|    237|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
              			|SC_ALGORITHM_MGF1_SHA256|SC_ALGORITHM_MGF1_SHA384|SC_ALGORITHM_MGF1_SHA512;
  ------------------
  |  |  157|    237|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
 1794|       |
 1795|    237|	_sc_card_add_rsa_alg(card, 1024, flags, 0);
 1796|    237|	_sc_card_add_rsa_alg(card, 1536, flags, 0);
 1797|    237|	_sc_card_add_rsa_alg(card, 2048, flags, 0);
 1798|    237|	_sc_card_add_rsa_alg(card, 3072, flags, 0);
 1799|    237|	_sc_card_add_rsa_alg(card, 4096, flags, 0);
 1800|       |
 1801|    237|	flags = SC_ALGORITHM_ECDSA_RAW|
  ------------------
  |  |  183|    237|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
 1802|    237|		SC_ALGORITHM_ECDH_CDH_RAW|
  ------------------
  |  |  182|    237|#define SC_ALGORITHM_ECDH_CDH_RAW	0x00200000
  ------------------
 1803|    237|		SC_ALGORITHM_ECDSA_HASH_NONE|
  ------------------
  |  |  184|    237|#define SC_ALGORITHM_ECDSA_HASH_NONE		SC_ALGORITHM_RSA_HASH_NONE
  |  |  ------------------
  |  |  |  |  142|    237|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  |  |  ------------------
  ------------------
 1804|    237|		SC_ALGORITHM_ECDSA_HASH_SHA1|
  ------------------
  |  |  185|    237|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  143|    237|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
 1805|    237|		SC_ALGORITHM_ECDSA_HASH_SHA224|
  ------------------
  |  |  186|    237|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  150|    237|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
 1806|    237|		SC_ALGORITHM_ECDSA_HASH_SHA256|
  ------------------
  |  |  187|    237|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  147|    237|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
 1807|    237|		SC_ALGORITHM_ECDSA_HASH_SHA384|
  ------------------
  |  |  188|    237|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  148|    237|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
 1808|    237|		SC_ALGORITHM_ECDSA_HASH_SHA512|
  ------------------
  |  |  189|    237|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  149|    237|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
 1809|    237|		SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    237|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1810|       |
 1811|    237|	ext_flags = SC_ALGORITHM_EXT_EC_F_P|
  ------------------
  |  |  207|    237|#define SC_ALGORITHM_EXT_EC_F_P          0x00000001
  ------------------
 1812|    237|			SC_ALGORITHM_EXT_EC_ECPARAMETERS|
  ------------------
  |  |  209|    237|#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
  ------------------
 1813|    237|			SC_ALGORITHM_EXT_EC_NAMEDCURVE|
  ------------------
  |  |  210|    237|#define SC_ALGORITHM_EXT_EC_NAMEDCURVE   0x00000008
  ------------------
 1814|    237|			SC_ALGORITHM_EXT_EC_UNCOMPRESES|
  ------------------
  |  |  211|    237|#define SC_ALGORITHM_EXT_EC_UNCOMPRESES  0x00000010
  ------------------
 1815|    237|			SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    237|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
 1816|    237|	_sc_card_add_ec_alg(card, 192, flags, ext_flags, NULL);
 1817|    237|	_sc_card_add_ec_alg(card, 224, flags, ext_flags, NULL);
 1818|    237|	_sc_card_add_ec_alg(card, 256, flags, ext_flags, NULL);
 1819|    237|	_sc_card_add_ec_alg(card, 320, flags, ext_flags, NULL);
 1820|    237|	_sc_card_add_ec_alg(card, 384, flags, ext_flags, NULL);
 1821|    237|	_sc_card_add_ec_alg(card, 512, flags, ext_flags, NULL);
 1822|    237|	_sc_card_add_ec_alg(card, 521, flags, ext_flags, NULL);
 1823|       |
 1824|    237|	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  557|    237|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  554|    237|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_RNG|SC_CARD_CAP_APDU_EXT|SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    237|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
 1825|       |
 1826|       |	// APDU Size limits
 1827|       |	//   JCOP 2.4.1r3           1462
 1828|       |	//   JCOP 2.4.2r3           1454
 1829|       |	//   JCOP 3                 1232
 1830|       |	//   JCOP 4                 1454
 1831|       |	//   MicroSD with JCOP 3    478 / 506 - handled in reader-pcsc.c
 1832|       |	//   Reiner SCT             1014 - handled in reader-pcsc.c
 1833|       |	//
 1834|       |	// Note, that these are limits for the whole APDU, but the semantics of max_send_size
 1835|       |	// is the size of the APDU send buffer so to get the right value from them, we need
 1836|       |	// to subtract APDU headers (CLA, INS, P1, P2, Lc (3B)), 7 bytes altogether for
 1837|       |	// class 3 APDU
 1838|       |	// (or 9 bytes for case 4 when we pass in >255 B data and expect return of more than 255 B)
 1839|       |
 1840|       |	// Use JCOP 3 (smallest unhandled by reader limitation) card limits for sending
 1841|       |	// And make it 9 smaller to make sure we fit the rest of the APDU.
 1842|    237|	card->max_send_size = 1232 - 9;
 1843|       |	// Assume that card supports sending with extended length APDU and without limit
 1844|    237|	card->max_recv_size = 0;
 1845|       |
 1846|    237|	if (card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (1846:6): [True: 0, False: 237]
  ------------------
 1847|    237|			|| card->type == SC_CARD_TYPE_SC_HSM_GOID) {
  ------------------
  |  Branch (1847:7): [True: 236, False: 1]
  ------------------
 1848|    236|		card->max_recv_size = 0x0630;	// SoC Proxy forces this limit
 1849|    236|	} else {
 1850|       |		// Adjust to the limits set by the reader
 1851|      1|		if (card->reader->max_send_size < card->max_send_size) {
  ------------------
  |  Branch (1851:7): [True: 1, False: 0]
  ------------------
 1852|      1|			if (18 >= card->reader->max_send_size)
  ------------------
  |  Branch (1852:8): [True: 1, False: 0]
  ------------------
 1853|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1854|       |
 1855|       |			// 17 byte header and TLV because of odd ins in UPDATE BINARY
 1856|      0|			card->max_send_size = card->reader->max_send_size - 17;
 1857|      0|		}
 1858|       |
 1859|      0|		if (0 < card->reader->max_recv_size) {
  ------------------
  |  Branch (1859:7): [True: 0, False: 0]
  ------------------
 1860|      0|			if (3 >= card->reader->max_recv_size)
  ------------------
  |  Branch (1860:8): [True: 0, False: 0]
  ------------------
 1861|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1862|      0|			card->max_recv_size = card->reader->max_recv_size - 2;
 1863|      0|		}
 1864|      0|	}
 1865|       |
 1866|    236|	priv = card->drv_data;
 1867|    236|	if (!priv) {
  ------------------
  |  Branch (1867:6): [True: 236, False: 0]
  ------------------
 1868|    236|		priv = calloc(1, sizeof(sc_hsm_private_data_t));
 1869|    236|		if (!priv)
  ------------------
  |  Branch (1869:7): [True: 0, False: 236]
  ------------------
 1870|    236|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1871|    236|		card->drv_data = priv;
 1872|    236|	}
 1873|       |
 1874|    236|	sc_path_set(&path, SC_PATH_TYPE_DF_NAME, sc_hsm_aid.value, sc_hsm_aid.len, 0, 0);
  ------------------
  |  |  118|    236|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
 1875|    236|	if (sc_hsm_select_file_ex(card, &path, 0, &file) == SC_SUCCESS
  ------------------
  |  |   28|    472|#define SC_SUCCESS				0
  ------------------
  |  Branch (1875:6): [True: 38, False: 198]
  ------------------
 1876|     38|			&& file && file->prop_attr && file->prop_attr_len >= 2) {
  ------------------
  |  Branch (1876:7): [True: 38, False: 0]
  |  Branch (1876:15): [True: 4, False: 34]
  |  Branch (1876:34): [True: 3, False: 1]
  ------------------
 1877|      3|		static char card_name[SC_MAX_APDU_BUFFER_SIZE];
 1878|      3|		u8 type = 0xFF;
 1879|      3|		u8 major = file->prop_attr[file->prop_attr_len - 2];
 1880|      3|		u8 minor = file->prop_attr[file->prop_attr_len - 1];
 1881|      3|		char p00[] = "SmartCard-HSM Applet for JCOP";
 1882|      3|		char p01[] = "SmartCard-HSM Demo Applet for JCOP";
 1883|      3|		char *p = "SmartCard-HSM";
 1884|      3|		if (file->prop_attr_len >= 3) {
  ------------------
  |  Branch (1884:7): [True: 2, False: 1]
  ------------------
 1885|      2|			type = file->prop_attr[file->prop_attr_len - 3];
 1886|      2|		}
 1887|      3|		switch (type) {
 1888|      1|			case 0x00:
  ------------------
  |  Branch (1888:4): [True: 1, False: 2]
  ------------------
 1889|      1|				p = p00;
 1890|      1|				break;
 1891|      1|			case 0x01:
  ------------------
  |  Branch (1891:4): [True: 1, False: 2]
  ------------------
 1892|      1|				p = p01;
 1893|      1|				break;
 1894|      1|			default:
  ------------------
  |  Branch (1894:4): [True: 1, False: 2]
  ------------------
 1895|      1|				break;
 1896|      3|		}
 1897|      3|		snprintf(card_name, sizeof card_name, "%s version %u.%u", p, major, minor);
 1898|      3|		card->name = card_name;
 1899|       |
 1900|      3|		if (file->prop_attr[1] & 0x04) {
  ------------------
  |  Branch (1900:7): [True: 1, False: 2]
  ------------------
 1901|      1|			card->caps |= SC_CARD_CAP_SESSION_PIN;
  ------------------
  |  |  570|      1|#define SC_CARD_CAP_SESSION_PIN	0x00000200
  ------------------
 1902|      1|		}
 1903|      3|	}
 1904|    236|	sc_file_free(file);
 1905|       |
 1906|    236|	priv->EF_C_DevAut = NULL;
 1907|    236|	priv->EF_C_DevAut_len = 0;
 1908|       |
 1909|    236|#if defined(ENABLE_SM) && defined(ENABLE_OPENPACE)
 1910|    236|	EAC_init();
 1911|       |#ifdef _WIN32
 1912|       |	expanded_len = ExpandEnvironmentStringsA(CVCDIR, expanded_val, sizeof expanded_val);
 1913|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1914|       |		EAC_set_cvc_default_dir(expanded_val);
 1915|       |#else
 1916|    236|	EAC_set_cvc_default_dir(CVCDIR);
  ------------------
  |  |    8|    236|#define CVCDIR "/usr/etc/eac/cvc"
  ------------------
 1917|    236|#endif
 1918|    236|#endif
 1919|       |
 1920|    236|	return 0;
 1921|    236|}
card-sc-hsm.c:sc_hsm_finish:
 1926|    236|{
 1927|    236|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1928|    236|#ifdef ENABLE_SM
 1929|    236|	sc_sm_stop(card);
 1930|    236|#endif
 1931|    236|	if (priv) {
  ------------------
  |  Branch (1931:6): [True: 236, False: 0]
  ------------------
 1932|    236|		free(priv->serialno);
 1933|    236|		sc_file_free(priv->dffcp);
 1934|    236|		free(priv->EF_C_DevAut);
 1935|    236|	}
 1936|    236|	free(priv);
 1937|       |
 1938|    236|	return SC_SUCCESS;
  ------------------
  |  |   28|    236|#define SC_SUCCESS				0
  ------------------
 1939|    236|}
card-sc-hsm.c:sc_hsm_card_ctl:
 1750|    155|{
 1751|    155|	switch (cmd) {
  ------------------
  |  Branch (1751:10): [True: 155, False: 0]
  ------------------
 1752|    155|	case SC_CARDCTL_GET_SERIALNR:
  ------------------
  |  Branch (1752:2): [True: 155, False: 0]
  ------------------
 1753|    155|		return sc_hsm_get_serialnr(card, (sc_serial_number_t *)ptr);
 1754|      0|	case SC_CARDCTL_PKCS11_INIT_TOKEN:
  ------------------
  |  Branch (1754:2): [True: 0, False: 155]
  ------------------
 1755|      0|		return sc_hsm_init_token(card, (sc_cardctl_pkcs11_init_token_t *)ptr);
 1756|      0|	case SC_CARDCTL_PKCS11_INIT_PIN:
  ------------------
  |  Branch (1756:2): [True: 0, False: 155]
  ------------------
 1757|      0|		return sc_hsm_init_pin(card, (sc_cardctl_pkcs11_init_pin_t *)ptr);
 1758|      0|	case SC_CARDCTL_SC_HSM_GENERATE_KEY:
  ------------------
  |  Branch (1758:2): [True: 0, False: 155]
  ------------------
 1759|      0|		return sc_hsm_generate_keypair(card, (sc_cardctl_sc_hsm_keygen_info_t *)ptr);
 1760|      0|	case SC_CARDCTL_SC_HSM_INITIALIZE:
  ------------------
  |  Branch (1760:2): [True: 0, False: 155]
  ------------------
 1761|      0|		return sc_hsm_initialize(card, (sc_cardctl_sc_hsm_init_param_t *)ptr);
 1762|      0|	case SC_CARDCTL_SC_HSM_IMPORT_DKEK_SHARE:
  ------------------
  |  Branch (1762:2): [True: 0, False: 155]
  ------------------
 1763|      0|		return sc_hsm_import_dkek_share(card, (sc_cardctl_sc_hsm_dkek_t *)ptr);
 1764|      0|	case SC_CARDCTL_SC_HSM_WRAP_KEY:
  ------------------
  |  Branch (1764:2): [True: 0, False: 155]
  ------------------
 1765|      0|		return sc_hsm_wrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1766|      0|	case SC_CARDCTL_SC_HSM_UNWRAP_KEY:
  ------------------
  |  Branch (1766:2): [True: 0, False: 155]
  ------------------
 1767|      0|		return sc_hsm_unwrap_key(card, (sc_cardctl_sc_hsm_wrapped_key_t *)ptr);
 1768|      0|	case SC_CARDCTL_SC_HSM_REGISTER_PUBLIC_KEY:
  ------------------
  |  Branch (1768:2): [True: 0, False: 155]
  ------------------
 1769|      0|		return sc_hsm_register_public_key(card, ptr);
 1770|      0|	case SC_CARDCTL_SC_HSM_PUBLIC_KEY_AUTH_STATUS:
  ------------------
  |  Branch (1770:2): [True: 0, False: 155]
  ------------------
 1771|      0|		return sc_hsm_public_key_auth_status(card, ptr);
 1772|    155|	}
 1773|      0|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1774|    155|}
card-sc-hsm.c:sc_hsm_get_serialnr:
 1197|    155|{
 1198|    155|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
 1199|       |
 1200|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1201|       |
 1202|    155|	if (!priv->serialno && 0 == strcmp(card->ctx->app_name, "opensc-tool")) {
  ------------------
  |  Branch (1202:6): [True: 155, False: 0]
  |  Branch (1202:25): [True: 0, False: 155]
  ------------------
 1203|       |		/* sc-hsm initializes the serial number via its PKCS#15 layer.
 1204|       |		 * Create and destroy a dummy card to get this initialized.  Only do
 1205|       |		 * this for `opensc-tool --serial` to avoid unnecessary card commands
 1206|       |		 * in all other cases. */
 1207|      0|		sc_pkcs15_card_t *p15card = NULL;
 1208|      0|		(void)sc_pkcs15_bind(card, NULL, &p15card);
 1209|      0|		sc_pkcs15_unbind(p15card);
 1210|      0|	}
 1211|       |
 1212|    155|	if (!priv->serialno) {
  ------------------
  |  Branch (1212:6): [True: 155, False: 0]
  ------------------
 1213|    155|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    155|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1214|    155|	}
 1215|       |
 1216|      0|	serial->len = strlen(priv->serialno);
 1217|      0|	if (serial->len > sizeof(serial->value))
  ------------------
  |  Branch (1217:6): [True: 0, False: 0]
  ------------------
 1218|      0|		serial->len = sizeof(serial->value);
 1219|       |
 1220|      0|	memcpy(serial->value, priv->serialno, serial->len);
 1221|       |
 1222|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1223|      0|}
card-sc-hsm.c:sc_hsm_pin_cmd:
  620|    491|{
  621|    491|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  622|    491|	sc_apdu_t apdu;
  623|    491|	u8 cmdbuff[16];
  624|    491|#ifdef ENABLE_SM
  625|    491|	u8 rbuf[SC_MAX_APDU_BUFFER_SIZE];
  626|    491|#endif
  627|    491|	int r;
  628|    491|	int cmd = data->cmd;
  629|    491|	size_t pin2_len = data->pin2.len;
  630|       |
  631|    491|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  426|    491|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (631:6): [True: 0, False: 491]
  ------------------
  632|       |		/* First, perform a standard VERIFY */
  633|      0|		data->cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|      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|    491|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|    491|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (639:6): [True: 0, False: 491]
  ------------------
  640|      0|		   	&& (data->cmd == SC_PIN_CMD_CHANGE)
  ------------------
  |  |  423|      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, tries_left);
  644|    491|	} else if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|    491|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (644:13): [True: 0, False: 491]
  ------------------
  645|      0|		   	&& (data->cmd == SC_PIN_CMD_UNBLOCK)
  ------------------
  |  |  424|      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, tries_left);
  649|      0|	}
  650|       |
  651|    491|#ifdef ENABLE_SM
  652|       |	/* For contactless cards always establish a secure channel before PIN
  653|       |	 * verification. Also, Session PIN generation requires SM. */
  654|    491|	if ((card->type == SC_CARD_TYPE_SC_HSM_SOC
  ------------------
  |  Branch (654:7): [True: 0, False: 491]
  ------------------
  655|    491|				|| card->type == SC_CARD_TYPE_SC_HSM_GOID
  ------------------
  |  Branch (655:8): [True: 491, False: 0]
  ------------------
  656|      0|				|| card->reader->uid.len || cmd == SC_PIN_CMD_GET_SESSION_PIN)
  ------------------
  |  |  426|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (656:8): [True: 0, False: 0]
  |  Branch (656:33): [True: 0, False: 0]
  ------------------
  657|    491|			&& (data->cmd != SC_PIN_CMD_GET_INFO)) {
  ------------------
  |  |  425|    491|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (657:7): [True: 30, False: 461]
  ------------------
  658|     30|		struct sc_pin_cmd_data check_sm_pin_data;
  659|     30|		memset(&check_sm_pin_data, 0, sizeof(check_sm_pin_data));
  660|     30|		check_sm_pin_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  425|     30|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  661|     30|		check_sm_pin_data.pin_type = data->pin_type;
  662|     30|		check_sm_pin_data.pin_reference = data->pin_reference;
  663|       |
  664|     30|		r = SC_ERROR_NOT_ALLOWED;
  ------------------
  |  |   59|     30|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  665|     30|		if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|     30|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (665:7): [True: 0, False: 30]
  ------------------
  666|       |			/* check if the existing SM channel is still valid */
  667|      0|			r = sc_pin_cmd(card, &check_sm_pin_data, NULL);
  668|      0|		}
  669|     30|		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   83|     60|#define SC_ERROR_ASN1_OBJECT_NOT_FOUND		-1402
  ------------------
              		if (r == SC_ERROR_ASN1_OBJECT_NOT_FOUND || r == SC_ERROR_NOT_ALLOWED) {
  ------------------
  |  |   59|     30|#define SC_ERROR_NOT_ALLOWED			-1209
  ------------------
  |  Branch (669:7): [True: 0, False: 30]
  |  Branch (669:46): [True: 30, False: 0]
  ------------------
  670|       |			/* need to establish a new SM channel */
  671|     30|			LOG_TEST_RET(card->ctx,
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  672|     30|					sc_hsm_perform_chip_authentication(card),
  673|     30|					"Could not perform chip authentication");
  674|     30|		}
  675|     30|	}
  676|    461|#endif
  677|       |
  678|    461|	if ((card->caps & SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH)
  ------------------
  |  |  567|    461|#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH	0x00000100
  ------------------
  |  Branch (678:6): [True: 0, False: 461]
  ------------------
  679|      0|			&& (data->cmd == SC_PIN_CMD_VERIFY)
  ------------------
  |  |  422|      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, tries_left);
  683|    461|	} else {
  684|    461|		if ((data->cmd == SC_PIN_CMD_VERIFY) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  422|    461|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (684:7): [True: 0, False: 461]
  |  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|    461|		if ((data->cmd == SC_PIN_CMD_CHANGE) && (data->pin_reference == 0x88)) {
  ------------------
  |  |  423|    461|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (695:7): [True: 0, False: 461]
  |  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|    461|#ifdef ENABLE_SM
  714|    461|		if ((data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|    461|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (714:7): [True: 461, False: 0]
  ------------------
  715|    461|				&& (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT)) {
  ------------------
  |  |   47|    461|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (715:8): [True: 0, False: 461]
  ------------------
  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|    461|#endif
  723|       |
  724|    461|		data->pin1.offset = 5;
  725|    461|		data->pin2.offset = 5;
  726|       |
  727|    461|		r = (*iso_ops->pin_cmd)(card, data, tries_left);
  728|    461|		data->apdu = NULL;
  729|    461|	}
  730|    461|	LOG_TEST_RET(card->ctx, r, "Verification failed");
  ------------------
  |  |  174|    461|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    461|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    461|	int _ret = (r); \
  |  |  |  |  168|    461|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 297, False: 164]
  |  |  |  |  ------------------
  |  |  |  |  169|    297|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    297|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    297|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    297|		return _ret; \
  |  |  |  |  172|    297|	} \
  |  |  |  |  173|    461|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 164]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  731|       |
  732|    164|	if (cmd == SC_PIN_CMD_GET_SESSION_PIN) {
  ------------------
  |  |  426|    164|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  |  Branch (732:6): [True: 0, False: 164]
  ------------------
  733|       |		/* reset data->cmd to its original value */
  734|      0|		data->cmd = SC_PIN_CMD_GET_SESSION_PIN;
  ------------------
  |  |  426|      0|#define SC_PIN_CMD_GET_SESSION_PIN	4
  ------------------
  735|      0|		if (data->pin_reference == 0x81) {
  ------------------
  |  Branch (735:7): [True: 0, False: 0]
  ------------------
  736|      0|			u8 recvbuf[SC_MAX_APDU_BUFFER_SIZE];
  737|      0|#ifdef ENABLE_SM
  738|      0|			if (card->sm_ctx.sm_mode != SM_MODE_TRANSMIT) {
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
  |  Branch (738:8): [True: 0, False: 0]
  ------------------
  739|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  740|      0|						"Session PIN generation only supported in SM");
  741|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  742|      0|			}
  743|       |#else
  744|       |			sc_log(card->ctx,
  745|       |					"Session PIN generation only supported in SM");
  746|       |			LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  747|       |#endif
  748|      0|			sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0x5A, 0x01, data->pin_reference);
  ------------------
  |  |  292|      0|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  749|      0|			apdu.cla = 0x80;
  750|      0|			apdu.resp = recvbuf;
  751|      0|			apdu.resplen = sizeof recvbuf;
  752|      0|			apdu.le = 0;
  753|      0|			if (sc_transmit_apdu(card, &apdu) != SC_SUCCESS
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (753:8): [True: 0, False: 0]
  ------------------
  754|      0|					|| sc_check_sw(card, apdu.sw1, apdu.sw2) != SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (754:9): [True: 0, False: 0]
  ------------------
  755|      0|				sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  756|      0|						"Generating session PIN failed");
  757|      0|				LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  758|      0|			}
  759|      0|			if (data->pin2.data && pin2_len > 0) {
  ------------------
  |  Branch (759:8): [True: 0, False: 0]
  |  Branch (759:27): [True: 0, False: 0]
  ------------------
  760|      0|				if (pin2_len >= apdu.resplen) {
  ------------------
  |  Branch (760:9): [True: 0, False: 0]
  ------------------
  761|      0|					memcpy((unsigned char *) data->pin2.data, apdu.resp,
  762|      0|							apdu.resplen);
  763|      0|					data->pin2.len = apdu.resplen;
  764|      0|				} else {
  765|      0|					sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  766|      0|							"Buffer too small for session PIN");
  767|      0|				}
  768|      0|			}
  769|      0|		} else {
  770|      0|			sc_log(card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  771|      0|					"Session PIN not supported for this PIN (0x%02X)",
  772|      0|					data->pin_reference);
  773|      0|		}
  774|      0|	}
  775|    164|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    164|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    164|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    164|	int _ret = r; \
  |  |  |  |  155|    164|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 164, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    164|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 164]
  |  |  |  |  ------------------
  |  |  |  |  157|    164|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    164|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    164|	return _ret; \
  |  |  |  |  163|    164|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  776|    164|}
card-sc-hsm.c:sc_hsm_perform_chip_authentication:
  494|     30|{
  495|     30|	int r, protocol;
  496|     30|	sc_path_t path;
  497|     30|	u8 all_certs[1024];
  498|     30|	EAC_CTX *ctx = NULL;
  499|     30|	size_t all_certs_len = sizeof all_certs, left, device_cert_len, issuer_cert_len;
  500|     30|	const unsigned char *cert = all_certs, *device_cert, *issuer_cert;
  501|     30|	BUF_MEM *comp_pub_key = NULL;
  502|     30|	sc_cvc_t cvc_device, cvc_issuer;
  503|       |	/* this is only needed to call sc_pkcs15emu_sc_hsm_decode_cvc */
  504|     30|	sc_pkcs15_card_t p15card;
  505|     30|	sc_hsm_private_data_t *priv = (sc_hsm_private_data_t *) card->drv_data;
  506|       |	/* we know that sc_pkcs15emu_sc_hsm_decode_cvc does not require anything
  507|       |	 * else to be initialized than p15card->card */
  508|     30|	p15card.card = card;
  509|       |
  510|     30|	memset(&cvc_device, 0, sizeof(cvc_device));
  511|     30|	memset(&cvc_issuer, 0, sizeof(cvc_issuer));
  512|       |
  513|       |
  514|     30|	if (priv->EF_C_DevAut && priv->EF_C_DevAut_len) {
  ------------------
  |  Branch (514:6): [True: 5, False: 25]
  |  Branch (514:27): [True: 5, False: 0]
  ------------------
  515|      5|		all_certs_len = priv->EF_C_DevAut_len;
  516|      5|		cert = priv->EF_C_DevAut;
  517|     25|	} else {
  518|       |		/* get issuer and device certificate from the card */
  519|     25|		r = sc_path_set(&path, SC_PATH_TYPE_FILE_ID, (u8 *) "\x2F\x02", 2, 0, 0);
  ------------------
  |  |  117|     25|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  520|     25|		if (r < 0)
  ------------------
  |  Branch (520:7): [True: 0, False: 25]
  ------------------
  521|      0|			goto err;
  522|     25|		r = sc_select_file(card, &path, NULL);
  523|     25|		if (r < 0)
  ------------------
  |  Branch (523:7): [True: 13, False: 12]
  ------------------
  524|     13|			goto err;
  525|     12|		r = sc_read_binary(card, 0, all_certs, all_certs_len, 0);
  526|     12|		if (r < 0)
  ------------------
  |  Branch (526:7): [True: 3, False: 9]
  ------------------
  527|      3|			goto err;
  528|      9|		if (r == 0) {
  ------------------
  |  Branch (528:7): [True: 3, False: 6]
  ------------------
  529|      3|			r = SC_ERROR_FILE_NOT_FOUND;
  ------------------
  |  |   51|      3|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  530|      3|			goto err;
  531|      3|		}
  532|       |
  533|      6|		all_certs_len = r;
  534|       |
  535|       |		/* save EF_C_DevAut for further use */
  536|      6|		cert = realloc(priv->EF_C_DevAut, all_certs_len);
  537|      6|		if (cert) {
  ------------------
  |  Branch (537:7): [True: 6, False: 0]
  ------------------
  538|      6|			memcpy((unsigned char *) cert, all_certs, all_certs_len);
  539|      6|			priv->EF_C_DevAut = (unsigned char *) cert;
  540|      6|			priv->EF_C_DevAut_len = all_certs_len;
  541|      6|		}
  542|       |
  543|      6|		cert = all_certs;
  544|      6|	}
  545|     11|	left = all_certs_len;
  546|       |
  547|     11|	device_cert = cert;
  548|     11|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_device);
  549|     11|	if (r < 0)
  ------------------
  |  Branch (549:6): [True: 11, False: 0]
  ------------------
  550|     11|		goto err;
  551|      0|	device_cert_len = all_certs_len - left;
  552|       |
  553|      0|	issuer_cert = cert;
  554|      0|	r = sc_pkcs15emu_sc_hsm_decode_cvc(&p15card, &cert, &left, &cvc_issuer);
  555|      0|	if (r < 0)
  ------------------
  |  Branch (555:6): [True: 0, False: 0]
  ------------------
  556|      0|		goto err;
  557|      0|	issuer_cert_len = all_certs_len - device_cert_len - left;
  558|       |
  559|      0|	ctx = EAC_CTX_new();
  560|      0|	if (!ctx) {
  ------------------
  |  Branch (560:6): [True: 0, False: 0]
  ------------------
  561|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  562|      0|		goto err;
  563|      0|	}
  564|       |
  565|       |
  566|       |	/* check all CVCs given of the document's pki */
  567|      0|	if (!TA_STEP2_import_certificate(ctx, issuer_cert, issuer_cert_len)
  ------------------
  |  Branch (567:6): [True: 0, False: 0]
  ------------------
  568|      0|			|| !TA_STEP2_import_certificate(ctx, device_cert, device_cert_len)) {
  ------------------
  |  Branch (568:7): [True: 0, False: 0]
  ------------------
  569|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  570|      0|		goto err;
  571|      0|	}
  572|       |
  573|       |	/* XXX on older JCOPs only NID_id_CA_ECDH_3DES_CBC_CBC may be
  574|       |	 * supported. The card does not export its capabilities. We hardcode
  575|       |	 * NID_id_CA_ECDH_AES_CBC_CMAC_128 here, because we don't have the older
  576|       |	 * cards in production. */
  577|      0|	protocol = NID_id_CA_ECDH_AES_CBC_CMAC_128;
  578|       |
  579|       |	/* initialize CA domain parameter with the document's public key */
  580|      0|	if (!EAC_CTX_init_ca(ctx, protocol, 8)) {
  ------------------
  |  Branch (580:6): [True: 0, False: 0]
  ------------------
  581|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  582|      0|		goto err;
  583|      0|	}
  584|      0|	EVP_PKEY_free(ctx->ca_ctx->ka_ctx->key);
  585|      0|	if (!EVP_PKEY_up_ref(ctx->ta_ctx->pub_key)) {
  ------------------
  |  Branch (585:6): [True: 0, False: 0]
  ------------------
  586|      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__
  |  |  ------------------
  ------------------
  587|      0|		r = SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  588|      0|		goto err;
  589|      0|	}
  590|      0|	ctx->ca_ctx->ka_ctx->key = ctx->ta_ctx->pub_key;
  591|       |
  592|       |	/* generate keys for CA */
  593|      0|	comp_pub_key = TA_STEP3_generate_ephemeral_key(ctx);
  594|      0|	r = perform_chip_authentication_ex(card, ctx,
  595|      0|			cvc_device.publicPoint, cvc_device.publicPointlen);
  596|       |
  597|     30|err:
  598|     30|	if (r < 0)
  ------------------
  |  Branch (598:6): [True: 30, False: 0]
  ------------------
  599|     30|		EAC_CTX_clear_free(ctx);
  600|     30|	if (comp_pub_key)
  ------------------
  |  Branch (600:6): [True: 0, False: 30]
  ------------------
  601|      0|		BUF_MEM_free(comp_pub_key);
  602|     30|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_device);
  603|     30|	sc_pkcs15emu_sc_hsm_free_cvc(&cvc_issuer);
  604|       |
  605|     30|	return r;
  606|      0|}

sc_get_setcos_driver:
 1130|  15.3k|{
 1131|  15.3k|	return sc_get_driver();
 1132|  15.3k|}
card-setcos.c:sc_get_driver:
 1110|  15.3k|{
 1111|  15.3k|	struct sc_card_driver *iso_drv = sc_get_iso7816_driver();
 1112|       |
 1113|  15.3k|	setcos_ops = *iso_drv->ops;
 1114|  15.3k|	setcos_ops.match_card = setcos_match_card;
 1115|  15.3k|	setcos_ops.init = setcos_init;
 1116|  15.3k|	if (iso_ops == NULL)
  ------------------
  |  Branch (1116:6): [True: 1, False: 15.3k]
  ------------------
 1117|      1|		iso_ops = iso_drv->ops;
 1118|  15.3k|	setcos_ops.create_file = setcos_create_file;
 1119|  15.3k|	setcos_ops.set_security_env = setcos_set_security_env;
 1120|  15.3k|	setcos_ops.select_file = setcos_select_file;
 1121|  15.3k|	setcos_ops.list_files = setcos_list_files;
 1122|  15.3k|	setcos_ops.process_fci = setcos_process_fci;
 1123|  15.3k|	setcos_ops.construct_fci = setcos_construct_fci;
 1124|  15.3k|	setcos_ops.card_ctl = setcos_card_ctl;
 1125|       |
 1126|  15.3k|	return &setcos_drv;
 1127|  15.3k|}
card-setcos.c:setcos_match_card:
   83|  5.28k|{
   84|  5.28k|	sc_apdu_t apdu;
   85|  5.28k|	u8 buf[6];
   86|  5.28k|	int i;
   87|       |
   88|  5.28k|	i = _sc_match_atr(card, setcos_atrs, &card->type);
   89|  5.28k|	if (i < 0) {
  ------------------
  |  Branch (89:6): [True: 5.26k, False: 20]
  ------------------
   90|  5.26k|		if (match_hist_bytes(card, "FISE", 0)) {
  ------------------
  |  Branch (90:7): [True: 40, False: 5.22k]
  ------------------
   91|     40|			card->type = SC_CARD_TYPE_SETCOS_GENERIC;
   92|     40|			return 1;
   93|     40|		}
   94|       |		/* Check if it's a EID2.x applet by reading the version info */
   95|  5.22k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xCA, 0xDF, 0x30);
  ------------------
  |  |  292|  5.22k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   96|  5.22k|		apdu.cla = 0x00;
   97|  5.22k|		apdu.resp = buf;
   98|  5.22k|		apdu.resplen = 5;
   99|  5.22k|		apdu.le = 5;
  100|  5.22k|		i = sc_transmit_apdu(card, &apdu);
  101|  5.22k|		if (i == 0 && apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && apdu.resplen == 5) {
  ------------------
  |  Branch (101:7): [True: 5.08k, False: 139]
  |  Branch (101:17): [True: 337, False: 4.74k]
  |  Branch (101:37): [True: 300, False: 37]
  |  Branch (101:57): [True: 246, False: 54]
  ------------------
  102|    246|			if (memcmp(buf, "v2.0", 4) == 0)
  ------------------
  |  Branch (102:8): [True: 127, False: 119]
  ------------------
  103|    127|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_0;
  104|    119|			else if (memcmp(buf, "v2.1", 4) == 0)
  ------------------
  |  Branch (104:13): [True: 22, False: 97]
  ------------------
  105|     22|				card->type = SC_CARD_TYPE_SETCOS_EID_V2_1;
  106|     97|			else {
  107|     97|				buf[sizeof(buf) - 1] = '\0';
  108|     97|				sc_log(card->ctx,  "SetCOS EID applet %s is not supported", (char *) buf);
  ------------------
  |  |   71|     97|#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|     97|				return 0;
  110|     97|			}
  111|    149|			return 1;
  112|    246|		}
  113|       |
  114|  4.97k|		return 0;
  115|  5.22k|	}
  116|     20|	card->flags = setcos_atrs[i].flags;
  117|     20|	return 1;
  118|  5.28k|}
card-setcos.c:match_hist_bytes:
   64|  5.26k|{
   65|  5.26k|	const char *src = (const char *) card->reader->atr_info.hist_bytes;
   66|  5.26k|	size_t srclen = card->reader->atr_info.hist_bytes_len;
   67|  5.26k|	size_t offset = 0;
   68|       |
   69|  5.26k|	if (len == 0)
  ------------------
  |  Branch (69:6): [True: 5.26k, False: 0]
  ------------------
   70|  5.26k|		len = strlen(str);
   71|  5.26k|	if (srclen < len)
  ------------------
  |  Branch (71:6): [True: 3.20k, False: 2.05k]
  ------------------
   72|  3.20k|		return 0;
   73|  13.7k|	while (srclen - offset > len) {
  ------------------
  |  Branch (73:9): [True: 11.7k, False: 2.01k]
  ------------------
   74|  11.7k|		if (memcmp(src + offset, str, len) == 0) {
  ------------------
  |  Branch (74:7): [True: 40, False: 11.6k]
  ------------------
   75|     40|			return 1;
   76|     40|		}
   77|  11.6k|		offset++;
   78|  11.6k|	}
   79|  2.01k|	return 0;
   80|  2.05k|}
card-setcos.c:setcos_init:
  133|    209|{
  134|    209|	card->name = "SetCOS";
  135|       |
  136|       |	/* Handle unknown or forced cards */
  137|    209|	if (card->type < 0) {
  ------------------
  |  Branch (137:6): [True: 0, False: 209]
  ------------------
  138|      0|		card->type = SC_CARD_TYPE_SETCOS_GENERIC;
  139|      0|	}
  140|       |
  141|    209|	switch (card->type) {
  142|      6|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (142:2): [True: 6, False: 203]
  ------------------
  143|      6|		card->cla = 0x00;
  144|      6|		select_pkcs15_app(card);
  145|      6|		if (card->flags & SC_CARD_FLAG_RNG)
  ------------------
  |  |  543|      6|#define SC_CARD_FLAG_RNG		0x00000002
  ------------------
  |  Branch (145:7): [True: 0, False: 6]
  ------------------
  146|      0|			card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|      0|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  147|      6|		break;
  148|     13|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (148:2): [True: 13, False: 196]
  ------------------
  149|    140|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (149:2): [True: 127, False: 82]
  ------------------
  150|    162|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (150:2): [True: 22, False: 187]
  ------------------
  151|    162|		card->cla = 0x00;
  152|    162|		card->caps |= SC_CARD_CAP_USE_FCI_AC;
  ------------------
  |  |  564|    162|#define SC_CARD_CAP_USE_FCI_AC		0x00000010
  ------------------
  153|    162|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|    162|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  154|    162|		card->caps |= SC_CARD_CAP_APDU_EXT;
  ------------------
  |  |  554|    162|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  155|    162|		break;
  156|     41|	default:
  ------------------
  |  Branch (156:2): [True: 41, False: 168]
  ------------------
  157|       |		/* XXX: Get SetCOS version */
  158|     41|		card->cla = 0x80;	/* SetCOS 4.3.x */
  159|       |		/* State that we have an RNG */
  160|     41|		card->caps |= SC_CARD_CAP_RNG;
  ------------------
  |  |  557|     41|#define SC_CARD_CAP_RNG			0x00000004
  ------------------
  161|     41|		break;
  162|    209|	}
  163|       |
  164|    209|	switch (card->type) {
  ------------------
  |  Branch (164:10): [True: 169, False: 40]
  ------------------
  165|      1|	case SC_CARD_TYPE_SETCOS_PKI: {
  ------------------
  |  Branch (165:2): [True: 1, False: 208]
  ------------------
  166|      1|		unsigned long flags;
  167|       |
  168|      1|		flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|      1|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              		flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|      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) */
  |  |  ------------------
  |  |  |  |  118|      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) */
  |  |  ------------------
  |  |  |  |  119|      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;
  ------------------
  |  |  142|      1|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              		flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  143|      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|     13|	case SC_CARD_TYPE_SETCOS_44:
  ------------------
  |  Branch (174:2): [True: 13, False: 196]
  ------------------
  175|     19|	case SC_CARD_TYPE_SETCOS_NIDEL:
  ------------------
  |  Branch (175:2): [True: 6, False: 203]
  ------------------
  176|    146|	case SC_CARD_TYPE_SETCOS_EID_V2_0:
  ------------------
  |  Branch (176:2): [True: 127, False: 82]
  ------------------
  177|    168|	case SC_CARD_TYPE_SETCOS_EID_V2_1:
  ------------------
  |  Branch (177:2): [True: 22, False: 187]
  ------------------
  178|    168|		{
  179|    168|			unsigned long flags;
  180|       |
  181|    168|			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  111|    168|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              			flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|    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) */
  |  |  ------------------
  |  |  |  |  118|    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) */
  |  |  ------------------
  |  |  |  |  119|    168|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  182|    168|			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  142|    168|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
              			flags |= SC_ALGORITHM_RSA_HASH_NONE | SC_ALGORITHM_RSA_HASH_SHA1;
  ------------------
  |  |  143|    168|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  ------------------
  183|    168|			flags |= SC_ALGORITHM_ONBOARD_KEY_GEN;
  ------------------
  |  |  102|    168|#define SC_ALGORITHM_ONBOARD_KEY_GEN	0x80000000
  ------------------
  184|       |
  185|    168|			_sc_card_add_rsa_alg(card, 512, flags, 0);
  186|    168|			_sc_card_add_rsa_alg(card, 768, flags, 0);
  187|    168|			_sc_card_add_rsa_alg(card, 1024, flags, 0);
  188|    168|			_sc_card_add_rsa_alg(card, 2048, flags, 0);
  189|    168|		}
  190|    168|		break;
  191|    209|	}
  192|    209|	return 0;
  193|    209|}
card-setcos.c:select_pkcs15_app:
  121|      6|{
  122|      6|	sc_path_t app;
  123|      6|	int r;
  124|       |
  125|       |	/* Regular PKCS#15 AID */
  126|      6|	sc_format_path("A000000063504B43532D3135", &app);
  127|      6|	app.type = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|      6|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  128|       |	r = sc_select_file(card, &app, NULL);
  129|      6|	return r;
  130|      6|}
card-setcos.c:setcos_select_file:
  895|  1.04k|{
  896|  1.04k|	int r;
  897|       |
  898|  1.04k|	r = iso_ops->select_file(card, in_path, file);
  899|  1.04k|	if (r)
  ------------------
  |  Branch (899:6): [True: 769, False: 279]
  ------------------
  900|    769|		return r;
  901|    279|	if (file != NULL) {
  ------------------
  |  Branch (901:6): [True: 234, False: 45]
  ------------------
  902|    234|		if (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (902:7): [True: 22, False: 212]
  ------------------
  903|    212|		    card->type == SC_CARD_TYPE_SETCOS_NIDEL ||
  ------------------
  |  Branch (903:7): [True: 8, False: 204]
  ------------------
  904|    204|		    SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|    204|#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: 130, False: 74]
  |  |  |  Branch (46:85): [True: 28, False: 46]
  |  |  ------------------
  ------------------
  905|    188|			parse_sec_attr_44(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  906|     46|		else
  907|     46|			parse_sec_attr(*file, (*file)->sec_attr, (*file)->sec_attr_len);
  908|    234|	}
  909|    279|	return 0;
  910|  1.04k|}
card-setcos.c:parse_sec_attr_44:
  740|    188|{
  741|       |	/* OpenSc Operation values for each command operation-type */
  742|    188|	const int df_idx[8] = {	 /* byte 1 = OpenSC type of AC Bit0,  byte 2 = OpenSC type of AC Bit1 ...*/
  743|    188|		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  168|    188|#define SC_AC_OP_DELETE			2
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    188|#define SC_AC_OP_CREATE			3
  ------------------
              		SC_AC_OP_DELETE, SC_AC_OP_CREATE, SC_AC_OP_CREATE,
  ------------------
  |  |  169|    188|#define SC_AC_OP_CREATE			3
  ------------------
  744|    188|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    188|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    188|#define SC_AC_OP_REHABILITATE		4
  ------------------
  745|    188|		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  167|    188|#define SC_AC_OP_LOCK			1
  ------------------
              		SC_AC_OP_LOCK, SC_AC_OP_DELETE, -1};
  ------------------
  |  |  168|    188|#define SC_AC_OP_DELETE			2
  ------------------
  746|    188|	const int ef_idx[8] = {
  747|    188|		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|    188|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|    188|#define SC_AC_OP_UPDATE			23
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|    188|#define SC_AC_OP_WRITE			24
  ------------------
  748|    188|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    188|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    188|#define SC_AC_OP_REHABILITATE		4
  ------------------
  749|    188|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    188|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    188|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  750|    188|	const int efi_idx[8] = { /* internal EF used for RSA keys */
  751|    188|		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  188|    188|#define SC_AC_OP_READ			22
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  202|    188|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    188|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              		SC_AC_OP_READ, SC_AC_OP_ERASE, SC_AC_OP_UPDATE,
  ------------------
  |  |  189|    188|#define SC_AC_OP_UPDATE			23
  ------------------
  752|    188|		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  171|    188|#define SC_AC_OP_INVALIDATE		5
  ------------------
              		SC_AC_OP_INVALIDATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|    188|#define SC_AC_OP_REHABILITATE		4
  ------------------
  753|    188|		-1, SC_AC_OP_ERASE, -1};
  ------------------
  |  |  202|    188|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|    188|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
  754|       |
  755|    188|	u8		bValue;
  756|    188|	int		i;
  757|    188|	int		iKeyRef = 0;
  758|    188|	int		iMethod;
  759|    188|	int		iPinCount;
  760|    188|	int		iOffset = 0;
  761|    188|	int		iOperation;
  762|    188|	const int*	p_idx;
  763|       |
  764|       |	/* Check all sub-AC definitions within the total AC */
  765|  1.22k|	while (len > 1 && (size_t)iOffset < len) {	/* minimum length = 2 */
  ------------------
  |  Branch (765:9): [True: 1.14k, False: 73]
  |  Branch (765:20): [True: 1.06k, False: 87]
  ------------------
  766|  1.06k|		size_t iACLen   = buf[iOffset] & 0x0F;
  767|  1.06k|		if (iACLen >= len)
  ------------------
  |  Branch (767:7): [True: 23, False: 1.03k]
  ------------------
  768|     23|			break;
  769|       |
  770|  1.03k|		iMethod = SC_AC_NONE;		/* default no authentication required */
  ------------------
  |  |  150|  1.03k|#define SC_AC_NONE			0x00000000
  ------------------
  771|       |
  772|  1.03k|		if (buf[iOffset] & 0X80) { /* AC in adaptive coding */
  ------------------
  |  Branch (772:7): [True: 472, False: 567]
  ------------------
  773|       |			/* Evaluates only the command-byte, not the optional P1/P2/Option bytes */
  774|    472|			size_t	iParmLen = 1;			/* command-byte is always present */
  775|    472|			size_t	iKeyLen  = 0;			/* Encryption key is optional */
  776|       |
  777|    472|			if (buf[iOffset]   & 0x20) iKeyLen++;
  ------------------
  |  Branch (777:8): [True: 266, False: 206]
  ------------------
  778|    472|			if (buf[iOffset+1] & 0x40) iParmLen++;
  ------------------
  |  Branch (778:8): [True: 205, False: 267]
  ------------------
  779|    472|			if (buf[iOffset+1] & 0x20) iParmLen++;
  ------------------
  |  Branch (779:8): [True: 229, False: 243]
  ------------------
  780|    472|			if (buf[iOffset+1] & 0x10) iParmLen++;
  ------------------
  |  Branch (780:8): [True: 203, False: 269]
  ------------------
  781|    472|			if (buf[iOffset+1] & 0x08) iParmLen++;
  ------------------
  |  Branch (781:8): [True: 47, False: 425]
  ------------------
  782|       |
  783|       |			/* Get KeyNumber if available */
  784|    472|			if(iKeyLen) {
  ------------------
  |  Branch (784:7): [True: 266, False: 206]
  ------------------
  785|    266|				int iSC;
  786|    266|				if (len < 1 + iACLen)
  ------------------
  |  Branch (786:9): [True: 0, False: 266]
  ------------------
  787|      0|					break;
  788|    266|				iSC = buf[iOffset+iACLen];
  789|       |
  790|    266|				switch( (iSC>>5) & 0x03 ){
  ------------------
  |  Branch (790:13): [True: 266, False: 0]
  ------------------
  791|     29|				case 0:
  ------------------
  |  Branch (791:5): [True: 29, False: 237]
  ------------------
  792|     29|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     29|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  793|     29|					break;
  794|    117|				case 1:
  ------------------
  |  Branch (794:5): [True: 117, False: 149]
  ------------------
  795|    117|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|    117|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  796|    117|					break;
  797|     19|				case 2:
  ------------------
  |  Branch (797:5): [True: 19, False: 247]
  ------------------
  798|    120|				case 3:
  ------------------
  |  Branch (798:5): [True: 101, False: 165]
  ------------------
  799|    120|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|    120|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  800|    120|					break;
  801|    266|				}
  802|    266|				iKeyRef = iSC & 0x1F;			/* get key number */
  803|    266|			}
  804|       |
  805|       |			/* Get PinNumber if available */
  806|    472|			if (iACLen > (1+iParmLen+iKeyLen)) {  /* check via total length if pin is present */
  ------------------
  |  Branch (806:8): [True: 42, False: 430]
  ------------------
  807|     42|				if (len < 1+1+1+(size_t)iParmLen)
  ------------------
  |  Branch (807:9): [True: 0, False: 42]
  ------------------
  808|      0|					break;
  809|     42|				iKeyRef = buf[iOffset+1+1+iParmLen];  /* PTL + AM-header + parameter-bytes */
  810|     42|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     42|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  811|     42|			}
  812|       |
  813|       |			/* Convert SETCOS command to OpenSC command group */
  814|    472|			if (len < 1+2)
  ------------------
  |  Branch (814:8): [True: 5, False: 467]
  ------------------
  815|      5|				break;
  816|    467|			switch(buf[iOffset+2]){
  817|     12|			case 0x2A:			/* crypto operation */
  ------------------
  |  Branch (817:4): [True: 12, False: 455]
  ------------------
  818|     12|				iOperation = SC_AC_OP_CRYPTO;
  ------------------
  |  |  173|     12|#define SC_AC_OP_CRYPTO			7
  ------------------
  819|     12|				break;
  820|     18|			case 0x46:			/* key-generation operation */
  ------------------
  |  Branch (820:4): [True: 18, False: 449]
  ------------------
  821|     18|				iOperation = SC_AC_OP_UPDATE;
  ------------------
  |  |  189|     18|#define SC_AC_OP_UPDATE			23
  ------------------
  822|     18|				break;
  823|    437|			default:
  ------------------
  |  Branch (823:4): [True: 437, False: 30]
  ------------------
  824|    437|				iOperation = SC_AC_OP_SELECT;
  ------------------
  |  |  166|    437|#define SC_AC_OP_SELECT			0
  ------------------
  825|    437|				break;
  826|    467|			}
  827|    467|			sc_file_add_acl_entry(file, iOperation, iMethod, iKeyRef);
  828|    467|		}
  829|    567|		else { /* AC in simple coding */
  830|       |			   /* Initial AC is treated as an operational AC */
  831|       |
  832|       |			/* Get specific Cmd groups for specified file-type */
  833|    567|			switch (file->type) {
  834|     79|			case SC_FILE_TYPE_DF:            /* DF */
  ------------------
  |  |  214|     79|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (834:4): [True: 79, False: 488]
  ------------------
  835|     79|				p_idx = df_idx;
  836|     79|				break;
  837|     72|			case SC_FILE_TYPE_INTERNAL_EF:   /* EF for RSA keys */
  ------------------
  |  |  215|     72|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  |  Branch (837:4): [True: 72, False: 495]
  ------------------
  838|     72|				p_idx = efi_idx;
  839|     72|				break;
  840|    416|			default:                         /* EF */
  ------------------
  |  Branch (840:4): [True: 416, False: 151]
  ------------------
  841|    416|				p_idx = ef_idx;
  842|    416|				break;
  843|    567|			}
  844|       |
  845|       |			/* Encryption key present ? */
  846|    567|			iPinCount = iACLen > 0 ? (int)iACLen - 1 : 0;
  ------------------
  |  Branch (846:16): [True: 159, False: 408]
  ------------------
  847|       |
  848|    567|			if (buf[iOffset] & 0x20) {
  ------------------
  |  Branch (848:8): [True: 297, False: 270]
  ------------------
  849|    297|				int iSC;
  850|    297|				if (len < 1 + (size_t)iACLen)
  ------------------
  |  Branch (850:9): [True: 0, False: 297]
  ------------------
  851|      0|					break;
  852|    297|				iSC = buf[iOffset + iACLen];
  853|       |
  854|    297|				switch( (iSC>>5) & 0x03 ) {
  ------------------
  |  Branch (854:13): [True: 297, False: 0]
  ------------------
  855|     34|				case 0:
  ------------------
  |  Branch (855:5): [True: 34, False: 263]
  ------------------
  856|     34|					iMethod = SC_AC_TERM;		/* key authentication */
  ------------------
  |  |  152|     34|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  857|     34|					break;
  858|    120|				case 1:
  ------------------
  |  Branch (858:5): [True: 120, False: 177]
  ------------------
  859|    120|					iMethod = SC_AC_AUT;		/* key authentication  */
  ------------------
  |  |  154|    120|#define SC_AC_AUT			0x00000008 /* Key auth. */
  ------------------
  860|    120|					break;
  861|     12|				case 2:
  ------------------
  |  Branch (861:5): [True: 12, False: 285]
  ------------------
  862|    143|				case 3:
  ------------------
  |  Branch (862:5): [True: 131, False: 166]
  ------------------
  863|    143|					iMethod = SC_AC_PRO;		/* secure messaging */
  ------------------
  |  |  153|    143|#define SC_AC_PRO			0x00000004 /* Secure Messaging */
  ------------------
  864|    143|					break;
  865|    297|				}
  866|    297|				iKeyRef = iSC & 0x1F;			/* get key number */
  867|       |
  868|    297|				iPinCount--;				/* one byte used for keyReference  */
  869|    297|			}
  870|       |
  871|       |			/* Pin present ? */
  872|    567|			if ( iPinCount > 0 ) {
  ------------------
  |  Branch (872:9): [True: 83, False: 484]
  ------------------
  873|     83|				if (len < 1 + 2)
  ------------------
  |  Branch (873:9): [True: 0, False: 83]
  ------------------
  874|      0|					break;
  875|     83|				iKeyRef = buf[iOffset + 2];	/* pin ref */
  876|     83|				iMethod = SC_AC_CHV;
  ------------------
  |  |  151|     83|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  877|     83|			}
  878|       |
  879|       |			/* Add AC for each command-operationType into OpenSc structure */
  880|    567|			bValue = buf[iOffset + 1];
  881|  5.10k|			for (i = 0; i < 8; i++) {
  ------------------
  |  Branch (881:16): [True: 4.53k, False: 567]
  ------------------
  882|  4.53k|				if((bValue & 1) && (p_idx[i] >= 0))
  ------------------
  |  Branch (882:8): [True: 1.02k, False: 3.50k]
  |  Branch (882:24): [True: 678, False: 349]
  ------------------
  883|    678|					sc_file_add_acl_entry(file, p_idx[i], iMethod, iKeyRef);
  884|  4.53k|				bValue >>= 1;
  885|  4.53k|			}
  886|    567|		}
  887|       |		/* Current field treated, get next AC sub-field */
  888|  1.03k|		iOffset += iACLen +1;		/* AC + PTL-byte */
  889|  1.03k|		len     -= iACLen +1;
  890|  1.03k|	}
  891|    188|}
card-setcos.c:parse_sec_attr:
  712|     46|{
  713|     46|	int i;
  714|     46|	int idx[6];
  715|       |
  716|     46|	if (len < 6)
  ------------------
  |  Branch (716:6): [True: 14, False: 32]
  ------------------
  717|     14|		return;
  718|     32|	if (file->type == SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|     32|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (718:6): [True: 5, False: 27]
  ------------------
  719|      5|		const int df_idx[6] = {
  720|      5|			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  166|      5|#define SC_AC_OP_SELECT			0
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  167|      5|#define SC_AC_OP_LOCK			1
  ------------------
              			SC_AC_OP_SELECT, SC_AC_OP_LOCK, SC_AC_OP_DELETE,
  ------------------
  |  |  168|      5|#define SC_AC_OP_DELETE			2
  ------------------
  721|      5|			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  169|      5|#define SC_AC_OP_CREATE			3
  ------------------
              			SC_AC_OP_CREATE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|      5|#define SC_AC_OP_REHABILITATE		4
  ------------------
  722|      5|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|      5|#define SC_AC_OP_INVALIDATE		5
  ------------------
  723|      5|		};
  724|     35|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (724:15): [True: 30, False: 5]
  ------------------
  725|     30|			idx[i] = df_idx[i];
  726|     27|	} else {
  727|     27|		const int ef_idx[6] = {
  728|     27|			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  188|     27|#define SC_AC_OP_READ			22
  ------------------
              			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  189|     27|#define SC_AC_OP_UPDATE			23
  ------------------
              			SC_AC_OP_READ, SC_AC_OP_UPDATE, SC_AC_OP_WRITE,
  ------------------
  |  |  190|     27|#define SC_AC_OP_WRITE			24
  ------------------
  729|     27|			SC_AC_OP_ERASE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  202|     27|#define SC_AC_OP_ERASE			SC_AC_OP_DELETE
  |  |  ------------------
  |  |  |  |  168|     27|#define SC_AC_OP_DELETE			2
  |  |  ------------------
  ------------------
              			SC_AC_OP_ERASE, SC_AC_OP_REHABILITATE,
  ------------------
  |  |  170|     27|#define SC_AC_OP_REHABILITATE		4
  ------------------
  730|     27|			SC_AC_OP_INVALIDATE
  ------------------
  |  |  171|     27|#define SC_AC_OP_INVALIDATE		5
  ------------------
  731|     27|		};
  732|    189|		for (i = 0; i < 6; i++)
  ------------------
  |  Branch (732:15): [True: 162, False: 27]
  ------------------
  733|    162|			idx[i] = ef_idx[i];
  734|     27|	}
  735|    224|	for (i = 0; i < 6; i++)
  ------------------
  |  Branch (735:14): [True: 192, False: 32]
  ------------------
  736|    192|		add_acl_entry(file, idx[i], buf[i]);
  737|     32|}
card-setcos.c:add_acl_entry:
  683|    192|{
  684|    192|	unsigned int method, key_ref = SC_AC_KEY_REF_NONE;
  ------------------
  |  |  204|    192|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  685|       |
  686|    192|	switch (byte >> 4) {
  687|     42|	case 0:
  ------------------
  |  Branch (687:2): [True: 42, False: 150]
  ------------------
  688|     42|		method = SC_AC_NONE;
  ------------------
  |  |  150|     42|#define SC_AC_NONE			0x00000000
  ------------------
  689|     42|		break;
  690|     10|	case 1:
  ------------------
  |  Branch (690:2): [True: 10, False: 182]
  ------------------
  691|     10|		method = SC_AC_CHV;
  ------------------
  |  |  151|     10|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  692|     10|		key_ref = 1;
  693|     10|		break;
  694|     22|	case 2:
  ------------------
  |  Branch (694:2): [True: 22, False: 170]
  ------------------
  695|     22|		method = SC_AC_CHV;
  ------------------
  |  |  151|     22|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  696|     22|		key_ref = 2;
  697|     22|		break;
  698|     20|	case 4:
  ------------------
  |  Branch (698:2): [True: 20, False: 172]
  ------------------
  699|     20|		method = SC_AC_TERM;
  ------------------
  |  |  152|     20|#define SC_AC_TERM			0x00000002 /* Terminal auth. */
  ------------------
  700|     20|		break;
  701|     42|	case 15:
  ------------------
  |  Branch (701:2): [True: 42, False: 150]
  ------------------
  702|     42|		method = SC_AC_NEVER;
  ------------------
  |  |  163|     42|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  703|     42|		break;
  704|     56|	default:
  ------------------
  |  Branch (704:2): [True: 56, False: 136]
  ------------------
  705|     56|		method = SC_AC_UNKNOWN;
  ------------------
  |  |  162|     56|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  706|     56|		break;
  707|    192|	}
  708|    192|	sc_file_add_acl_entry(file, op, method, key_ref);
  709|    192|}
card-setcos.c:setcos_process_fci:
  936|    229|{
  937|    229|	int r = iso_ops->process_fci(card, file, buf, buflen);
  938|       |
  939|       |	/* SetCOS 4.4: RSA key file is an internal EF but it's
  940|       |	 * file descriptor doesn't seem to follow ISO7816. */
  941|    229|	if (r >= 0 && (card->type == SC_CARD_TYPE_SETCOS_44 ||
  ------------------
  |  Branch (941:6): [True: 229, False: 0]
  |  Branch (941:17): [True: 21, False: 208]
  ------------------
  942|    208|	               SETCOS_IS_EID_APPLET(card))) {
  ------------------
  |  |   46|    208|#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: 128, False: 80]
  |  |  |  Branch (46:85): [True: 28, False: 52]
  |  |  ------------------
  ------------------
  943|    177|		const u8 *tag;
  944|    177|		size_t taglen = 1;
  945|    177|		tag = (u8 *) sc_asn1_find_tag(card->ctx, buf, buflen, 0x82, &taglen);
  946|    177|		if (tag != NULL && taglen == 1 && *tag == 0x11)
  ------------------
  |  Branch (946:7): [True: 34, False: 143]
  |  Branch (946:22): [True: 25, False: 9]
  |  Branch (946:37): [True: 4, False: 21]
  ------------------
  947|      4|			file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|      4|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  948|    177|	}
  949|       |
  950|    229|	return r;
  951|    229|}
card-setcos.c:setcos_card_ctl:
 1086|      6|{
 1087|      6|	if (card->type != SC_CARD_TYPE_SETCOS_44 && !SETCOS_IS_EID_APPLET(card))
  ------------------
  |  |   46|      5|#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: 4]
  |  |  |  Branch (46:85): [True: 1, False: 3]
  |  |  ------------------
  ------------------
  |  Branch (1087:6): [True: 5, False: 1]
  ------------------
 1088|      3|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      3|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1089|       |
 1090|      3|	switch(cmd) {
  ------------------
  |  Branch (1090:9): [True: 0, False: 3]
  ------------------
 1091|      0|	case SC_CARDCTL_SETCOS_PUTDATA:
  ------------------
  |  Branch (1091:2): [True: 0, False: 3]
  ------------------
 1092|      0|		return setcos_putdata(card,
 1093|      0|				(struct sc_cardctl_setcos_data_obj*) ptr);
 1094|      0|		break;
 1095|      0|	case SC_CARDCTL_SETCOS_GETDATA:
  ------------------
  |  Branch (1095:2): [True: 0, False: 3]
  ------------------
 1096|      0|		return setcos_getdata(card,
 1097|      0|				(struct sc_cardctl_setcos_data_obj*) ptr);
 1098|      0|		break;
 1099|      0|	case SC_CARDCTL_SETCOS_GENERATE_STORE_KEY:
  ------------------
  |  Branch (1099:2): [True: 0, False: 3]
  ------------------
 1100|      0|		return setcos_generate_store_key(card,
 1101|      0|				(struct sc_cardctl_setcos_gen_store_key_info *) ptr);
 1102|      0|	case SC_CARDCTL_SETCOS_ACTIVATE_FILE:
  ------------------
  |  Branch (1102:2): [True: 0, False: 3]
  ------------------
 1103|      0|		return setcos_activate_file(card);
 1104|      3|	}
 1105|       |
 1106|      3|	return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      3|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1107|      3|}

sc_get_skeid_driver:
  179|  15.3k|{
  180|  15.3k|	if (iso_ops == NULL) iso_ops = sc_get_iso7816_driver()->ops;
  ------------------
  |  Branch (180:6): [True: 1, False: 15.3k]
  ------------------
  181|  15.3k|	skeid_ops = *iso_ops;
  182|  15.3k|	skeid_ops.match_card = skeid_match_card;
  183|  15.3k|	skeid_ops.init = skeid_init;
  184|  15.3k|	skeid_ops.set_security_env = skeid_set_security_env;
  185|  15.3k|	skeid_ops.logout = skeid_logout;
  186|  15.3k|	return &skeid_drv;
  187|  15.3k|}
card-skeid.c:skeid_match_card:
   73|  14.4k|{
   74|  14.4k|	if (_sc_match_atr(card, skeid_atrs, &card->type) < 0 || skeid_known_url(card) != SC_SUCCESS)
  ------------------
  |  |   28|    101|#define SC_SUCCESS				0
  ------------------
  |  Branch (74:6): [True: 14.3k, False: 101]
  |  Branch (74:58): [True: 78, False: 23]
  ------------------
   75|  14.4k|		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|  14.4k|}
card-skeid.c:skeid_known_url:
   53|    101|{
   54|    101|	const struct sc_aid skeid_aid_eid = {{0xE8, 0x07, 0x04, 0x00, 0x7F, 0x00, 0x07, 0x03, 0x02}, 9};
   55|    101|	const char *known_url = "\x80\x01\x00\x5F\x50\x28http://www.minv.sk/cif/cif-sk-eid-v3.xml";
   56|    101|	u8 buf[SKEID_KNOWN_URL_LEN];
   57|       |
   58|    101|	sc_path_t url_path;
   59|       |
   60|    101|	int r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    101|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
   61|       |
   62|    101|	sc_path_set(&url_path, SC_PATH_TYPE_DF_NAME, skeid_aid_eid.value, skeid_aid_eid.len, 0, 0);
  ------------------
  |  |  118|    101|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
   63|       |
   64|    101|	if (sc_select_file(card, &url_path, NULL) == SC_SUCCESS
  ------------------
  |  |   28|    202|#define SC_SUCCESS				0
  ------------------
  |  Branch (64:6): [True: 42, False: 59]
  ------------------
   65|     42|		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|     42|#define SKEID_KNOWN_URL_LEN 46
  ------------------
              		&& sc_get_data(card, 0x7F62, buf, SKEID_KNOWN_URL_LEN) == SKEID_KNOWN_URL_LEN
  ------------------
  |  |   30|    143|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (65:6): [True: 32, False: 10]
  ------------------
   66|     32|		&& !memcmp(buf, known_url, SKEID_KNOWN_URL_LEN))
  ------------------
  |  |   30|     32|#define SKEID_KNOWN_URL_LEN 46
  ------------------
  |  Branch (66:6): [True: 23, False: 9]
  ------------------
   67|     23|		r = SC_SUCCESS;
  ------------------
  |  |   28|     23|#define SC_SUCCESS				0
  ------------------
   68|       |
   69|    101|	return r;
   70|    101|}
card-skeid.c:skeid_init:
  108|     23|{
  109|     23|	const unsigned long flags = SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE;
  ------------------
  |  |  120|     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) */
  |  |  ------------------
  |  |  |  |  118|     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) */
  |  |  ------------------
  |  |  |  |  119|     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;
  ------------------
  |  |  142|     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;
  ------------------
  |  |  554|     16|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
              	card->caps |= SC_CARD_CAP_APDU_EXT | SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|     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: 1, False: 22]
  |  |  |  |  ------------------
  |  |  |  |  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|     23|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 22]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   94|     22|	if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
  ------------------
  |  Branch (94:6): [True: 3, False: 19]
  |  Branch (94:26): [True: 1, False: 18]
  ------------------
   95|      4|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      4|#define SC_ERROR_INTERNAL			-1400
  ------------------
   96|     18|	if (apdu.resplen == 8) {
  ------------------
  |  Branch (96:6): [True: 16, False: 2]
  ------------------
   97|       |		/* cache serial number */
   98|     16|		memcpy(card->serialnr.value, rbuf, 8);
   99|     16|		card->serialnr.len = 8;
  100|     16|	} else {
  101|      2|		sc_log(card->ctx, "unexpected response to GET DATA serial number");
  ------------------
  |  |   71|      2|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  102|      2|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      2|#define SC_ERROR_INTERNAL			-1400
  ------------------
  103|      2|	}
  104|     16|	return SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
  105|     18|}
card-skeid.c:skeid_set_security_env:
  146|     47|{
  147|     47|	int key_id;
  148|     47|	int r;
  149|       |
  150|     47|	if (card == NULL || env == NULL)
  ------------------
  |  Branch (150:6): [True: 0, False: 47]
  |  Branch (150:22): [True: 0, False: 47]
  ------------------
  151|      0|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|      0|#define SC_ERROR_INTERNAL			-1400
  ------------------
  152|       |
  153|     47|	if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT) || env->key_ref_len != 1) {
  ------------------
  |  |   67|     47|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (153:6): [True: 0, False: 47]
  |  Branch (153:52): [True: 0, False: 47]
  ------------------
  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|     47|	key_id = env->key_ref[0];
  162|     47|	r = sc_restore_security_env(card, key_id);
  163|       |
  164|     47|	return r;
  165|     47|}

sc_get_srbeid_driver:
  301|  15.3k|{
  302|       |	/* Save ISO ops for delegation, then override what we handle. */
  303|  15.3k|	iso_ops = sc_get_iso7816_driver()->ops;
  304|  15.3k|	srbeid_ops = *iso_ops;
  305|  15.3k|	srbeid_ops.match_card = srbeid_match_card;
  306|  15.3k|	srbeid_ops.init = srbeid_init;
  307|  15.3k|	srbeid_ops.select_file = srbeid_select_file;
  308|  15.3k|	srbeid_ops.set_security_env = srbeid_set_security_env;
  309|  15.3k|	srbeid_ops.compute_signature = srbeid_compute_signature;
  310|  15.3k|	srbeid_ops.decipher = srbeid_decipher;
  311|       |
  312|  15.3k|	return &srbeid_drv;
  313|  15.3k|}
card-srbeid.c:srbeid_match_card:
   71|  6.84k|{
   72|  6.84k|	int i = _sc_match_atr(card, srbeid_atrs, &card->type);
   73|  6.84k|	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   30|    416|#define AID_PKCS15_LEN (sizeof(AID_PKCS15))
  ------------------
              	if (i >= 0 && iso7816_select_aid(card, AID_PKCS15, AID_PKCS15_LEN, NULL, NULL) == SC_SUCCESS) {
  ------------------
  |  |   28|    416|#define SC_SUCCESS				0
  ------------------
  |  Branch (73:6): [True: 416, False: 6.42k]
  |  Branch (73:16): [True: 180, False: 236]
  ------------------
   74|    180|		card->name = srbeid_atrs[i].name;
   75|    180|		return 1;
   76|    180|	}
   77|  6.66k|	return 0;
   78|  6.84k|}
card-srbeid.c:srbeid_init:
   82|    180|{
   83|    180|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    180|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    180|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    180|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    180|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 180]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   84|       |
   85|    180|	card->caps |= SC_CARD_CAP_ISO7816_PIN_INFO;
  ------------------
  |  |  560|    180|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
   86|       |
   87|    180|	_sc_card_add_rsa_alg(card, 2048,
   88|    180|			SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_HASH_NONE, 0);
  ------------------
  |  |  120|    180|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|    180|#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) */
  |  |  ------------------
  |  |  |  |  119|    180|#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);
  ------------------
  |  |  142|    180|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
   89|       |
   90|    180|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   91|    180|}
card-srbeid.c:srbeid_select_file:
  107|  1.32k|{
  108|  1.32k|	sc_apdu_t apdu;
  109|  1.32k|	u8 fci[16];
  110|  1.32k|	sc_file_t *file;
  111|  1.32k|	int r;
  112|       |
  113|  1.32k|	if (in_path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  1.32k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (113:6): [True: 392, False: 929]
  ------------------
  114|    392|		return iso_ops->select_file(card, in_path, file_out);
  115|       |
  116|       |	/* AID-only path (path.len==0, path.aid.len>0): PKCS#15 layer wants
  117|       |	 * to select the applet before a PIN or key operation. */
  118|    929|	if (in_path->len == 0 && in_path->aid.len > 0)
  ------------------
  |  Branch (118:6): [True: 49, False: 880]
  |  Branch (118:27): [True: 49, False: 0]
  ------------------
  119|     49|		return iso7816_select_aid(card, in_path->aid.value,
  120|     49|				in_path->aid.len, NULL, NULL);
  121|       |
  122|    880|	if (in_path->len != 2)
  ------------------
  |  Branch (122:6): [True: 540, False: 340]
  ------------------
  123|    880|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  164|    540|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    540|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    540|	int _ret = r; \
  |  |  |  |  155|    540|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 540, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    540|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    540|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 540, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    540|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    540|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    540|	return _ret; \
  |  |  |  |  163|    540|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  124|       |
  125|    340|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0x00, 0x00);
  ------------------
  |  |  294|    340|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  126|    340|	apdu.data = in_path->value;
  127|    340|	apdu.datalen = 2;
  128|    340|	apdu.lc = 2;
  129|    340|	apdu.resp = fci;
  130|    340|	apdu.resplen = sizeof(fci);
  131|    340|	apdu.le = 10;
  132|       |
  133|    340|	r = sc_transmit_apdu(card, &apdu);
  134|    340|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    340|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    340|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    340|	int _ret = (r); \
  |  |  |  |  168|    340|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 16, False: 324]
  |  |  |  |  ------------------
  |  |  |  |  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|    340|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 324]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  135|    324|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  136|    324|	LOG_TEST_RET(card->ctx, r, "SELECT FILE failed");
  ------------------
  |  |  174|    324|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    324|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    324|	int _ret = (r); \
  |  |  |  |  168|    324|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 89, False: 235]
  |  |  |  |  ------------------
  |  |  |  |  169|     89|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     89|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     89|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     89|		return _ret; \
  |  |  |  |  172|     89|	} \
  |  |  |  |  173|    324|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 235]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  137|       |
  138|    235|	if (apdu.resplen < 4)
  ------------------
  |  Branch (138:6): [True: 8, False: 227]
  ------------------
  139|    235|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  140|       |
  141|    227|	if (file_out) {
  ------------------
  |  Branch (141:6): [True: 174, False: 53]
  ------------------
  142|    174|		file = sc_file_new();
  143|    174|		if (!file)
  ------------------
  |  Branch (143:7): [True: 0, False: 174]
  ------------------
  144|    174|			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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  145|       |
  146|    174|		file->id = ((unsigned)in_path->value[0] << 8) | in_path->value[1];
  147|    174|		file->path = *in_path;
  148|    174|		file->size = ((size_t)fci[2] << 8) | (size_t)fci[3];
  149|    174|		file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|    174|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  150|    174|		*file_out = file;
  151|    174|	}
  152|       |
  153|    227|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 227]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  154|    227|}
card-srbeid.c:srbeid_set_security_env:
  172|    135|{
  173|    135|	sc_apdu_t apdu;
  174|    135|	u8 mse_data[7];
  175|    135|	unsigned key_ref;
  176|    135|	u8 p2;
  177|    135|	int r;
  178|       |
  179|    135|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    135|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    135|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    135|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    135|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 135]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  180|    135|	(void)se_num;
  181|       |
  182|       |	/* Extract key FID. */
  183|    135|	if ((env->flags & SC_SEC_ENV_FILE_REF_PRESENT) && env->file_ref.len >= 2) {
  ------------------
  |  |   66|    135|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (183:6): [True: 0, False: 135]
  |  Branch (183:52): [True: 0, False: 0]
  ------------------
  184|      0|		key_ref = ((unsigned)env->file_ref.value[0] << 8) | (unsigned)env->file_ref.value[1];
  185|    135|	} else if ((env->flags & SC_SEC_ENV_KEY_REF_PRESENT) && env->key_ref_len >= 1) {
  ------------------
  |  |   67|    135|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (185:13): [True: 135, False: 0]
  |  Branch (185:58): [True: 135, False: 0]
  ------------------
  186|    135|		key_ref = CE_KEYS_BASE_FID | (unsigned)env->key_ref[0];
  ------------------
  |  |   33|    135|#define CE_KEYS_BASE_FID 0x6000u
  ------------------
  187|    135|	} else {
  188|      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__
  |  |  ------------------
  ------------------
  189|      0|		return SC_ERROR_INCORRECT_PARAMETERS;
  ------------------
  |  |   55|      0|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  190|      0|	}
  191|       |
  192|       |	/* Determine MSE SET template from operation type. */
  193|    135|	switch (env->operation) {
  194|    108|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|    108|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (194:2): [True: 108, False: 27]
  ------------------
  195|    108|		p2 = 0xB6;
  196|    108|		break;
  197|     27|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|     27|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (197:2): [True: 27, False: 108]
  ------------------
  198|     27|		p2 = 0xB8;
  199|     27|		break;
  200|      0|	default:
  ------------------
  |  Branch (200:2): [True: 0, False: 135]
  ------------------
  201|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  202|    135|	}
  203|       |
  204|       |	/* MSE SET: tag 0x80 = algorithm (RSA2048), tag 0x84 = key ref (2 bytes BE) */
  205|    135|	mse_data[0] = 0x80;
  206|    135|	mse_data[1] = 0x01;
  207|    135|	mse_data[2] = CE_MSE_ALG_RSA2048;
  ------------------
  |  |   36|    135|#define CE_MSE_ALG_RSA2048 0x02u
  ------------------
  208|    135|	mse_data[3] = 0x84;
  209|    135|	mse_data[4] = 0x02;
  210|    135|	mse_data[5] = (u8)((key_ref >> 8) & 0xFF);
  211|    135|	mse_data[6] = (u8)(key_ref & 0xFF);
  212|       |
  213|    135|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, p2);
  ------------------
  |  |  293|    135|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  214|    135|	apdu.data = mse_data;
  215|    135|	apdu.datalen = sizeof(mse_data);
  216|    135|	apdu.lc = sizeof(mse_data);
  217|       |
  218|    135|	r = sc_transmit_apdu(card, &apdu);
  219|    135|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    135|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    135|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    135|	int _ret = (r); \
  |  |  |  |  168|    135|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 12, False: 123]
  |  |  |  |  ------------------
  |  |  |  |  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|    135|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 123]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  220|    123|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  221|    123|	LOG_TEST_RET(card->ctx, r, "MSE SET failed");
  ------------------
  |  |  174|    123|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    123|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    123|	int _ret = (r); \
  |  |  |  |  168|    123|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 67, False: 56]
  |  |  |  |  ------------------
  |  |  |  |  169|     67|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     67|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     67|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     67|		return _ret; \
  |  |  |  |  172|     67|	} \
  |  |  |  |  173|    123|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 56]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  222|       |
  223|     56|	sc_log(card->ctx, "srbeid: set_security_env: key_ref=0x%04x p2=0x%02x", key_ref, p2);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  224|     56|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  225|     56|}
card-srbeid.c:srbeid_compute_signature:
  237|     44|{
  238|     44|	sc_apdu_t apdu;
  239|     44|	u8 resp[256];
  240|     44|	int r;
  241|       |
  242|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  243|       |
  244|     44|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x9E, 0x00);
  ------------------
  |  |  294|     44|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  245|     44|	apdu.data = data;
  246|     44|	apdu.datalen = datalen;
  247|     44|	apdu.lc = datalen;
  248|     44|	apdu.resp = resp;
  249|     44|	apdu.resplen = sizeof(resp);
  250|     44|	apdu.le = sizeof(resp);
  251|       |
  252|     44|	r = sc_transmit_apdu(card, &apdu);
  253|     44|	LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 10, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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|     44|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  254|     34|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  255|     34|	LOG_TEST_RET(card->ctx, r, "PSO COMPUTE DIGITAL SIGNATURE failed");
  ------------------
  |  |  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: 8, False: 26]
  |  |  |  |  ------------------
  |  |  |  |  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|     34|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  256|       |
  257|     26|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (257:6): [True: 0, False: 26]
  ------------------
  258|     26|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  259|     26|	memcpy(out, resp, apdu.resplen);
  260|     26|	LOG_FUNC_RETURN(card->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: 11, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  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|     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|     26|	return _ret; \
  |  |  |  |  163|     26|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  261|     26|}
card-srbeid.c:srbeid_decipher:
  273|     12|{
  274|     12|	sc_apdu_t apdu;
  275|     12|	u8 resp[256];
  276|     12|	int r;
  277|       |
  278|     12|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     12|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     12|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     12|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     12|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|     12|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x80, 0x86);
  ------------------
  |  |  294|     12|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  281|     12|	apdu.data = crgram;
  282|     12|	apdu.datalen = crgram_len;
  283|     12|	apdu.lc = crgram_len;
  284|     12|	apdu.resp = resp;
  285|     12|	apdu.resplen = sizeof(resp);
  286|     12|	apdu.le = sizeof(resp);
  287|       |
  288|     12|	r = sc_transmit_apdu(card, &apdu);
  289|     12|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     12|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     12|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     12|	int _ret = (r); \
  |  |  |  |  168|     12|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 9]
  |  |  |  |  ------------------
  |  |  |  |  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|     12|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  290|      9|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  291|      9|	LOG_TEST_RET(card->ctx, r, "PSO DECIPHER failed");
  ------------------
  |  |  174|      9|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      9|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      9|	int _ret = (r); \
  |  |  |  |  168|      9|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1, False: 8]
  |  |  |  |  ------------------
  |  |  |  |  169|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      1|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      1|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      1|		return _ret; \
  |  |  |  |  172|      1|	} \
  |  |  |  |  173|      9|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 8]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  292|       |
  293|      8|	if (apdu.resplen > outlen)
  ------------------
  |  Branch (293:6): [True: 0, False: 8]
  ------------------
  294|      8|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  295|      8|	memcpy(out, resp, apdu.resplen);
  296|      8|	LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 1, False: 7]
  |  |  |  |  ------------------
  |  |  |  |  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|      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|      8|	return _ret; \
  |  |  |  |  163|      8|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  297|      8|}

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

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

sc_check_sw:
   45|   456k|{
   46|   456k|	if (card == NULL)
  ------------------
  |  Branch (46:6): [True: 0, False: 456k]
  ------------------
   47|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   48|   456k|	if (card->ops->check_sw == NULL)
  ------------------
  |  Branch (48:6): [True: 0, False: 456k]
  ------------------
   49|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
   50|   456k|	return card->ops->check_sw(card, sw1, sw2);
   51|   456k|}
sc_format_apdu:
   55|   517k|{
   56|   517k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (56:6): [True: 0, False: 517k]
  |  Branch (56:22): [True: 0, False: 517k]
  ------------------
   57|      0|		return;
   58|      0|	}
   59|   517k|	memset(apdu, 0, sizeof(*apdu));
   60|   517k|	apdu->cla = (u8) card->cla;
   61|   517k|	apdu->cse = cse;
   62|   517k|	apdu->ins = (u8) ins;
   63|   517k|	apdu->p1 = (u8) p1;
   64|   517k|	apdu->p2 = (u8) p2;
   65|   517k|}
sc_format_apdu_cse_lc_le:
   68|  9.82k|{
   69|       |	/* TODO calculating the APDU case, Lc and Le should actually only be
   70|       |	 * done in sc_apdu2bytes, but to gradually change OpenSC we start here. */
   71|       |	/* Let sc_detect_apdu_cse set short or extended  and test for chaining */
   72|       |
   73|  9.82k|	if (!apdu)
  ------------------
  |  Branch (73:6): [True: 0, False: 9.82k]
  ------------------
   74|      0|		return;
   75|  9.82k|	if (apdu->datalen > SC_MAX_APDU_DATA_SIZE
  ------------------
  |  |   35|  19.6k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (75:6): [True: 254, False: 9.56k]
  ------------------
   76|  9.56k|			|| apdu->resplen > SC_MAX_APDU_RESP_SIZE) {
  ------------------
  |  |   36|  9.56k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (76:7): [True: 641, False: 8.92k]
  ------------------
   77|       |		/* extended length  or data chaining and/or get response */
   78|    895|		if (apdu->datalen <= SC_MAX_EXT_APDU_DATA_SIZE)
  ------------------
  |  |   38|    895|#define SC_MAX_EXT_APDU_DATA_SIZE		0xFFFF
  ------------------
  |  Branch (78:7): [True: 895, False: 0]
  ------------------
   79|    895|			apdu->lc = apdu->datalen;
   80|    895|		if (apdu->resplen <= SC_MAX_EXT_APDU_RESP_SIZE)
  ------------------
  |  |   39|    895|#define SC_MAX_EXT_APDU_RESP_SIZE		(0xFFFF+1)
  ------------------
  |  Branch (80:7): [True: 895, False: 0]
  ------------------
   81|    895|			apdu->le = apdu->resplen;
   82|    895|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (82:7): [True: 895, False: 0]
  |  Branch (82:24): [True: 354, False: 541]
  ------------------
   83|    354|			apdu->cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    354|#define SC_APDU_CASE_2			0x22
  ------------------
   84|    895|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (84:7): [True: 0, False: 895]
  |  Branch (84:25): [True: 0, False: 0]
  ------------------
   85|      0|			apdu->cse = SC_APDU_CASE_3;
  ------------------
  |  |  302|      0|#define SC_APDU_CASE_3			0x23
  ------------------
   86|    895|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (86:7): [True: 895, False: 0]
  |  Branch (86:24): [True: 541, False: 354]
  ------------------
   87|    541|			apdu->cse = SC_APDU_CASE_4;
  ------------------
  |  |  303|    541|#define SC_APDU_CASE_4			0x24
  ------------------
   88|  8.92k|	} else {
   89|       |		/* short length */
   90|  8.92k|		if (apdu->datalen <= SC_MAX_APDU_DATA_SIZE)
  ------------------
  |  |   35|  8.92k|#define SC_MAX_APDU_DATA_SIZE		0xFF
  ------------------
  |  Branch (90:7): [True: 8.92k, False: 0]
  ------------------
   91|  8.92k|			apdu->lc = apdu->datalen;
   92|  8.92k|		if (apdu->resplen <= SC_MAX_APDU_RESP_SIZE)
  ------------------
  |  |   36|  8.92k|#define SC_MAX_APDU_RESP_SIZE		(0xFF+1)
  ------------------
  |  Branch (92:7): [True: 8.92k, False: 0]
  ------------------
   93|  8.92k|			apdu->le = apdu->resplen;
   94|  8.92k|		if (!apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (94:7): [True: 2.53k, False: 6.38k]
  |  Branch (94:25): [True: 4, False: 2.53k]
  ------------------
   95|      4|			apdu->cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      4|#define SC_APDU_CASE_1			0x01
  ------------------
   96|  8.92k|		if (apdu->resplen && !apdu->datalen)
  ------------------
  |  Branch (96:7): [True: 6.38k, False: 2.53k]
  |  Branch (96:24): [True: 3.82k, False: 2.56k]
  ------------------
   97|  3.82k|			apdu->cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|  3.82k|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
   98|  8.92k|		if (!apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (98:7): [True: 2.53k, False: 6.38k]
  |  Branch (98:25): [True: 2.53k, False: 4]
  ------------------
   99|  2.53k|			apdu->cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  2.53k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  100|  8.92k|		if (apdu->resplen && apdu->datalen)
  ------------------
  |  Branch (100:7): [True: 6.38k, False: 2.53k]
  |  Branch (100:24): [True: 2.56k, False: 3.82k]
  ------------------
  101|  2.56k|			apdu->cse = SC_APDU_CASE_4_SHORT;
  ------------------
  |  |  294|  2.56k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  102|  8.92k|	}
  103|  9.82k|}
sc_format_apdu_ex:
  109|  9.82k|{
  110|  9.82k|	if (!apdu) {
  ------------------
  |  Branch (110:6): [True: 0, False: 9.82k]
  ------------------
  111|      0|		return;
  112|      0|	}
  113|       |
  114|  9.82k|	memset(apdu, 0, sizeof(*apdu));
  115|  9.82k|	apdu->cla = cla;
  116|  9.82k|	apdu->ins = ins;
  117|  9.82k|	apdu->p1 = p1;
  118|  9.82k|	apdu->p2 = p2;
  119|  9.82k|	apdu->resp = resp;
  120|  9.82k|	apdu->resplen = resplen;
  121|  9.82k|	apdu->data = data;
  122|  9.82k|	apdu->datalen = datalen;
  123|  9.82k|	sc_format_apdu_cse_lc_le(apdu);
  124|  9.82k|}
sc_get_max_recv_size:
  188|   471k|{
  189|   471k|	size_t max_recv_size;
  190|   471k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (190:6): [True: 0, False: 471k]
  |  Branch (190:22): [True: 0, False: 471k]
  ------------------
  191|      0|		return 0;
  192|      0|	}
  193|   471k|	max_recv_size = card->max_recv_size;
  194|       |
  195|       |	/* initialize max_recv_size to a meaningful value */
  196|   471k|	if (card->caps & SC_CARD_CAP_APDU_EXT) {
  ------------------
  |  |  554|   471k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (196:6): [True: 46.1k, False: 425k]
  ------------------
  197|  46.1k|		if (!max_recv_size)
  ------------------
  |  Branch (197:7): [True: 2.11k, False: 44.0k]
  ------------------
  198|  2.11k|			max_recv_size = 65536;
  199|   425k|	} else {
  200|   425k|		if (!max_recv_size)
  ------------------
  |  Branch (200:7): [True: 144k, False: 281k]
  ------------------
  201|   144k|			max_recv_size = 256;
  202|   425k|	}
  203|       |
  204|       |	/*  Override card limitations with reader limitations. */
  205|   471k|	if (card->reader->max_recv_size != 0
  ------------------
  |  Branch (205:6): [True: 7.67k, False: 464k]
  ------------------
  206|  7.67k|			&& (card->reader->max_recv_size < card->max_recv_size))
  ------------------
  |  Branch (206:7): [True: 0, False: 7.67k]
  ------------------
  207|      0|		max_recv_size = card->reader->max_recv_size;
  208|       |
  209|   471k|	return max_recv_size;
  210|   471k|}
sc_get_max_send_size:
  213|  86.8k|{
  214|  86.8k|	size_t max_send_size;
  215|       |
  216|  86.8k|	if (card == NULL || card->reader == NULL) {
  ------------------
  |  Branch (216:6): [True: 0, False: 86.8k]
  |  Branch (216:22): [True: 0, False: 86.8k]
  ------------------
  217|      0|		return 0;
  218|      0|	}
  219|       |
  220|  86.8k|	max_send_size = card->max_send_size;
  221|       |
  222|       |	/* initialize max_send_size to a meaningful value */
  223|  86.8k|	if (card->caps & SC_CARD_CAP_APDU_EXT
  ------------------
  |  |  554|   173k|#define SC_CARD_CAP_APDU_EXT		0x00000001
  ------------------
  |  Branch (223:6): [True: 25.9k, False: 60.8k]
  ------------------
  224|  25.9k|			&& card->reader->active_protocol != SC_PROTO_T0) {
  ------------------
  |  |  359|  25.9k|#define SC_PROTO_T0		0x00000001
  ------------------
  |  Branch (224:7): [True: 25.9k, False: 0]
  ------------------
  225|  25.9k|		if (!max_send_size)
  ------------------
  |  Branch (225:7): [True: 1.55k, False: 24.3k]
  ------------------
  226|  1.55k|			max_send_size = 65535;
  227|  60.8k|	} else {
  228|  60.8k|		if (!max_send_size)
  ------------------
  |  Branch (228:7): [True: 13.1k, False: 47.7k]
  ------------------
  229|  13.1k|			max_send_size = 255;
  230|  60.8k|	}
  231|       |
  232|       |	/*  Override card limitations with reader limitations. */
  233|  86.8k|	if (card->reader->max_send_size != 0
  ------------------
  |  Branch (233:6): [True: 3, False: 86.7k]
  ------------------
  234|      3|			&& (card->reader->max_send_size < card->max_send_size))
  ------------------
  |  Branch (234:7): [True: 0, False: 3]
  ------------------
  235|      0|		max_send_size = card->reader->max_send_size;
  236|       |
  237|  86.8k|	return max_send_size;
  238|  86.8k|}
sc_connect_card:
  241|  15.3k|{
  242|  15.3k|	sc_card_t *card;
  243|  15.3k|	sc_context_t *ctx;
  244|  15.3k|	struct sc_card_driver *driver;
  245|  15.3k|	int i, r = 0, idx, connected = 0;
  246|       |
  247|  15.3k|	if (card_out == NULL || reader == NULL)
  ------------------
  |  Branch (247:6): [True: 0, False: 15.3k]
  |  Branch (247:26): [True: 0, False: 15.3k]
  ------------------
  248|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  249|  15.3k|	ctx = reader->ctx;
  250|  15.3k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  15.3k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  15.3k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  15.3k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 15.3k]
  |  |  ------------------
  ------------------
  251|  15.3k|	if (reader->ops->connect == NULL)
  ------------------
  |  Branch (251:6): [True: 0, False: 15.3k]
  ------------------
  252|  15.3k|		LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  253|       |
  254|  15.3k|	card = sc_card_new(ctx);
  255|  15.3k|	if (card == NULL)
  ------------------
  |  Branch (255:6): [True: 0, False: 15.3k]
  ------------------
  256|  15.3k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  257|  15.3k|	r = reader->ops->connect(reader);
  258|  15.3k|	if (r)
  ------------------
  |  Branch (258:6): [True: 0, False: 15.3k]
  ------------------
  259|      0|		goto err;
  260|       |
  261|  15.3k|	connected = 1;
  262|  15.3k|	card->reader = reader;
  263|  15.3k|	card->ctx = ctx;
  264|       |
  265|  15.3k|	if (reader->flags & SC_READER_ENABLE_ESCAPE)
  ------------------
  |  |  379|  15.3k|#define SC_READER_ENABLE_ESCAPE		0x00000040
  ------------------
  |  Branch (265:6): [True: 0, False: 15.3k]
  ------------------
  266|      0|		sc_detect_escape_cmds(reader);
  267|       |
  268|  15.3k|	memcpy(&card->atr, &reader->atr, sizeof(card->atr));
  269|  15.3k|	memcpy(&card->uid, &reader->uid, sizeof(card->uid));
  270|       |
  271|  15.3k|	_sc_parse_atr(reader);
  272|       |
  273|       |	/* See if the ATR matches any ATR specified in the config file */
  274|  15.3k|	if ((driver = ctx->forced_driver) == NULL) {
  ------------------
  |  Branch (274:6): [True: 15.3k, False: 0]
  ------------------
  275|  15.3k|		sc_log(ctx, "matching configured ATRs");
  ------------------
  |  |   71|  15.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  276|   690k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (276:15): [True: 675k, False: 15.3k]
  ------------------
  277|   675k|			driver = ctx->card_drivers[i];
  278|       |
  279|   675k|			if (driver->atr_map == NULL ||
  ------------------
  |  Branch (279:8): [True: 675k, False: 0]
  ------------------
  280|   675k|			    !strcmp(driver->short_name, "default")) {
  ------------------
  |  Branch (280:8): [True: 0, False: 0]
  ------------------
  281|   675k|				driver = NULL;
  282|   675k|				continue;
  283|   675k|			}
  284|      0|			sc_log(ctx, "trying driver '%s'", driver->short_name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  285|      0|			idx = _sc_match_atr(card, driver->atr_map, NULL);
  286|      0|			if (idx >= 0) {
  ------------------
  |  Branch (286:8): [True: 0, False: 0]
  ------------------
  287|      0|				struct sc_atr_table *src = &driver->atr_map[idx];
  288|       |
  289|      0|				sc_log(ctx, "matched driver '%s'", driver->name);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  290|       |				/* It's up to card driver to notice these correctly */
  291|      0|				card->name = src->name;
  292|      0|				card->type = src->type;
  293|      0|				card->flags = src->flags;
  294|      0|				break;
  295|      0|			}
  296|      0|			driver = NULL;
  297|      0|		}
  298|  15.3k|	}
  299|       |
  300|  15.3k|	if (driver != NULL) {
  ------------------
  |  Branch (300:6): [True: 0, False: 15.3k]
  ------------------
  301|       |		/* Forced driver, or matched via ATR mapping from config file */
  302|      0|		card->driver = driver;
  303|       |
  304|      0|		memcpy(card->ops, card->driver->ops, sizeof(struct sc_card_operations));
  305|      0|		if (card->ops->match_card != NULL)
  ------------------
  |  Branch (305:7): [True: 0, False: 0]
  ------------------
  306|      0|			if (card->ops->match_card(card) != 1)
  ------------------
  |  Branch (306:8): [True: 0, False: 0]
  ------------------
  307|      0|				sc_log(ctx, "driver '%s' match_card() failed: %s (will continue anyway)", card->driver->name, sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  308|       |
  309|      0|		if (card->ops->init != NULL) {
  ------------------
  |  Branch (309:7): [True: 0, False: 0]
  ------------------
  310|      0|			r = card->ops->init(card);
  311|      0|			if (r) {
  ------------------
  |  Branch (311:8): [True: 0, False: 0]
  ------------------
  312|      0|				sc_log(ctx, "driver '%s' init() failed: %s", card->driver->name, sc_strerror(r));
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  313|      0|				goto err;
  314|      0|			}
  315|      0|		}
  316|      0|	}
  317|  15.3k|	else {
  318|  15.3k|		sc_card_t uninitialized = *card;
  319|  15.3k|		sc_log(ctx, "matching built-in ATRs");
  ------------------
  |  |   71|  15.3k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  320|   359k|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (320:15): [True: 357k, False: 2.06k]
  ------------------
  321|       |			/* FIXME If we had a clean API description, we'd probably get a
  322|       |			 * cleaner implementation of the driver's match_card and init,
  323|       |			 * which should normally *not* modify the card object if
  324|       |			 * unsuccessful. However, after years of relentless hacking, reality
  325|       |			 * is different: The card object is changed in virtually every card
  326|       |			 * driver so in order to prevent unwanted interaction, we reset the
  327|       |			 * card object here and hope that the card driver at least doesn't
  328|       |			 * allocate any internal resources that need to be freed. If we
  329|       |			 * had more time, we should refactor the existing code to not
  330|       |			 * modify sc_card_t until complete success (possibly by combining
  331|       |			 * `match_card()` and `init()`) */
  332|   357k|			*card = uninitialized;
  333|       |
  334|   357k|			struct sc_card_driver *drv = ctx->card_drivers[i];
  335|   357k|			const struct sc_card_operations *ops = drv->ops;
  336|       |
  337|   357k|			sc_log(ctx, "trying driver '%s'", drv->short_name);
  ------------------
  |  |   71|   357k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  338|   357k|			if (ops == NULL || ops->match_card == NULL)   {
  ------------------
  |  Branch (338:8): [True: 0, False: 357k]
  |  Branch (338:23): [True: 0, False: 357k]
  ------------------
  339|      0|				continue;
  340|      0|			}
  341|   357k|			else if (!(ctx->flags & SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER)
  ------------------
  |  |  868|   357k|#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER	0x00000008
  ------------------
  |  Branch (341:13): [True: 357k, False: 0]
  ------------------
  342|   357k|				   	&& !strcmp("default", drv->short_name))   {
  ------------------
  |  Branch (342:12): [True: 2.06k, False: 355k]
  ------------------
  343|  2.06k|				sc_log(ctx , "ignore 'default' card driver");
  ------------------
  |  |   71|  2.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  344|  2.06k|				continue;
  345|  2.06k|			}
  346|       |
  347|       |			/* Needed if match_card() needs to talk with the card (e.g. card-muscle) */
  348|   355k|			*card->ops = *ops;
  349|   355k|			if (ops->match_card(card) != 1)
  ------------------
  |  Branch (349:8): [True: 341k, False: 14.1k]
  ------------------
  350|   341k|				continue;
  351|  14.1k|			sc_log(ctx, "matched: %s", drv->name);
  ------------------
  |  |   71|  14.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__
  |  |  ------------------
  ------------------
  352|  14.1k|			memcpy(card->ops, ops, sizeof(struct sc_card_operations));
  353|  14.1k|			card->driver = drv;
  354|  14.1k|			r = ops->init(card);
  355|  14.1k|			if (r) {
  ------------------
  |  Branch (355:8): [True: 1.59k, False: 12.5k]
  ------------------
  356|  1.59k|				sc_log(ctx, "driver '%s' init() failed: %s", drv->name, sc_strerror(r));
  ------------------
  |  |   71|  1.59k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  357|  1.59k|				if (r == SC_ERROR_INVALID_CARD) {
  ------------------
  |  |   60|  1.59k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  |  Branch (357:9): [True: 862, False: 729]
  ------------------
  358|    862|					card->driver = NULL;
  359|    862|					continue;
  360|    862|				}
  361|    729|				goto err;
  362|  1.59k|			}
  363|  12.5k|			break;
  364|  14.1k|		}
  365|  15.3k|	}
  366|  14.6k|	if (card->driver == NULL) {
  ------------------
  |  Branch (366:6): [True: 2.06k, False: 12.5k]
  ------------------
  367|  2.06k|		sc_log(ctx, "unable to find driver for inserted card");
  ------------------
  |  |   71|  2.06k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  368|  2.06k|		r = SC_ERROR_INVALID_CARD;
  ------------------
  |  |   60|  2.06k|#define SC_ERROR_INVALID_CARD			-1210
  ------------------
  369|  2.06k|		goto err;
  370|  2.06k|	}
  371|  12.5k|	if (card->name == NULL)
  ------------------
  |  Branch (371:6): [True: 2.65k, False: 9.89k]
  ------------------
  372|  2.65k|		card->name = card->driver->name;
  373|       |
  374|       |	/* initialize max_send_size/max_recv_size to a meaningful value */
  375|  12.5k|	card->max_recv_size = sc_get_max_recv_size(card);
  376|  12.5k|	card->max_send_size = sc_get_max_send_size(card);
  377|       |
  378|  12.5k|	sc_log(ctx,
  ------------------
  |  |   71|  12.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__
  |  |  ------------------
  ------------------
  379|  12.5k|	       "card info name:'%s', type:%i, flags:0x%lX, max_send/recv_size:%"SC_FORMAT_LEN_SIZE_T"u/%"SC_FORMAT_LEN_SIZE_T"u",
  380|  12.5k|	       card->name, card->type, card->flags, card->max_send_size,
  381|  12.5k|	       card->max_recv_size);
  382|       |
  383|  12.5k|#ifdef ENABLE_SM
  384|       |        /* Check, if secure messaging module present. */
  385|  12.5k|	r = sc_card_sm_check(card);
  386|  12.5k|	if (r)   {
  ------------------
  |  Branch (386:6): [True: 0, False: 12.5k]
  ------------------
  387|      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__
  |  |  ------------------
  ------------------
  388|      0|		goto err;
  389|      0|	}
  390|  12.5k|#endif
  391|  12.5k|	*card_out = card;
  392|       |
  393|  12.5k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.5k|	int _ret = r; \
  |  |  |  |  155|  12.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.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: 12.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.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|  12.5k|	return _ret; \
  |  |  |  |  163|  12.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  394|  2.79k|err:
  395|  2.79k|	if (connected)
  ------------------
  |  Branch (395:6): [True: 2.79k, False: 0]
  ------------------
  396|  2.79k|		reader->ops->disconnect(reader);
  397|  2.79k|	if (card != NULL)
  ------------------
  |  Branch (397:6): [True: 2.79k, False: 0]
  ------------------
  398|  2.79k|		sc_card_free(card);
  399|  2.79k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  2.79k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.79k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.79k|	int _ret = r; \
  |  |  |  |  155|  2.79k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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|  2.79k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 2.79k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.79k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.79k|	return _ret; \
  |  |  |  |  163|  2.79k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  400|  2.79k|}
sc_disconnect_card:
  403|  15.3k|{
  404|  15.3k|	sc_context_t *ctx;
  405|       |
  406|  15.3k|	if (!card)
  ------------------
  |  Branch (406:6): [True: 2.79k, False: 12.5k]
  ------------------
  407|  2.79k|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  2.79k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  408|       |
  409|  12.5k|	ctx = card->ctx;
  410|  12.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  411|       |
  412|  12.5k|	if (card->ops->finish) {
  ------------------
  |  Branch (412:6): [True: 11.7k, False: 785]
  ------------------
  413|  11.7k|		int r = card->ops->finish(card);
  414|  11.7k|		if (r)
  ------------------
  |  Branch (414:7): [True: 503, False: 11.2k]
  ------------------
  415|    503|			sc_log(ctx, "card driver finish() failed: %s", sc_strerror(r));
  ------------------
  |  |   71|    503|#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|  11.7k|	}
  417|       |
  418|  12.5k|	if (card->reader->ops->disconnect) {
  ------------------
  |  Branch (418:6): [True: 12.5k, False: 0]
  ------------------
  419|  12.5k|		int r = card->reader->ops->disconnect(card->reader);
  420|  12.5k|		if (r)
  ------------------
  |  Branch (420:7): [True: 0, False: 12.5k]
  ------------------
  421|      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__
  |  |  ------------------
  ------------------
  422|  12.5k|	}
  423|       |
  424|  12.5k|#ifdef ENABLE_SM
  425|       |	/* release SM related resources */
  426|  12.5k|	sc_card_sm_unload(card);
  427|  12.5k|#endif
  428|       |
  429|  12.5k|	sc_card_free(card);
  430|  12.5k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.5k|	int _ret = r; \
  |  |  |  |  155|  12.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.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: 12.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.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|  12.5k|	return _ret; \
  |  |  |  |  163|  12.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  431|  12.5k|}
sc_lock:
  458|   638k|{
  459|   638k|	int r = 0, r2 = 0;
  460|   638k|	int was_reset = 0;
  461|   638k|	int reader_lock_obtained  = 0;
  462|       |
  463|   638k|	if (card == NULL)
  ------------------
  |  Branch (463:6): [True: 0, False: 638k]
  ------------------
  464|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  465|       |
  466|   638k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   638k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   638k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   638k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   638k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 638k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  467|       |
  468|   638k|	r = sc_mutex_lock(card->ctx, card->mutex);
  469|   638k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   638k|#define SC_SUCCESS				0
  ------------------
  |  Branch (469:6): [True: 0, False: 638k]
  ------------------
  470|      0|		return r;
  471|   638k|	if (card->lock_count == 0) {
  ------------------
  |  Branch (471:6): [True: 258k, False: 380k]
  ------------------
  472|   258k|		if (card->reader->ops->lock != NULL) {
  ------------------
  |  Branch (472:7): [True: 258k, False: 0]
  ------------------
  473|   258k|			r = card->reader->ops->lock(card->reader);
  474|   258k|			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   37|   516k|#define SC_ERROR_CARD_RESET			-1106
  ------------------
              			while (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
  ------------------
  |  |   46|   258k|#define SC_ERROR_READER_REATTACHED		-1115
  ------------------
  |  Branch (474:11): [True: 0, False: 258k]
  |  Branch (474:39): [True: 0, False: 258k]
  ------------------
  475|      0|				if (was_reset++ > 4) /* TODO retry a few times */
  ------------------
  |  Branch (475:9): [True: 0, False: 0]
  ------------------
  476|      0|					break;
  477|      0|				r = card->reader->ops->lock(card->reader);
  478|      0|			}
  479|   258k|			if (r == 0)
  ------------------
  |  Branch (479:8): [True: 258k, False: 0]
  ------------------
  480|   258k|				reader_lock_obtained = 1;
  481|   258k|		}
  482|   258k|	}
  483|   638k|	if (r == 0)
  ------------------
  |  Branch (483:6): [True: 638k, False: 0]
  ------------------
  484|   638k|		card->lock_count++;
  485|       |
  486|   638k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  487|   638k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   638k|#define SC_SUCCESS				0
  ------------------
  |  Branch (487:6): [True: 0, False: 638k]
  ------------------
  488|      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__
  |  |  ------------------
  ------------------
  489|      0|		r = r != SC_SUCCESS ? r : r2;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (489:7): [True: 0, False: 0]
  ------------------
  490|      0|	}
  491|       |
  492|   638k|	if (r == 0 && was_reset > 0) {
  ------------------
  |  Branch (492:6): [True: 638k, False: 0]
  |  Branch (492:16): [True: 0, False: 638k]
  ------------------
  493|      0|#ifdef ENABLE_SM
  494|      0|		if (card->sm_ctx.ops.open)
  ------------------
  |  Branch (494:7): [True: 0, False: 0]
  ------------------
  495|      0|			card->sm_ctx.ops.open(card);
  496|      0|#endif
  497|      0|	}
  498|       |
  499|       |	/* give card driver a chance to do something when reader lock first obtained */
  500|   638k|	if (r == 0 && reader_lock_obtained == 1  && card->ops->card_reader_lock_obtained) {
  ------------------
  |  Branch (500:6): [True: 638k, False: 0]
  |  Branch (500:16): [True: 258k, False: 380k]
  |  Branch (500:46): [True: 68.3k, False: 189k]
  ------------------
  501|  68.3k|		if (SC_SUCCESS != card->ops->card_reader_lock_obtained(card, was_reset))
  ------------------
  |  |   28|  68.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (501:7): [True: 4.81k, False: 63.5k]
  ------------------
  502|  4.81k|			sc_log(card->ctx, "card_reader_lock_obtained failed");
  ------------------
  |  |   71|  4.81k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  503|  68.3k|	}
  504|       |
  505|   638k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   638k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   638k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   638k|	int _ret = r; \
  |  |  |  |  155|   638k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 638k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   638k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 638k]
  |  |  |  |  ------------------
  |  |  |  |  157|   638k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   638k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   638k|	return _ret; \
  |  |  |  |  163|   638k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  506|   638k|}
sc_unlock:
  509|   638k|{
  510|   638k|	int r, r2;
  511|       |
  512|   638k|	if (!card)
  ------------------
  |  Branch (512:6): [True: 0, False: 638k]
  ------------------
  513|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  514|       |
  515|   638k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   638k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   638k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   638k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   638k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 638k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  516|       |
  517|   638k|	r = sc_mutex_lock(card->ctx, card->mutex);
  518|   638k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   638k|#define SC_SUCCESS				0
  ------------------
  |  Branch (518:6): [True: 0, False: 638k]
  ------------------
  519|   638k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  520|       |
  521|   638k|	if (card->lock_count < 1) {
  ------------------
  |  Branch (521:6): [True: 0, False: 638k]
  ------------------
  522|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  523|      0|	}
  524|   638k|	if (--card->lock_count == 0) {
  ------------------
  |  Branch (524:6): [True: 258k, False: 380k]
  ------------------
  525|       |		/* release reader lock */
  526|   258k|		if (card->reader->ops->unlock != NULL)
  ------------------
  |  Branch (526:7): [True: 258k, False: 0]
  ------------------
  527|   258k|			r = card->reader->ops->unlock(card->reader);
  528|   258k|	}
  529|   638k|	r2 = sc_mutex_unlock(card->ctx, card->mutex);
  530|   638k|	if (r2 != SC_SUCCESS) {
  ------------------
  |  |   28|   638k|#define SC_SUCCESS				0
  ------------------
  |  Branch (530:6): [True: 0, False: 638k]
  ------------------
  531|      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__
  |  |  ------------------
  ------------------
  532|      0|		r = (r == SC_SUCCESS) ? r2 : r;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (532:7): [True: 0, False: 0]
  ------------------
  533|      0|	}
  534|       |
  535|   638k|	return r;
  536|   638k|}
sc_read_binary:
  607|  11.4k|{
  608|  11.4k|	size_t max_le = sc_get_max_recv_size(card);
  609|  11.4k|	size_t todo = count;
  610|  11.4k|	int r;
  611|       |
  612|  11.4k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (612:6): [True: 0, False: 11.4k]
  |  Branch (612:22): [True: 0, False: 11.4k]
  |  Branch (612:43): [True: 0, False: 11.4k]
  ------------------
  613|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  614|      0|	}
  615|  11.4k|	sc_log(card->ctx, "called; %"SC_FORMAT_LEN_SIZE_T"u bytes at index %d",
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  616|  11.4k|	       count, idx);
  617|  11.4k|	if (count == 0)
  ------------------
  |  Branch (617:6): [True: 437, False: 11.0k]
  ------------------
  618|  11.4k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    437|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    437|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    437|	int _ret = r; \
  |  |  |  |  155|    437|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 437, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    437|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 437]
  |  |  |  |  ------------------
  |  |  |  |  157|    437|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    437|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    437|	return _ret; \
  |  |  |  |  163|    437|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  619|       |
  620|  11.0k|#ifdef ENABLE_SM
  621|  11.0k|	if (card->sm_ctx.ops.read_binary)   {
  ------------------
  |  Branch (621:6): [True: 271, False: 10.7k]
  ------------------
  622|    271|		r = card->sm_ctx.ops.read_binary(card, idx, buf, count);
  623|    271|		if (r)
  ------------------
  |  Branch (623:7): [True: 217, False: 54]
  ------------------
  624|    271|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    217|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  625|    271|	}
  626|  10.8k|#endif
  627|       |
  628|  10.8k|	if (card->ops->read_binary == NULL)
  ------------------
  |  Branch (628:6): [True: 0, False: 10.8k]
  ------------------
  629|  10.8k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  630|       |
  631|       |	/* lock the card now to avoid deselection of the file */
  632|  10.8k|	r = sc_lock(card);
  633|  10.8k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  10.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  10.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  10.8k|	int _ret = (r); \
  |  |  |  |  168|  10.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 10.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|  10.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  634|       |
  635|  42.6k|	while (todo > 0) {
  ------------------
  |  Branch (635:9): [True: 38.9k, False: 3.76k]
  ------------------
  636|  38.9k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  38.9k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 12.7k, False: 26.1k]
  |  |  ------------------
  ------------------
  637|       |
  638|  38.9k|		r = card->ops->read_binary(card, idx, buf, chunk, flags);
  639|  38.9k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  36.1k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (639:7): [True: 2.76k, False: 36.1k]
  |  Branch (639:17): [True: 109, False: 36.0k]
  ------------------
  640|  2.87k|			break;
  641|  36.0k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (641:7): [True: 4.17k, False: 31.8k]
  |  Branch (641:16): [True: 2.55k, False: 1.62k]
  ------------------
  642|       |			/* the last command failed, but previous ones succeeded.
  643|       |			 * Let's just return what we've successfully read. */
  644|  2.55k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  645|  2.55k|			break;
  646|  2.55k|		}
  647|  33.4k|		if (r < 0) {
  ------------------
  |  Branch (647:7): [True: 1.62k, False: 31.8k]
  ------------------
  648|  1.62k|			sc_unlock(card);
  649|  1.62k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  1.62k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.62k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.62k|	int _ret = r; \
  |  |  |  |  155|  1.62k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.62k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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|  1.62k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.62k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.62k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.62k|	return _ret; \
  |  |  |  |  163|  1.62k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  650|  1.62k|		}
  651|  31.8k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (651:7): [True: 0, False: 31.8k]
  |  Branch (651:40): [True: 0, False: 31.8k]
  ------------------
  652|       |			/* `idx + r` or `todo - r` would overflow */
  653|      0|			sc_unlock(card);
  654|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  655|      0|		}
  656|       |
  657|  31.8k|		todo -= (size_t) r;
  658|  31.8k|		buf  += (size_t) r;
  659|  31.8k|		idx  += (size_t) r;
  660|  31.8k|	}
  661|       |
  662|  9.19k|	sc_unlock(card);
  663|       |
  664|  9.19k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  164|  9.19k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.19k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.19k|	int _ret = r; \
  |  |  |  |  155|  9.19k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.00k, False: 8.19k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.00k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.00k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.00k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.19k|	} else { \
  |  |  |  |  159|  8.19k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  8.19k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  8.19k|	} \
  |  |  |  |  162|  9.19k|	return _ret; \
  |  |  |  |  163|  9.19k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  665|  9.19k|}
sc_select_file:
  818|   103k|{
  819|   103k|	int r;
  820|   103k|	char pbuf[SC_MAX_PATH_STRING_SIZE];
  821|       |
  822|   103k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (822:6): [True: 0, False: 103k]
  |  Branch (822:22): [True: 0, False: 103k]
  ------------------
  823|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  824|      0|	}
  825|       |
  826|   103k|	r = sc_path_print(pbuf, sizeof(pbuf), in_path);
  827|   103k|	if (r != SC_SUCCESS)
  ------------------
  |  |   28|   103k|#define SC_SUCCESS				0
  ------------------
  |  Branch (827:6): [True: 626, False: 102k]
  ------------------
  828|    626|		pbuf[0] = '\0';
  829|       |
  830|       |	/* FIXME We should be a bit less strict and let the upper layers do
  831|       |	 * the initialization (including reuse of existing file objects). We
  832|       |	 * implemented this here because we are lazy. */
  833|   103k|	if (file != NULL)
  ------------------
  |  Branch (833:6): [True: 49.1k, False: 54.2k]
  ------------------
  834|  49.1k|		*file = NULL;
  835|       |
  836|   103k|	sc_log(card->ctx, "called; type=%d, path=%s", in_path->type, pbuf);
  ------------------
  |  |   71|   103k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  837|   103k|	if (in_path->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|   103k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (837:6): [True: 0, False: 103k]
  ------------------
  838|   103k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  839|       |
  840|   103k|	if (in_path->type == SC_PATH_TYPE_PATH) {
  ------------------
  |  |  119|   103k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (840:6): [True: 75.0k, False: 28.3k]
  ------------------
  841|       |		/* Perform a sanity check */
  842|  75.0k|		size_t i;
  843|       |
  844|  75.0k|		if ((in_path->len & 1) != 0)
  ------------------
  |  Branch (844:7): [True: 66, False: 74.9k]
  ------------------
  845|  75.0k|			LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  846|       |
  847|   225k|		for (i = 0; i < in_path->len/2; i++) {
  ------------------
  |  Branch (847:15): [True: 150k, False: 74.9k]
  ------------------
  848|   150k|			u8 p1 = in_path->value[2*i],
  849|   150k|			   p2 = in_path->value[2*i+1];
  850|       |
  851|   150k|			if ((p1 == 0x3F && p2 == 0x00) && i != 0)
  ------------------
  |  Branch (851:9): [True: 52.2k, False: 98.2k]
  |  Branch (851:23): [True: 52.1k, False: 110]
  |  Branch (851:38): [True: 18, False: 52.1k]
  ------------------
  852|   150k|				LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  853|   150k|		}
  854|  74.9k|	}
  855|   103k|	if (card->ops->select_file == NULL)
  ------------------
  |  Branch (855:6): [True: 0, False: 103k]
  ------------------
  856|   103k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  857|   103k|	r = card->ops->select_file(card, in_path, file);
  858|   103k|	LOG_TEST_RET(card->ctx, r, "'SELECT' error");
  ------------------
  |  |  174|   103k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|   103k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|   103k|	int _ret = (r); \
  |  |  |  |  168|   103k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 76.4k, False: 26.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|  76.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|  76.4k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  76.4k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  76.4k|		return _ret; \
  |  |  |  |  172|  76.4k|	} \
  |  |  |  |  173|   103k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 26.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|       |
  860|  26.8k|	if (file) {
  ------------------
  |  Branch (860:6): [True: 14.4k, False: 12.4k]
  ------------------
  861|  14.4k|		if (*file)
  ------------------
  |  Branch (861:7): [True: 14.3k, False: 82]
  ------------------
  862|       |			/* Remember file path */
  863|  14.3k|			(*file)->path = *in_path;
  864|     82|		else
  865|       |			/* FIXME We should be a bit less strict and let the upper layers do
  866|       |			 * the error checking. We implemented this here because we are
  867|       |			 * lazy.  */
  868|     82|			r = SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     82|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  869|  14.4k|	}
  870|       |
  871|  26.8k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  26.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  26.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  26.8k|	int _ret = r; \
  |  |  |  |  155|  26.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 26.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  26.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     82|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 82, False: 26.7k]
  |  |  |  |  ------------------
  |  |  |  |  157|  26.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  26.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  26.8k|	return _ret; \
  |  |  |  |  163|  26.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  872|  26.8k|}
sc_get_data:
  876|  6.14k|{
  877|  6.14k|	int	r;
  878|       |
  879|  6.14k|	sc_log(card->ctx, "called, tag=%04x", tag);
  ------------------
  |  |   71|  6.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__
  |  |  ------------------
  ------------------
  880|  6.14k|	if (card->ops->get_data == NULL)
  ------------------
  |  Branch (880:6): [True: 0, False: 6.14k]
  ------------------
  881|  6.14k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  882|  6.14k|	r = card->ops->get_data(card, tag, buf, len);
  883|       |
  884|  6.14k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  6.14k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  6.14k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  6.14k|	int _ret = r; \
  |  |  |  |  155|  6.14k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 4.48k, False: 1.65k]
  |  |  |  |  ------------------
  |  |  |  |  156|  4.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|  3.61k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.61k, False: 873]
  |  |  |  |  ------------------
  |  |  |  |  157|  4.48k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  4.48k|	} else { \
  |  |  |  |  159|  1.65k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.65k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.65k|	} \
  |  |  |  |  162|  6.14k|	return _ret; \
  |  |  |  |  163|  6.14k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  885|  6.14k|}
sc_read_record:
  940|   187k|{
  941|   187k|	size_t max_le = sc_get_max_recv_size(card);
  942|   187k|	size_t todo = count;
  943|   187k|	int r;
  944|       |
  945|   187k|	if (card == NULL || card->ops == NULL || buf == NULL) {
  ------------------
  |  Branch (945:6): [True: 0, False: 187k]
  |  Branch (945:22): [True: 0, False: 187k]
  |  Branch (945:43): [True: 0, False: 187k]
  ------------------
  946|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  947|      0|	}
  948|   187k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|   187k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|   187k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|   187k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|   187k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 187k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  949|   187k|	if (count == 0)
  ------------------
  |  Branch (949:6): [True: 169k, False: 18.1k]
  ------------------
  950|   187k|		LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|   169k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   169k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   169k|	int _ret = r; \
  |  |  |  |  155|   169k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 169k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|   169k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 169k]
  |  |  |  |  ------------------
  |  |  |  |  157|   169k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|   169k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|   169k|	return _ret; \
  |  |  |  |  163|   169k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  951|       |
  952|  18.1k|	if (card->ops->read_record == NULL)
  ------------------
  |  Branch (952:6): [True: 15, False: 18.1k]
  ------------------
  953|  18.1k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  954|       |
  955|       |	/* lock the card now to avoid deselection of the file */
  956|  18.1k|	r = sc_lock(card);
  957|  18.1k|	LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
  ------------------
  |  |  174|  18.1k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  18.1k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  18.1k|	int _ret = (r); \
  |  |  |  |  168|  18.1k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 18.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|  18.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  958|       |
  959|  34.1k|	while (todo > 0) {
  ------------------
  |  Branch (959:9): [True: 32.8k, False: 1.27k]
  ------------------
  960|  32.8k|		size_t chunk = MIN(todo, max_le);
  ------------------
  |  |   70|  32.8k|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 25.4k, False: 7.37k]
  |  |  ------------------
  ------------------
  961|       |
  962|  32.8k|		r = card->ops->read_record(card, rec_nr, idx, buf, chunk, flags);
  963|  32.8k|		if (r == 0 || r == SC_ERROR_FILE_END_REACHED)
  ------------------
  |  |   69|  30.6k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
  |  Branch (963:7): [True: 2.18k, False: 30.6k]
  |  Branch (963:17): [True: 480, False: 30.1k]
  ------------------
  964|  2.66k|			break;
  965|  30.1k|		if (r < 0 && todo != count) {
  ------------------
  |  Branch (965:7): [True: 14.2k, False: 15.9k]
  |  Branch (965:16): [True: 13.1k, False: 1.10k]
  ------------------
  966|       |			/* the last command failed, but previous ones succeeded.
  967|       |			 * Let's just return what we've successfully read. */
  968|  13.1k|			sc_log(card->ctx, "Subsequent read failed with %d, returning what was read successfully.", r);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  969|  13.1k|			break;
  970|  13.1k|		}
  971|  17.0k|		if (r < 0) {
  ------------------
  |  Branch (971:7): [True: 1.10k, False: 15.9k]
  ------------------
  972|  1.10k|			sc_unlock(card);
  973|  1.10k|			LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  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|  1.10k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 1.10k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  974|  1.10k|		}
  975|  15.9k|		if ((idx > SIZE_MAX - (size_t) r) || (size_t) r > todo) {
  ------------------
  |  Branch (975:7): [True: 0, False: 15.9k]
  |  Branch (975:40): [True: 0, False: 15.9k]
  ------------------
  976|       |			/* `idx + r` or `todo - r` would overflow */
  977|      0|			sc_unlock(card);
  978|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  979|      0|		}
  980|       |
  981|  15.9k|		todo -= (size_t) r;
  982|  15.9k|		buf  += (size_t) r;
  983|  15.9k|		idx  += (size_t) r;
  984|  15.9k|	}
  985|       |
  986|  17.0k|	sc_unlock(card);
  987|       |
  988|  17.0k|	LOG_FUNC_RETURN(card->ctx, (int)(count - todo));
  ------------------
  |  |  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: 2.53k, False: 14.5k]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.53k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 2.53k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.53k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.5k|	} else { \
  |  |  |  |  159|  14.5k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  14.5k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  14.5k|	} \
  |  |  |  |  162|  17.0k|	return _ret; \
  |  |  |  |  163|  17.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  989|  17.0k|}
sc_card_ctl:
 1099|   113k|{
 1100|   113k|	int r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|   113k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1101|       |
 1102|   113k|	if (card == NULL) {
  ------------------
  |  Branch (1102:6): [True: 0, False: 113k]
  ------------------
 1103|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1104|      0|	}
 1105|   113k|	sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "called with cmd=%lu\n", cmd);
  ------------------
  |  |   70|   113k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1106|       |
 1107|   113k|	if (card->ops->card_ctl != NULL)
  ------------------
  |  Branch (1107:6): [True: 112k, False: 1.48k]
  ------------------
 1108|   112k|		r = card->ops->card_ctl(card, cmd, args);
 1109|       |
 1110|       |	/* suppress "not supported" error messages */
 1111|   113k|	if (r == SC_ERROR_NOT_SUPPORTED) {
  ------------------
  |  |   89|   113k|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (1111:6): [True: 3.49k, False: 110k]
  ------------------
 1112|  3.49k|		sc_log(card->ctx, "card_ctl(%lu) not supported", cmd);
  ------------------
  |  |   71|  3.49k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1113|  3.49k|		return r;
 1114|  3.49k|	}
 1115|   110k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|   110k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|   110k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|   110k|	int _ret = r; \
  |  |  |  |  155|   110k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 82.8k, False: 27.4k]
  |  |  |  |  ------------------
  |  |  |  |  156|  82.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  36.1k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 36.1k, False: 46.6k]
  |  |  |  |  ------------------
  |  |  |  |  157|  82.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  82.8k|	} else { \
  |  |  |  |  159|  27.4k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  27.4k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  27.4k|	} \
  |  |  |  |  162|   110k|	return _ret; \
  |  |  |  |  163|   110k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1116|   110k|}
_sc_card_add_algorithm:
 1119|  48.8k|{
 1120|  48.8k|	sc_algorithm_info_t *p;
 1121|       |
 1122|  48.8k|	if (info == NULL) {
  ------------------
  |  Branch (1122:6): [True: 0, False: 48.8k]
  ------------------
 1123|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1124|      0|	}
 1125|  48.8k|	p = (sc_algorithm_info_t *) realloc(card->algorithms, (card->algorithm_count + 1) * sizeof(*info));
 1126|  48.8k|	if (!p) {
  ------------------
  |  Branch (1126:6): [True: 0, False: 48.8k]
  ------------------
 1127|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1128|      0|	}
 1129|  48.8k|	card->algorithms = p;
 1130|  48.8k|	p += card->algorithm_count;
 1131|  48.8k|	card->algorithm_count++;
 1132|  48.8k|	*p = *info;
 1133|  48.8k|	return SC_SUCCESS;
  ------------------
  |  |   28|  48.8k|#define SC_SUCCESS				0
  ------------------
 1134|  48.8k|}
_sc_card_add_symmetric_alg:
 1138|    130|{
 1139|    130|	sc_algorithm_info_t info;
 1140|       |
 1141|    130|	memset(&info, 0, sizeof(info));
 1142|    130|	info.algorithm = algorithm;
 1143|    130|	info.key_length = key_length;
 1144|    130|	info.flags = flags;
 1145|       |
 1146|    130|	return _sc_card_add_algorithm(card, &info);
 1147|    130|}
_sc_card_add_ec_alg:
 1184|  6.47k|{
 1185|  6.47k|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1186|  6.47k|		curve_oid, SC_ALGORITHM_EC);
  ------------------
  |  |   79|  6.47k|#define SC_ALGORITHM_EC		2
  ------------------
 1187|  6.47k|}
_sc_card_add_eddsa_alg:
 1192|    104|{
 1193|       |	/* For simplicity, share the ec union with the curve information */
 1194|    104|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1195|    104|		curve_oid, SC_ALGORITHM_EDDSA);
  ------------------
  |  |   81|    104|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1196|    104|}
_sc_card_add_xeddsa_alg:
 1201|     24|{
 1202|       |	/* For simplicity, share the ec union with the curve information */
 1203|     24|	return _sc_card_add_ec_alg_int(card, key_length, flags, ext_flags,
 1204|     24|		curve_oid, SC_ALGORITHM_XEDDSA);
  ------------------
  |  |   82|     24|#define SC_ALGORITHM_XEDDSA		5
  ------------------
 1205|     24|}
sc_card_find_alg:
 1209|  67.4k|{
 1210|  67.4k|	int i;
 1211|       |
 1212|   249k|	for (i = 0; i < card->algorithm_count; i++) {
  ------------------
  |  Branch (1212:14): [True: 237k, False: 11.4k]
  ------------------
 1213|   237k|		sc_algorithm_info_t *info = &card->algorithms[i];
 1214|       |
 1215|   237k|		if (param && (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   79|    460|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (1215:7): [True: 230, False: 237k]
  |  Branch (1215:17): [True: 54, False: 176]
  ------------------
 1216|    176|			info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|    406|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (1216:4): [True: 54, False: 122]
  ------------------
 1217|    162|			info->algorithm == SC_ALGORITHM_XEDDSA)) {
  ------------------
  |  |   82|    122|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (1217:4): [True: 54, False: 68]
  ------------------
 1218|    162|			if (sc_compare_oid((struct sc_object_id *)param, &info->u._ec.params.id))
  ------------------
  |  Branch (1218:8): [True: 0, False: 162]
  ------------------
 1219|      0|				return info;
 1220|   237k|		} else if (info->algorithm != algorithm) {
  ------------------
  |  Branch (1220:14): [True: 49.8k, False: 187k]
  ------------------
 1221|  49.8k|			continue;
 1222|   187k|		} else if (info->key_length == key_length)
  ------------------
  |  Branch (1222:14): [True: 56.0k, False: 131k]
  ------------------
 1223|  56.0k|			return info;
 1224|   237k|	}
 1225|  11.4k|	return NULL;
 1226|  67.4k|}
sc_card_find_ec_alg:
 1230|  6.25k|{
 1231|  6.25k|	return sc_card_find_alg(card, SC_ALGORITHM_EC, key_length, curve_name);
  ------------------
  |  |   79|  6.25k|#define SC_ALGORITHM_EC		2
  ------------------
 1232|  6.25k|}
sc_card_find_eddsa_alg:
 1236|    140|{
 1237|    140|	return sc_card_find_alg(card, SC_ALGORITHM_EDDSA, key_length, curve_name);
  ------------------
  |  |   81|    140|#define SC_ALGORITHM_EDDSA		4
  ------------------
 1238|    140|}
_sc_card_add_rsa_alg:
 1248|  42.0k|{
 1249|  42.0k|	sc_algorithm_info_t info;
 1250|       |
 1251|  42.0k|	memset(&info, 0, sizeof(info));
 1252|  42.0k|	info.algorithm = SC_ALGORITHM_RSA;
  ------------------
  |  |   78|  42.0k|#define SC_ALGORITHM_RSA		0
  ------------------
 1253|  42.0k|	info.key_length = key_length;
 1254|  42.0k|	info.flags = flags;
 1255|       |	/* disable particular PKCS1 v1.5 padding type if also RAW is supported on card */
 1256|  42.0k|	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  120|  42.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  42.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  42.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  42.0k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  120|  42.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  118|  42.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  |  |  ------------------
  |  |               #define SC_ALGORITHM_RSA_PAD_PKCS1	(SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01 | SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02) /* PKCS#1 v1.5 (type 1 or 2) */
  |  |  ------------------
  |  |  |  |  119|  42.0k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
              	if ((info.flags & (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) == (SC_ALGORITHM_RSA_PAD_PKCS1 | SC_ALGORITHM_RSA_RAW)) {
  ------------------
  |  |  111|  42.0k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  |  Branch (1256:6): [True: 8.09k, False: 33.9k]
  ------------------
 1257|  8.09k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01)
  ------------------
  |  |  118|  8.09k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
  |  Branch (1257:7): [True: 0, False: 8.09k]
  ------------------
 1258|      0|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01;
  ------------------
  |  |  118|      0|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01	0x00000040 /* PKCS#1 v1.5 padding type 1 */
  ------------------
 1259|  8.09k|		if (card->ctx->disable_hw_pkcs1_padding & SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02)
  ------------------
  |  |  119|  8.09k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
  |  Branch (1259:7): [True: 8.09k, False: 0]
  ------------------
 1260|  8.09k|			info.flags &= ~SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02;
  ------------------
  |  |  119|  8.09k|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  ------------------
 1261|  8.09k|	}
 1262|  42.0k|	info.u._rsa.exponent = exponent;
 1263|       |
 1264|  42.0k|	return _sc_card_add_algorithm(card, &info);
 1265|  42.0k|}
sc_card_find_rsa_alg:
 1268|  61.0k|{
 1269|  61.0k|	return sc_card_find_alg(card, SC_ALGORITHM_RSA, key_length, NULL);
  ------------------
  |  |   78|  61.0k|#define SC_ALGORITHM_RSA		0
  ------------------
 1270|  61.0k|}
_sc_match_atr:
 1341|   306k|{
 1342|   306k|	int res;
 1343|       |
 1344|   306k|	if (card == NULL)
  ------------------
  |  Branch (1344:6): [True: 0, False: 306k]
  ------------------
 1345|      0|		return -1;
 1346|   306k|	res = match_atr_table(card->ctx, table, &card->atr);
 1347|   306k|	if (res < 0)
  ------------------
  |  Branch (1347:6): [True: 295k, False: 11.1k]
  ------------------
 1348|   295k|		return res;
 1349|  11.1k|	if (type_out != NULL)
  ------------------
  |  Branch (1349:6): [True: 10.8k, False: 270]
  ------------------
 1350|  10.8k|		*type_out = table[res].type;
 1351|  11.1k|	return res;
 1352|   306k|}
_sc_match_atr_block:
 1355|  12.5k|{
 1356|  12.5k|	struct sc_card_driver *drv;
 1357|  12.5k|	struct sc_atr_table *table;
 1358|  12.5k|	int res;
 1359|       |
 1360|  12.5k|	if (ctx == NULL)
  ------------------
  |  Branch (1360:6): [True: 0, False: 12.5k]
  ------------------
 1361|      0|		return NULL;
 1362|  12.5k|	if (driver) {
  ------------------
  |  Branch (1362:6): [True: 12.5k, False: 0]
  ------------------
 1363|  12.5k|		drv = driver;
 1364|  12.5k|		table = drv->atr_map;
 1365|  12.5k|		res = match_atr_table(ctx, table, atr);
 1366|  12.5k|		if (res < 0)
  ------------------
  |  Branch (1366:7): [True: 12.5k, False: 0]
  ------------------
 1367|  12.5k|			return NULL;
 1368|      0|		return table[res].card_atr;
 1369|  12.5k|	} else {
 1370|      0|		unsigned int i;
 1371|       |
 1372|      0|		for (i = 0; ctx->card_drivers[i] != NULL; i++) {
  ------------------
  |  Branch (1372:15): [True: 0, False: 0]
  ------------------
 1373|      0|			drv = ctx->card_drivers[i];
 1374|      0|			table = drv->atr_map;
 1375|      0|			res = match_atr_table(ctx, table, atr);
 1376|      0|			if (res < 0)
  ------------------
  |  Branch (1376:8): [True: 0, False: 0]
  ------------------
 1377|      0|				continue;
 1378|      0|			return table[res].card_atr;
 1379|      0|		}
 1380|      0|	}
 1381|      0|	return NULL;
 1382|  12.5k|}
sc_get_conf_block:
 1453|  43.6k|{
 1454|  43.6k|	int i;
 1455|  43.6k|	scconf_block *conf_block = NULL;
 1456|       |
 1457|  87.2k|	for (i = 0; ctx->conf_blocks[i] != NULL; i++) {
  ------------------
  |  Branch (1457:14): [True: 43.6k, False: 43.6k]
  ------------------
 1458|  43.6k|		scconf_block **blocks;
 1459|       |
 1460|  43.6k|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[i], name1, name2);
 1461|  43.6k|		if (blocks != NULL) {
  ------------------
  |  Branch (1461:7): [True: 43.6k, False: 0]
  ------------------
 1462|  43.6k|			conf_block = blocks[0];
 1463|  43.6k|			free(blocks);
 1464|  43.6k|		}
 1465|  43.6k|		if (conf_block != NULL && priority)
  ------------------
  |  Branch (1465:7): [True: 0, False: 43.6k]
  |  Branch (1465:29): [True: 0, False: 0]
  ------------------
 1466|      0|			break;
 1467|  43.6k|	}
 1468|  43.6k|	return conf_block;
 1469|  43.6k|}
sc_clear_ec_params:
 1473|  6.60k|{
 1474|  6.60k|	if (ecp) {
  ------------------
  |  Branch (1474:6): [True: 6.60k, False: 0]
  ------------------
 1475|  6.60k|		free(ecp->named_curve);
 1476|  6.60k|		free(ecp->der.value);
 1477|  6.60k|		memset(ecp, 0, sizeof(struct sc_ec_parameters));
 1478|  6.60k|	}
 1479|  6.60k|	return;
 1480|  6.60k|}
card.c:sc_card_new:
  127|  15.3k|{
  128|  15.3k|	sc_card_t *card;
  129|       |
  130|  15.3k|	if (ctx == NULL)
  ------------------
  |  Branch (130:6): [True: 0, False: 15.3k]
  ------------------
  131|      0|		return NULL;
  132|       |
  133|  15.3k|	card = calloc(1, sizeof(struct sc_card));
  134|  15.3k|	if (card == NULL)
  ------------------
  |  Branch (134:6): [True: 0, False: 15.3k]
  ------------------
  135|      0|		return NULL;
  136|  15.3k|	card->ops = malloc(sizeof(struct sc_card_operations));
  137|  15.3k|	if (card->ops == NULL) {
  ------------------
  |  Branch (137:6): [True: 0, False: 15.3k]
  ------------------
  138|      0|		free(card);
  139|      0|		return NULL;
  140|      0|	}
  141|       |
  142|  15.3k|	card->ctx = ctx;
  143|  15.3k|	if (sc_mutex_create(ctx, &card->mutex) != SC_SUCCESS) {
  ------------------
  |  |   28|  15.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (143:6): [True: 0, False: 15.3k]
  ------------------
  144|      0|		free(card->ops);
  145|      0|		free(card);
  146|      0|		return NULL;
  147|      0|	}
  148|       |
  149|  15.3k|	card->type = -1;
  150|  15.3k|	card->app_count = -1;
  151|       |
  152|  15.3k|	return card;
  153|  15.3k|}
card.c:sc_card_free:
  156|  15.3k|{
  157|  15.3k|	sc_free_apps(card);
  158|  15.3k|	sc_free_ef_atr(card);
  159|       |
  160|  15.3k|	free(card->ops);
  161|       |
  162|  15.3k|	if (card->algorithms != NULL)   {
  ------------------
  |  Branch (162:6): [True: 11.6k, False: 3.71k]
  ------------------
  163|  11.6k|		int i;
  164|  60.4k|		for (i=0; i<card->algorithm_count; i++)   {
  ------------------
  |  Branch (164:13): [True: 48.8k, False: 11.6k]
  ------------------
  165|  48.8k|			struct sc_algorithm_info *info = (card->algorithms + i);
  166|  48.8k|			if (info->algorithm == SC_ALGORITHM_EC ||
  ------------------
  |  |   79|  97.6k|#define SC_ALGORITHM_EC		2
  ------------------
  |  Branch (166:8): [True: 6.47k, False: 42.3k]
  ------------------
  167|  42.3k|					info->algorithm == SC_ALGORITHM_EDDSA ||
  ------------------
  |  |   81|  91.1k|#define SC_ALGORITHM_EDDSA		4
  ------------------
  |  Branch (167:6): [True: 104, False: 42.2k]
  ------------------
  168|  42.2k|					info->algorithm == SC_ALGORITHM_XEDDSA) {
  ------------------
  |  |   82|  42.2k|#define SC_ALGORITHM_XEDDSA		5
  ------------------
  |  Branch (168:6): [True: 24, False: 42.2k]
  ------------------
  169|  6.60k|				sc_clear_ec_params(&info->u._ec.params);
  170|  6.60k|			}
  171|  48.8k|		}
  172|  11.6k|		free(card->algorithms);
  173|       |
  174|  11.6k|		card->algorithms = NULL;
  175|  11.6k|		card->algorithm_count = 0;
  176|  11.6k|	}
  177|       |
  178|  15.3k|	if (card->mutex != NULL) {
  ------------------
  |  Branch (178:6): [True: 0, False: 15.3k]
  ------------------
  179|      0|		int r = sc_mutex_destroy(card->ctx, card->mutex);
  180|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (180:7): [True: 0, False: 0]
  ------------------
  181|      0|			sc_log(card->ctx, "unable to destroy mutex");
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  182|      0|	}
  183|  15.3k|	sc_mem_clear(card, sizeof(*card));
  184|  15.3k|	free(card);
  185|  15.3k|}
card.c:_sc_card_add_ec_alg_int:
 1154|  6.60k|{
 1155|  6.60k|	sc_algorithm_info_t info;
 1156|  6.60k|	int r;
 1157|       |
 1158|  6.60k|	memset(&info, 0, sizeof(info));
 1159|  6.60k|	sc_init_oid(&info.u._ec.params.id);
 1160|       |
 1161|  6.60k|	info.algorithm = algorithm;
 1162|  6.60k|	info.key_length = key_length;
 1163|  6.60k|	info.flags = flags;
 1164|       |
 1165|  6.60k|	info.u._ec.ext_flags = ext_flags;
 1166|  6.60k|	if (curve_oid) {
  ------------------
  |  Branch (1166:6): [True: 2.20k, False: 4.39k]
  ------------------
 1167|  2.20k|		info.u._ec.params.id = *curve_oid;
 1168|  2.20k|		r = sc_encode_oid(card->ctx, &info.u._ec.params.id, &info.u._ec.params.der.value, &info.u._ec.params.der.len);
 1169|  2.20k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_encode_oid failed");
  ------------------
  |  |  184|  2.20k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.20k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.20k|	int _ret = (r); \
  |  |  |  |  178|  2.20k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.20k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1170|  2.20k|		r = sc_pkcs15_fix_ec_parameters(card->ctx, &info.u._ec.params);
 1171|  2.20k|		LOG_TEST_GOTO_ERR(card->ctx, r, "sc_pkcs15_fix_ec_parameters failed");
  ------------------
  |  |  184|  2.20k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  2.20k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  2.20k|	int _ret = (r); \
  |  |  |  |  178|  2.20k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 2.20k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.20k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 2.20k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1172|  2.20k|	}
 1173|       |
 1174|  6.60k|	r = _sc_card_add_algorithm(card, &info);
 1175|  6.60k|	return r;
 1176|      0|err:
 1177|      0|	sc_clear_ec_params(&info.u._ec.params);
 1178|      0|	return r;
 1179|  6.60k|}
card.c:match_atr_table:
 1278|   319k|{
 1279|   319k|	u8 *card_atr_bin;
 1280|   319k|	size_t card_atr_bin_len;
 1281|   319k|	char card_atr_hex[3 * SC_MAX_ATR_SIZE];
 1282|   319k|	size_t card_atr_hex_len;
 1283|   319k|	unsigned int i = 0;
 1284|       |
 1285|   319k|	if (ctx == NULL || table == NULL || atr == NULL)
  ------------------
  |  Branch (1285:6): [True: 0, False: 319k]
  |  Branch (1285:21): [True: 12.5k, False: 306k]
  |  Branch (1285:38): [True: 0, False: 306k]
  ------------------
 1286|  12.5k|		return -1;
 1287|   306k|	card_atr_bin = atr->value;
 1288|   306k|	card_atr_bin_len = atr->len;
 1289|   306k|	sc_bin_to_hex(card_atr_bin, card_atr_bin_len, card_atr_hex, sizeof(card_atr_hex), ':');
 1290|   306k|	card_atr_hex_len = strlen(card_atr_hex);
 1291|       |
 1292|   306k|	sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR     : %s", card_atr_hex);
  ------------------
  |  |   70|   306k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1293|       |
 1294|  2.65M|	for (i = 0; table[i].atr != NULL; i++) {
  ------------------
  |  Branch (1294:14): [True: 2.36M, False: 295k]
  ------------------
 1295|  2.36M|		const char *tatr = table[i].atr;
 1296|  2.36M|		const char *matr = table[i].atrmask;
 1297|  2.36M|		size_t tatr_len = strlen(tatr);
 1298|  2.36M|		u8 mbin[SC_MAX_ATR_SIZE], tbin[SC_MAX_ATR_SIZE];
 1299|  2.36M|		size_t mbin_len, tbin_len, s, matr_len;
 1300|  2.36M|		size_t fix_hex_len = card_atr_hex_len;
 1301|  2.36M|		size_t fix_bin_len = card_atr_bin_len;
 1302|       |
 1303|  2.36M|		sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR try : %s", tatr);
  ------------------
  |  |   70|  2.36M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1304|       |
 1305|  2.36M|		if (tatr_len != fix_hex_len) {
  ------------------
  |  Branch (1305:7): [True: 2.27M, False: 88.7k]
  ------------------
 1306|  2.27M|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ignored - wrong length");
  ------------------
  |  |   70|  2.27M|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1307|  2.27M|			continue;
 1308|  2.27M|		}
 1309|  88.7k|		if (matr != NULL) {
  ------------------
  |  Branch (1309:7): [True: 21.1k, False: 67.5k]
  ------------------
 1310|  21.1k|			sc_debug(ctx, SC_LOG_DEBUG_MATCH, "ATR mask: %s", matr);
  ------------------
  |  |   70|  21.1k|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1311|       |
 1312|  21.1k|			matr_len = strlen(matr);
 1313|  21.1k|			if (tatr_len != matr_len)
  ------------------
  |  Branch (1313:8): [True: 0, False: 21.1k]
  ------------------
 1314|      0|				continue;
 1315|  21.1k|			tbin_len = sizeof(tbin);
 1316|  21.1k|			sc_hex_to_bin(tatr, tbin, &tbin_len);
 1317|  21.1k|			mbin_len = sizeof(mbin);
 1318|  21.1k|			sc_hex_to_bin(matr, mbin, &mbin_len);
 1319|  21.1k|			if (mbin_len != fix_bin_len) {
  ------------------
  |  Branch (1319:8): [True: 0, False: 21.1k]
  ------------------
 1320|      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__
  |  |  ------------------
  ------------------
 1321|      0|				continue;
 1322|      0|			}
 1323|   407k|			for (s = 0; s < tbin_len; s++) {
  ------------------
  |  Branch (1323:16): [True: 386k, False: 21.1k]
  ------------------
 1324|       |				/* reduce tatr with mask */
 1325|   386k|				tbin[s] = (tbin[s] & mbin[s]);
 1326|       |				/* create copy of card_atr_bin masked) */
 1327|   386k|				mbin[s] = (card_atr_bin[s] & mbin[s]);
 1328|   386k|			}
 1329|  21.1k|			if (memcmp(tbin, mbin, tbin_len) != 0)
  ------------------
  |  Branch (1329:8): [True: 16.9k, False: 4.27k]
  ------------------
 1330|  16.9k|				continue;
 1331|  67.5k|		} else {
 1332|  67.5k|			if (strncasecmp(tatr, card_atr_hex, tatr_len) != 0)
  ------------------
  |  Branch (1332:8): [True: 60.7k, False: 6.83k]
  ------------------
 1333|  60.7k|				continue;
 1334|  67.5k|		}
 1335|  11.1k|		return i;
 1336|  88.7k|	}
 1337|   295k|	return -1;
 1338|   306k|}
card.c:sc_card_sm_unload:
 1519|  12.5k|{
 1520|  12.5k|	if (card->sm_ctx.module.ops.module_cleanup)
  ------------------
  |  Branch (1520:6): [True: 0, False: 12.5k]
  ------------------
 1521|      0|		card->sm_ctx.module.ops.module_cleanup(card->ctx);
 1522|       |
 1523|  12.5k|	if (card->sm_ctx.module.handle)
  ------------------
  |  Branch (1523:6): [True: 0, False: 12.5k]
  ------------------
 1524|      0|		sc_dlclose(card->sm_ctx.module.handle);
 1525|       |	card->sm_ctx.module.handle = NULL;
 1526|  12.5k|	return 0;
 1527|  12.5k|}
card.c:sc_card_sm_check:
 1622|  12.5k|{
 1623|  12.5k|	const char *sm = NULL, *module_name = NULL, *module_path = NULL, *module_data = NULL, *sm_mode = NULL;
 1624|  12.5k|	struct sc_context *ctx = card->ctx;
 1625|  12.5k|	scconf_block *atrblock = NULL, *sm_conf_block = NULL;
 1626|  12.5k|	int rv, ii;
 1627|       |#ifdef _WIN32
 1628|       |	char temp_path[PATH_MAX];
 1629|       |	size_t temp_len = PATH_MAX - 1;
 1630|       |	char expanded_val[PATH_MAX];
 1631|       |	DWORD expanded_len = PATH_MAX;
 1632|       |#endif
 1633|       |
 1634|  12.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1635|       |
 1636|       |	/* get the name of card specific SM configuration section */
 1637|  12.5k|	atrblock = _sc_match_atr_block(ctx, card->driver, &card->atr);
 1638|  12.5k|	if (atrblock == NULL)
  ------------------
  |  Branch (1638:6): [True: 12.5k, False: 0]
  ------------------
 1639|  12.5k|		LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  12.5k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.5k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.5k|	int _ret = r; \
  |  |  |  |  155|  12.5k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.5k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.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: 12.5k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.5k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.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|  12.5k|	return _ret; \
  |  |  |  |  163|  12.5k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1640|      0|	sm = scconf_get_str(atrblock, "secure_messaging", NULL);
 1641|      0|	if (!sm)
  ------------------
  |  Branch (1641:6): [True: 0, False: 0]
  ------------------
 1642|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1643|       |
 1644|       |	/* get SM configuration section by the name */
 1645|      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__
  |  |  ------------------
  ------------------
 1646|      0|        for (ii = 0; ctx->conf_blocks[ii]; ii++) {
  ------------------
  |  Branch (1646:22): [True: 0, False: 0]
  ------------------
 1647|      0|		scconf_block **blocks;
 1648|       |
 1649|      0|		blocks = scconf_find_blocks(ctx->conf, ctx->conf_blocks[ii], "secure_messaging", sm);
 1650|      0|		if (blocks) {
  ------------------
  |  Branch (1650:7): [True: 0, False: 0]
  ------------------
 1651|      0|			sm_conf_block = blocks[0];
 1652|      0|			free(blocks);
 1653|      0|		}
 1654|      0|		if (sm_conf_block != NULL)
  ------------------
  |  Branch (1654:7): [True: 0, False: 0]
  ------------------
 1655|      0|			break;
 1656|      0|	}
 1657|       |
 1658|      0|	if (!sm_conf_block)
  ------------------
  |  Branch (1658:6): [True: 0, False: 0]
  ------------------
 1659|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1660|       |
 1661|       |	/* check if an external SM module has to be used */
 1662|       |#ifdef _WIN32
 1663|       |	rv = sc_ctx_win32_get_config_value(NULL, "SmDir", "Software\\" OPENSC_VS_FF_COMPANY_NAME "\\OpenSC" OPENSC_ARCH_SUFFIX,
 1664|       |			temp_path, &temp_len);
 1665|       |	if (rv == SC_SUCCESS) {
 1666|       |		temp_path[temp_len] = '\0';
 1667|       |		module_path = temp_path;
 1668|       |	}
 1669|       |	expanded_len = ExpandEnvironmentStringsA(module_path, expanded_val, expanded_len);
 1670|       |	if (0 < expanded_len && expanded_len < sizeof expanded_val)
 1671|       |		module_path = expanded_val;
 1672|       |#else
 1673|      0|	module_path = scconf_get_str(sm_conf_block, "module_path", DEFAULT_SM_MODULE_PATH);
 1674|      0|#endif
 1675|      0|	module_name = scconf_get_str(sm_conf_block, "module_name", DEFAULT_SM_MODULE);
 1676|      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__
  |  |  ------------------
  ------------------
 1677|      0|	if (!module_name)
  ------------------
  |  Branch (1677:6): [True: 0, False: 0]
  ------------------
 1678|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1679|       |
 1680|      0|	rv = sc_card_sm_load(card, module_path, module_name);
 1681|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1682|       |
 1683|      0|	strlcpy(card->sm_ctx.module.filename, module_name, sizeof(card->sm_ctx.module.filename));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1684|      0|	strlcpy(card->sm_ctx.config_section, sm, sizeof(card->sm_ctx.config_section));
  ------------------
  |  |   43|      0|#define strlcpy _strlcpy
  ------------------
 1685|       |
 1686|       |	/* allocate resources for the external SM module */
 1687|      0|	if (card->sm_ctx.module.ops.module_init)   {
  ------------------
  |  Branch (1687:6): [True: 0, False: 0]
  ------------------
 1688|      0|		module_data = scconf_get_str(sm_conf_block, "module_data", NULL);
 1689|       |
 1690|      0|		rv = card->sm_ctx.module.ops.module_init(ctx, module_data);
 1691|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1692|      0|	}
 1693|       |
 1694|       |	/* initialize SM session in the case of 'APDU TRANSMIT' SM mode */
 1695|      0|	sm_mode = scconf_get_str(sm_conf_block, "mode", NULL);
 1696|      0|	if (sm_mode && !strcasecmp("Transmit", sm_mode))   {
  ------------------
  |  Branch (1696:6): [True: 0, False: 0]
  |  Branch (1696:17): [True: 0, False: 0]
  ------------------
 1697|      0|		if (!card->sm_ctx.ops.open || !card->sm_ctx.ops.get_sm_apdu || !card->sm_ctx.ops.free_sm_apdu)
  ------------------
  |  Branch (1697:7): [True: 0, False: 0]
  |  Branch (1697:33): [True: 0, False: 0]
  |  Branch (1697:66): [True: 0, False: 0]
  ------------------
 1698|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1699|       |
 1700|      0|		card->sm_ctx.sm_mode = SM_MODE_TRANSMIT;
  ------------------
  |  |   47|      0|#define SM_MODE_TRANSMIT	0x200
  ------------------
 1701|      0|		rv = card->sm_ctx.ops.open(card);
 1702|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1703|      0|	}
 1704|       |
 1705|      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__
  |  |  ------------------
  ------------------
 1706|      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]
  |  |  ------------------
  ------------------
 1707|      0|}

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

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

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

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

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

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

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

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

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

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

iasecc_sm_initialize:
  270|    201|{
  271|    201|	struct sc_context *ctx = card->ctx;
  272|    201|#ifdef ENABLE_SM
  273|    201|	struct sm_info *sm_info = &card->sm_ctx.info;
  274|    201|	struct sm_cwa_session *cwa_session = &sm_info->session.cwa;
  275|    201|	struct sc_remote_data rdata;
  276|    201|	int rv;
  277|       |
  278|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  279|       |
  280|    201|	strlcpy(sm_info->config_section, card->sm_ctx.config_section, sizeof(sm_info->config_section));
  ------------------
  |  |   43|    201|#define strlcpy _strlcpy
  ------------------
  281|    201|	sm_info->cmd = cmd;
  282|    201|	sm_info->serialnr = card->serialnr;
  283|    201|	sm_info->card_type = card->type;
  284|    201|	sm_info->sm_type = SM_TYPE_CWA14890;
  ------------------
  |  |   39|    201|#define SM_TYPE_CWA14890	0x400
  ------------------
  285|       |
  286|    201|	rv = iasecc_sm_se_mutual_authentication(card, se_num);
  287|    201|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() MUTUAL AUTHENTICATION failed");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  288|       |
  289|      0|	rv = sc_get_challenge(card, cwa_session->card_challenge, SM_SMALL_CHALLENGE_LEN);
  ------------------
  |  |   85|      0|#define SM_SMALL_CHALLENGE_LEN	8
  ------------------
  290|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() GET CHALLENGE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  291|       |
  292|      0|	sc_remote_data_init(&rdata);
  293|       |
  294|      0|	rv = sm_save_sc_context(card, sm_info);
  295|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() cannot save current context");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  296|       |
  297|      0|	if (!card->sm_ctx.module.ops.initialize)
  ------------------
  |  Branch (297:6): [True: 0, False: 0]
  ------------------
  298|      0|		LOG_TEST_RET(ctx, SC_ERROR_SM_NOT_INITIALIZED, "iasecc_sm_initialize() no SM module");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  299|      0|	rv = card->sm_ctx.module.ops.initialize(ctx, sm_info, &rdata);
  300|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() INITIALIZE failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  301|       |
  302|       |
  303|      0|	if (rdata.length == 1)   {
  ------------------
  |  Branch (303:6): [True: 0, False: 0]
  ------------------
  304|      0|		rdata.data->flags |= SC_REMOTE_APDU_FLAG_RETURN_ANSWER;
  ------------------
  |  |  386|      0|#define SC_REMOTE_APDU_FLAG_RETURN_ANSWER	0x02
  ------------------
  305|      0|		rdata.data->apdu.flags &= ~SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|      0|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  306|      0|	}
  307|      0|	else   {
  308|      0|		LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "TODO: SM init with more then one APDU");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  309|      0|	}
  310|       |
  311|      0|	cwa_session->mdata_len = sizeof(cwa_session->mdata);
  312|      0|	rv = iasecc_sm_transmit_apdus (card, &rdata, cwa_session->mdata, &cwa_session->mdata_len);
  313|      0|	if (rv == SC_ERROR_PIN_CODE_INCORRECT)
  ------------------
  |  |   64|      0|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (313:6): [True: 0, False: 0]
  ------------------
  314|      0|		sc_log(ctx, "SM initialization failed, %i tries left", (rdata.data + rdata.length - 1)->apdu.sw2 & 0x0F);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  315|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_initialize() transmit APDUs failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  316|       |
  317|      0|	rdata.free(&rdata);
  318|       |
  319|      0|	sc_log(ctx, "MA data(len:%"SC_FORMAT_LEN_SIZE_T"u) '%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__
  |  |  ------------------
  ------------------
  320|      0|	       cwa_session->mdata_len,
  321|      0|	       sc_dump_hex(cwa_session->mdata, cwa_session->mdata_len));
  322|      0|	if (cwa_session->mdata_len != 0x48)
  ------------------
  |  Branch (322:6): [True: 0, False: 0]
  ------------------
  323|      0|		LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "iasecc_sm_initialize() invalid MUTUAL AUTHENTICATE result data");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  324|       |
  325|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  326|       |#else
  327|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  328|       |	return SC_ERROR_NOT_SUPPORTED;
  329|       |#endif
  330|      0|}
iasecc_sm_read_binary:
  593|    201|{
  594|    201|	struct sc_context *ctx = card->ctx;
  595|    201|#ifdef ENABLE_SM
  596|    201|	struct sm_info *sm_info = &card->sm_ctx.info;
  597|    201|	struct sc_remote_data rdata;
  598|    201|	struct iasecc_sm_cmd_update_binary cmd_data;
  599|    201|	int rv;
  600|       |
  601|    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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  602|    201|	sc_log(ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  603|    201|	       "SM read binary: acl:%X, offs:%"SC_FORMAT_LEN_SIZE_T"u, count:%"SC_FORMAT_LEN_SIZE_T"u",
  604|    201|	       se_num, offs, count);
  605|       |
  606|    201|	rv = iasecc_sm_initialize(card, se_num, SM_CMD_FILE_READ);
  ------------------
  |  |   56|    201|#define SM_CMD_FILE_READ		0x201
  ------------------
  607|    201|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM INITIALIZE failed");
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  608|       |
  609|      0|	cmd_data.offs = offs;
  610|      0|	cmd_data.count = count;
  611|      0|	sm_info->cmd_data = &cmd_data;
  612|       |
  613|      0|	sc_remote_data_init(&rdata);
  614|      0|	rv = iasecc_sm_cmd(card, &rdata);
  615|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM 'READ BINARY' failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  616|       |
  617|      0|	sc_log(ctx, "IAS/ECC decode answer() rdata length %i", rdata.length);
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  618|       |
  619|      0|	rv = sm_release (card, &rdata, buff, count);
  620|      0|	LOG_TEST_RET(ctx, rv, "iasecc_sm_read_binary() SM release failed");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  621|       |
  622|      0|	rdata.free(&rdata);
  623|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  624|       |#else
  625|       |	LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "built without support of Secure-Messaging");
  626|       |	return SC_ERROR_NOT_SUPPORTED;
  627|       |#endif
  628|      0|}
iasecc-sm.c:iasecc_sm_se_mutual_authentication:
  222|    201|{
  223|    201|	struct sc_context *ctx = card->ctx;
  224|    201|	struct sm_info *sm_info = &card->sm_ctx.info;
  225|    201|	struct iasecc_se_info se;
  226|    201|	struct sc_crt *crt =  &sm_info->session.cwa.params.crt_at;
  227|    201|	struct sc_apdu apdu;
  228|    201|	unsigned char sbuf[0x100];
  229|    201|	int rv, offs;
  230|       |
  231|    201|	memset(&se, 0, sizeof(se));
  232|       |
  233|    201|	se.reference = se_num;
  234|    201|	crt->usage = IASECC_UQB_AT_MUTUAL_AUTHENTICATION;
  ------------------
  |  |  127|    201|#define IASECC_UQB_AT_MUTUAL_AUTHENTICATION	0xC0
  ------------------
  235|    201|	crt->tag = IASECC_CRT_TAG_AT;
  ------------------
  |  |  104|    201|#define IASECC_CRT_TAG_AT	0xA4
  ------------------
  236|       |
  237|    201|	rv = iasecc_se_get_info(card, &se);
  238|    201|	LOG_TEST_RET(ctx, rv, "Get SE info error");
  ------------------
  |  |  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: 165, False: 36]
  |  |  |  |  ------------------
  |  |  |  |  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|    201|} 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:
   36|  57.2k|{
   37|  57.2k|	if (card == NULL || apdu == NULL) {
  ------------------
  |  Branch (37:6): [True: 0, False: 57.2k]
  |  Branch (37:22): [True: 0, False: 57.2k]
  ------------------
   38|      0|		return;
   39|      0|	}
   40|       |
   41|  57.2k|	if (apdu->lc > sc_get_max_send_size(card)) {
  ------------------
  |  Branch (41:6): [True: 453, False: 56.7k]
  ------------------
   42|       |		/* The lower layers will automatically do chaining */
   43|    453|		apdu->flags |= SC_APDU_FLAGS_CHAINING;
  ------------------
  |  |  306|    453|#define SC_APDU_FLAGS_CHAINING		0x00000001UL
  ------------------
   44|    453|	}
   45|       |
   46|  57.2k|	if (apdu->le > sc_get_max_recv_size(card)) {
  ------------------
  |  Branch (46:6): [True: 1.93k, False: 55.2k]
  ------------------
   47|       |		/* The lower layers will automatically do a GET RESPONSE, if possible.
   48|       |		 * All other workarounds must be carried out by the upper layers. */
   49|  1.93k|		apdu->le = sc_get_max_recv_size(card);
   50|  1.93k|	}
   51|  57.2k|}
encode_do_data:
  177|  13.6k|{
  178|  13.6k|	unsigned char offset_buffer[2];
  179|  13.6k|	size_t offset_buffer_len = sizeof offset_buffer;
  180|  13.6k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  181|  13.6k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  182|       |
  183|  13.6k|	if (idx > 0xFFFF)
  ------------------
  |  Branch (183:6): [True: 0, False: 13.6k]
  ------------------
  184|  13.6k|		LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "Offset beyond 0xFFFF not supported");
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  185|  13.6k|	offset_buffer[0] = (u8) (idx >> 8);
  186|  13.6k|	offset_buffer[1] = (u8) (idx & 0x00FF);
  187|  13.6k|	sc_format_asn1_entry(asn1_do_data + 0, offset_buffer, &offset_buffer_len, 1);
  188|       |
  189|  13.6k|	if (data && data_len) {
  ------------------
  |  Branch (189:6): [True: 0, False: 13.6k]
  |  Branch (189:14): [True: 0, False: 0]
  ------------------
  190|      0|		sc_format_asn1_entry(asn1_do_data + 1, (void *) &data, &data_len, 1);
  191|  13.6k|	} else {
  192|  13.6k|		sc_format_asn1_entry(asn1_do_data + 1, NULL, NULL, 0);
  193|  13.6k|	}
  194|       |
  195|  13.6k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  13.6k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  13.6k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  13.6k|	int _ret = (r); \
  |  |  |  |  168|  13.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 13.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 13.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  196|  13.6k|			sc_asn1_encode(ctx, asn1_do_data, out, outlen),
  197|  13.6k|			"sc_asn1_encode() failed");
  198|       |
  199|  13.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  13.6k|#define SC_SUCCESS				0
  ------------------
  200|  13.6k|}
decode_do_data:
  205|  10.4k|{
  206|  10.4k|	struct sc_asn1_entry asn1_do_data[sizeof c_asn1_do_data / sizeof *c_asn1_do_data];
  207|  10.4k|	sc_copy_asn1_entry(c_asn1_do_data, asn1_do_data);
  208|       |
  209|  10.4k|	sc_format_asn1_entry(asn1_do_data + 0, NULL, NULL, 0);
  210|  10.4k|	sc_format_asn1_entry(asn1_do_data + 1, out, outlen, 0);
  211|       |
  212|  10.4k|	LOG_TEST_RET(ctx,
  ------------------
  |  |  174|  10.4k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  10.4k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  10.4k|	int _ret = (r); \
  |  |  |  |  168|  10.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.25k, False: 9.19k]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.25k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  1.25k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.25k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.25k|		return _ret; \
  |  |  |  |  172|  1.25k|	} \
  |  |  |  |  173|  10.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 9.19k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  213|  9.19k|			sc_asn1_decode(ctx, asn1_do_data, encoded_data, encoded_data_len, NULL, NULL),
  214|  9.19k|			"sc_asn1_decode() failed");
  215|       |
  216|  9.19k|	if (!(asn1_do_data[1].flags & SC_ASN1_PRESENT))
  ------------------
  |  |  147|  9.19k|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (216:6): [True: 7.76k, False: 1.43k]
  ------------------
  217|  7.76k|		return SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|  7.76k|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  218|       |
  219|  1.43k|	return SC_SUCCESS;
  ------------------
  |  |   28|  1.43k|#define SC_SUCCESS				0
  ------------------
  220|  9.19k|}
iso7816_build_pin_apdu:
 1189|  7.39k|{
 1190|  7.39k|	int r, len = 0, pad = 0, use_pin_pad = 0, ins, p1 = 0;
 1191|  7.39k|	int cse = SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  7.39k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1192|       |
 1193|  7.39k|	switch (data->pin_type) {
 1194|  7.39k|	case SC_AC_CHV:
  ------------------
  |  |  151|  7.39k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  |  Branch (1194:2): [True: 7.39k, False: 0]
  ------------------
 1195|       |		/* fall through */
 1196|  7.39k|	case SC_AC_SESSION:
  ------------------
  |  |  159|  7.39k|#define SC_AC_SESSION			0x00000100 /* Session PIN */
  ------------------
  |  Branch (1196:2): [True: 0, False: 7.39k]
  ------------------
 1197|  7.39k|	case SC_AC_CONTEXT_SPECIFIC:
  ------------------
  |  |  160|  7.39k|#define SC_AC_CONTEXT_SPECIFIC		0x00000200 /* Context specific login */
  ------------------
  |  Branch (1197:2): [True: 0, False: 7.39k]
  ------------------
 1198|  7.39k|		break;
 1199|      0|	default:
  ------------------
  |  Branch (1199:2): [True: 0, False: 7.39k]
  ------------------
 1200|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1201|  7.39k|	}
 1202|       |
 1203|  7.39k|	if (data->flags & SC_PIN_CMD_NEED_PADDING)
  ------------------
  |  |  429|  7.39k|#define SC_PIN_CMD_NEED_PADDING		0x0002
  ------------------
  |  Branch (1203:6): [True: 1.22k, False: 6.17k]
  ------------------
 1204|  1.22k|		pad = 1;
 1205|  7.39k|	if (data->flags & SC_PIN_CMD_USE_PINPAD)
  ------------------
  |  |  428|  7.39k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (1205:6): [True: 0, False: 7.39k]
  ------------------
 1206|      0|		use_pin_pad = 1;
 1207|       |
 1208|  7.39k|	data->pin1.offset = 5;
 1209|       |
 1210|  7.39k|	switch (data->cmd) {
 1211|    851|	case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|    851|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (1211:2): [True: 851, False: 6.54k]
  ------------------
 1212|    851|		ins = 0x20;
 1213|       |		/* detect overloaded APDU with SC_PIN_CMD_GET_INFO */
 1214|    851|		if (data->pin1.len == 0 && !use_pin_pad)
  ------------------
  |  Branch (1214:7): [True: 0, False: 851]
  |  Branch (1214:30): [True: 0, False: 0]
  ------------------
 1215|      0|			return SC_ERROR_INVALID_PIN_LENGTH;
  ------------------
  |  |   77|      0|#define SC_ERROR_INVALID_PIN_LENGTH		-1304
  ------------------
 1216|    851|		if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1216:7): [True: 21, False: 830]
  ------------------
 1217|     21|			return r;
 1218|    830|		len = r;
 1219|    830|		break;
 1220|    281|	case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|    281|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (1220:2): [True: 281, False: 7.11k]
  ------------------
 1221|    281|		ins = 0x24;
 1222|    281|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1222:7): [True: 275, False: 6]
  |  Branch (1222:31): [True: 0, False: 6]
  |  Branch (1222:46): [True: 0, False: 0]
  ------------------
 1223|    275|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1223:8): [True: 9, False: 266]
  ------------------
 1224|      9|				return r;
 1225|    266|			len += r;
 1226|    266|		}
 1227|      6|		else {
 1228|       |			/* implicit test */
 1229|      6|			p1 = 1;
 1230|      6|		}
 1231|       |
 1232|    272|		data->pin2.offset = data->pin1.offset + len;
 1233|    272|		if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1233:7): [True: 26, False: 246]
  ------------------
 1234|     26|			return r;
 1235|       |		/* Special case - where provided the old PIN on the command line
 1236|       |		 * but expect the new one to be entered on the keypad.
 1237|       |		 */
 1238|    246|		if (data->pin1.len && data->pin2.len == 0) {
  ------------------
  |  Branch (1238:7): [True: 240, False: 6]
  |  Branch (1238:25): [True: 0, False: 240]
  ------------------
 1239|      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__
  |  |  ------------------
  ------------------
 1240|      0|			data->flags |= SC_PIN_CMD_IMPLICIT_CHANGE;
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
 1241|      0|		};
 1242|    246|		len += r;
 1243|    246|		break;
 1244|    334|	case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|    334|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (1244:2): [True: 334, False: 7.06k]
  ------------------
 1245|    334|		ins = 0x2C;
 1246|    334|		if (data->pin1.len != 0 || (use_pin_pad && !( data->flags & SC_PIN_CMD_IMPLICIT_CHANGE))) {
  ------------------
  |  |  430|      0|#define SC_PIN_CMD_IMPLICIT_CHANGE	0x0004
  ------------------
  |  Branch (1246:7): [True: 328, False: 6]
  |  Branch (1246:31): [True: 0, False: 6]
  |  Branch (1246:46): [True: 0, False: 0]
  ------------------
 1247|    328|			if ((r = sc_build_pin(buf, buf_len, &data->pin1, pad)) < 0)
  ------------------
  |  Branch (1247:8): [True: 7, False: 321]
  ------------------
 1248|      7|				return r;
 1249|    321|			len += r;
 1250|    321|		} else {
 1251|      6|			p1 |= 0x02;
 1252|      6|		}
 1253|       |
 1254|    327|		if (data->pin2.len != 0 || use_pin_pad) {
  ------------------
  |  Branch (1254:7): [True: 327, False: 0]
  |  Branch (1254:30): [True: 0, False: 0]
  ------------------
 1255|    327|			data->pin2.offset = data->pin1.offset + len;
 1256|    327|			if ((r = sc_build_pin(buf+len, buf_len-len, &data->pin2, pad)) < 0)
  ------------------
  |  Branch (1256:8): [True: 14, False: 313]
  ------------------
 1257|     14|				return r;
 1258|    313|			len += r;
 1259|    313|		} else {
 1260|      0|			p1 |= 0x01;
 1261|      0|		}
 1262|    313|		if (p1 == 0x03) {
  ------------------
  |  Branch (1262:7): [True: 0, False: 313]
  ------------------
 1263|       |			/* No data to send or to receive */
 1264|      0|			cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1265|      0|		}
 1266|    313|		break;
 1267|  5.92k|	case SC_PIN_CMD_GET_INFO:
  ------------------
  |  |  425|  5.92k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1267:2): [True: 5.92k, False: 1.46k]
  ------------------
 1268|  5.92k|		ins = 0x20;
 1269|       |		/* No data to send or to receive */
 1270|  5.92k|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|  5.92k|#define SC_APDU_CASE_1			0x01
  ------------------
 1271|  5.92k|		break;
 1272|      0|	default:
  ------------------
  |  Branch (1272:2): [True: 0, False: 7.39k]
  ------------------
 1273|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1274|  7.39k|	}
 1275|       |
 1276|  7.31k|	sc_format_apdu(card, apdu, cse, ins, p1, data->pin_reference);
 1277|  7.31k|	apdu->lc = len;
 1278|  7.31k|	apdu->datalen = len;
 1279|  7.31k|	apdu->data = buf;
 1280|  7.31k|	apdu->resplen = 0;
 1281|       |
 1282|  7.31k|	return 0;
 1283|  7.39k|}
iso7816_select_aid:
 1407|  18.8k|{
 1408|  18.8k|	struct sc_context *ctx = card->ctx;
 1409|  18.8k|	struct sc_apdu apdu;
 1410|  18.8k|	int rv;
 1411|       |
 1412|  18.8k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  18.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  18.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  18.8k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 18.8k]
  |  |  ------------------
  ------------------
 1413|       |
 1414|  18.8k|	sc_format_apdu(card, &apdu, resp == NULL ? SC_APDU_CASE_3_SHORT : SC_APDU_CASE_4_SHORT, 0xA4, 0x04, resp == NULL ? 0x0C : 0x00);
  ------------------
  |  |  293|  7.05k|#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|  11.7k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  |  Branch (1414:30): [True: 7.05k, False: 11.7k]
  |  Branch (1414:102): [True: 7.05k, False: 11.7k]
  ------------------
 1415|  18.8k|	apdu.lc = reqlen;
 1416|  18.8k|	apdu.data = req;
 1417|  18.8k|	apdu.datalen = reqlen;
 1418|  18.8k|	apdu.resp = resp;
 1419|  18.8k|	apdu.resplen = resp == NULL ? 0 : *resplen;
  ------------------
  |  Branch (1419:17): [True: 7.05k, False: 11.7k]
  ------------------
 1420|  18.8k|	apdu.le = resp == NULL ? 0 : 256;
  ------------------
  |  Branch (1420:12): [True: 7.05k, False: 11.7k]
  ------------------
 1421|       |
 1422|  18.8k|	rv = sc_transmit_apdu(card, &apdu);
 1423|  18.8k|	if (resplen)
  ------------------
  |  Branch (1423:6): [True: 11.7k, False: 7.05k]
  ------------------
 1424|  11.7k|		*resplen = apdu.resplen;
 1425|  18.8k|	LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
  ------------------
  |  |  174|  18.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  18.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  18.8k|	int _ret = (r); \
  |  |  |  |  168|  18.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 228, False: 18.6k]
  |  |  |  |  ------------------
  |  |  |  |  169|    228|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    228|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    228|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    228|		return _ret; \
  |  |  |  |  172|    228|	} \
  |  |  |  |  173|  18.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 18.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1426|       |
 1427|  18.6k|	rv = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1428|  18.6k|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|  18.6k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  18.6k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  18.6k|	int _ret = r; \
  |  |  |  |  155|  18.6k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 18.6k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  18.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|  13.5k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.5k, False: 5.09k]
  |  |  |  |  ------------------
  |  |  |  |  157|  18.6k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  18.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|  18.6k|	return _ret; \
  |  |  |  |  163|  18.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1429|  18.6k|}
sc_get_iso7816_driver:
 1497|   530k|{
 1498|   530k|	return &iso_driver;
 1499|   530k|}
iso7816.c:no_match:
 1443|  6.89k|{
 1444|  6.89k|	return 0;
 1445|  6.89k|}
iso7816.c:iso7816_read_record:
  225|  28.2k|{
  226|  28.2k|	struct sc_apdu apdu;
  227|  28.2k|	int r;
  228|       |	/* XXX maybe use some bigger buffer */
  229|  28.2k|	unsigned char resp[SC_MAX_APDU_RESP_SIZE];
  230|  28.2k|	unsigned char *encoded_data = NULL, *decoded_data = NULL;
  231|  28.2k|	size_t encoded_data_len = 0, decoded_data_len = 0;
  232|       |
  233|  28.2k|	if (rec_nr > 0xFF)
  ------------------
  |  Branch (233:6): [True: 18, False: 28.2k]
  ------------------
  234|  28.2k|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|       |
  236|  28.2k|	if (idx == 0) {
  ------------------
  |  Branch (236:6): [True: 14.6k, False: 13.6k]
  ------------------
  237|  14.6k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB2, rec_nr, 0);
  ------------------
  |  |  301|  14.6k|#define SC_APDU_CASE_2			0x22
  ------------------
  238|  14.6k|		apdu.le = count;
  239|  14.6k|		apdu.resplen = count;
  240|  14.6k|		apdu.resp = buf;
  241|  14.6k|	} else {
  242|  13.6k|		r = encode_do_data(card->ctx, idx, NULL, 0, &encoded_data, &encoded_data_len);
  243|  13.6k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not encode data objects");
  ------------------
  |  |  184|  13.6k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  13.6k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  13.6k|	int _ret = (r); \
  |  |  |  |  178|  13.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 13.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|  13.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 13.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  244|       |
  245|  13.6k|		sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0xB3, rec_nr, 0);
  ------------------
  |  |  303|  13.6k|#define SC_APDU_CASE_4			0x24
  ------------------
  246|  13.6k|		apdu.lc = encoded_data_len;
  247|  13.6k|		apdu.datalen = encoded_data_len;
  248|  13.6k|		apdu.data = encoded_data;
  249|  13.6k|		apdu.le = sizeof resp;
  250|  13.6k|		apdu.resplen = sizeof resp;
  251|  13.6k|		apdu.resp = resp;
  252|  13.6k|	}
  253|  28.2k|	apdu.p2 = (flags & SC_RECORD_EF_ID_MASK) << 3;
  ------------------
  |  | 1301|  28.2k|#define SC_RECORD_EF_ID_MASK		0x0001FUL
  ------------------
  254|  28.2k|	if (flags & SC_RECORD_BY_REC_NR)
  ------------------
  |  | 1306|  28.2k|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
  |  Branch (254:6): [True: 28.2k, False: 0]
  ------------------
  255|  28.2k|		apdu.p2 |= 0x04;
  256|       |
  257|  28.2k|	iso7816_fixup_transceive_length(card, &apdu);
  258|  28.2k|	r = sc_transmit_apdu(card, &apdu);
  259|  28.2k|	LOG_TEST_GOTO_ERR(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  184|  28.2k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  28.2k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  28.2k|	int _ret = (r); \
  |  |  |  |  178|  28.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 1.62k, False: 26.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.62k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.62k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  1.62k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  1.62k|		goto err; \
  |  |  |  |  182|  1.62k|	} \
  |  |  |  |  183|  28.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 26.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  260|  26.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  261|  26.6k|	LOG_TEST_GOTO_ERR(card->ctx, r, "Card returned error");
  ------------------
  |  |  184|  26.6k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  26.6k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  26.6k|	int _ret = (r); \
  |  |  |  |  178|  26.6k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 2.95k, False: 23.6k]
  |  |  |  |  ------------------
  |  |  |  |  179|  2.95k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.95k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  2.95k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  2.95k|		goto err; \
  |  |  |  |  182|  2.95k|	} \
  |  |  |  |  183|  26.6k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 23.6k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  262|       |
  263|  23.6k|	if (idx == 0) {
  ------------------
  |  Branch (263:6): [True: 13.2k, False: 10.4k]
  ------------------
  264|  13.2k|		r = (int)apdu.resplen;
  265|  13.2k|	} else {
  266|  10.4k|		r = decode_do_data(card->ctx, apdu.resp, apdu.resplen,
  267|  10.4k|				&decoded_data, &decoded_data_len);
  268|  10.4k|		LOG_TEST_GOTO_ERR(card->ctx, r, "Could not decode data objects");
  ------------------
  |  |  184|  10.4k|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|  10.4k|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|  10.4k|	int _ret = (r); \
  |  |  |  |  178|  10.4k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 9.01k, False: 1.43k]
  |  |  |  |  ------------------
  |  |  |  |  179|  9.01k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.01k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|  9.01k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|  9.01k|		goto err; \
  |  |  |  |  182|  9.01k|	} \
  |  |  |  |  183|  10.4k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1.43k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  269|  1.43k|		if (decoded_data_len <= count) {
  ------------------
  |  Branch (269:7): [True: 1.21k, False: 219]
  ------------------
  270|  1.21k|			count = decoded_data_len;
  271|  1.21k|		}
  272|  1.43k|		memcpy(buf, decoded_data, count);
  273|  1.43k|		r = (int)count;
  274|  1.43k|	}
  275|       |
  276|  28.2k|err:
  277|  28.2k|	free(encoded_data);
  278|  28.2k|	free(decoded_data);
  279|  28.2k|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|  28.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  28.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  28.2k|	int _ret = r; \
  |  |  |  |  155|  28.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 14.4k, False: 13.8k]
  |  |  |  |  ------------------
  |  |  |  |  156|  14.4k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  13.6k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 13.6k, False: 811]
  |  |  |  |  ------------------
  |  |  |  |  157|  14.4k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  14.4k|	} else { \
  |  |  |  |  159|  13.8k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  13.8k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  13.8k|	} \
  |  |  |  |  162|  28.2k|	return _ret; \
  |  |  |  |  163|  28.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  280|  28.2k|}
iso7816.c:iso7816_select_file:
  631|  49.5k|{
  632|  49.5k|	struct sc_context *ctx;
  633|  49.5k|	struct sc_apdu apdu;
  634|  49.5k|	unsigned char buf[SC_MAX_APDU_BUFFER_SIZE];
  635|  49.5k|	unsigned char pathbuf[SC_MAX_PATH_SIZE], *path = pathbuf;
  636|  49.5k|	int r, pathtype;
  637|  49.5k|	size_t pathlen;
  638|  49.5k|	int select_mf = 0;
  639|  49.5k|	struct sc_file *file = NULL;
  640|  49.5k|	const u8 *buffer;
  641|  49.5k|	size_t buffer_len;
  642|  49.5k|	unsigned int cla, tag;
  643|       |
  644|  49.5k|	if (card == NULL || in_path == NULL) {
  ------------------
  |  Branch (644:6): [True: 0, False: 49.5k]
  |  Branch (644:22): [True: 0, False: 49.5k]
  ------------------
  645|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  646|      0|	}
  647|  49.5k|	ctx = card->ctx;
  648|  49.5k|	memcpy(path, in_path->value, in_path->len);
  649|  49.5k|	pathlen = in_path->len;
  650|  49.5k|	pathtype = in_path->type;
  651|       |
  652|  49.5k|	if (in_path->aid.len) {
  ------------------
  |  Branch (652:6): [True: 1.74k, False: 47.8k]
  ------------------
  653|  1.74k|		if (!pathlen) {
  ------------------
  |  Branch (653:7): [True: 1.28k, False: 466]
  ------------------
  654|  1.28k|			memcpy(path, in_path->aid.value, in_path->aid.len);
  655|  1.28k|			pathlen = in_path->aid.len;
  656|  1.28k|			pathtype = SC_PATH_TYPE_DF_NAME;
  ------------------
  |  |  118|  1.28k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  657|  1.28k|		} else {
  658|       |			/* First, select the application */
  659|    466|			sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|    466|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  660|    466|			apdu.data = in_path->aid.value;
  661|    466|			apdu.datalen = in_path->aid.len;
  662|    466|			apdu.lc = in_path->aid.len;
  663|       |
  664|    466|			r = sc_transmit_apdu(card, &apdu);
  665|    466|			LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    466|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    466|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    466|	int _ret = (r); \
  |  |  |  |  168|    466|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 3, False: 463]
  |  |  |  |  ------------------
  |  |  |  |  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|    466|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 463]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  666|    463|			r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  667|    463|			if (r)
  ------------------
  |  Branch (667:8): [True: 353, False: 110]
  ------------------
  668|    463|				LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  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|    353|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 353, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  669|       |
  670|    110|			if (pathtype == SC_PATH_TYPE_PATH
  ------------------
  |  |  119|    220|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (670:8): [True: 110, False: 0]
  ------------------
  671|      0|					|| pathtype == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|      0|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (671:9): [True: 0, False: 0]
  ------------------
  672|    110|				pathtype = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|    110|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  673|    110|		}
  674|  1.74k|	}
  675|       |
  676|  49.2k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0);
  ------------------
  |  |  294|  49.2k|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
  677|       |
  678|  49.2k|	switch (pathtype) {
  679|  10.5k|	case SC_PATH_TYPE_FILE_ID:
  ------------------
  |  |  117|  10.5k|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  |  Branch (679:2): [True: 10.5k, False: 38.6k]
  ------------------
  680|  10.5k|		apdu.p1 = 0;
  681|  10.5k|		if (pathlen != 2)
  ------------------
  |  Branch (681:7): [True: 0, False: 10.5k]
  ------------------
  682|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  683|  10.5k|		break;
  684|  20.7k|	case SC_PATH_TYPE_DF_NAME:
  ------------------
  |  |  118|  20.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (684:2): [True: 20.7k, False: 28.5k]
  ------------------
  685|  20.7k|		apdu.p1 = 4;
  686|  20.7k|		break;
  687|  17.7k|	case SC_PATH_TYPE_PATH:
  ------------------
  |  |  119|  17.7k|#define SC_PATH_TYPE_PATH		2
  ------------------
  |  Branch (687:2): [True: 17.7k, False: 31.5k]
  ------------------
  688|  17.7k|		apdu.p1 = 8;
  689|  17.7k|		if (pathlen >= 2 && memcmp(path, "\x3F\x00", 2) == 0) {
  ------------------
  |  Branch (689:7): [True: 17.6k, False: 82]
  |  Branch (689:23): [True: 12.3k, False: 5.33k]
  ------------------
  690|  12.3k|			if (pathlen == 2) {	/* only 3F00 supplied */
  ------------------
  |  Branch (690:8): [True: 3.30k, False: 9.00k]
  ------------------
  691|  3.30k|				select_mf = 1;
  692|  3.30k|				apdu.p1 = 0;
  693|  3.30k|				break;
  694|  3.30k|			}
  695|  9.00k|			path += 2;
  696|  9.00k|			pathlen -= 2;
  697|  9.00k|		}
  698|  14.4k|		break;
  699|  14.4k|	case SC_PATH_TYPE_FROM_CURRENT:
  ------------------
  |  |  122|    110|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
  |  Branch (699:2): [True: 110, False: 49.1k]
  ------------------
  700|    110|		apdu.p1 = 9;
  701|    110|		break;
  702|    125|	case SC_PATH_TYPE_PARENT:
  ------------------
  |  |  123|    125|#define SC_PATH_TYPE_PARENT		5
  ------------------
  |  Branch (702:2): [True: 125, False: 49.1k]
  ------------------
  703|    125|		apdu.p1 = 3;
  704|    125|		pathlen = 0;
  705|    125|		apdu.cse = SC_APDU_CASE_2_SHORT;
  ------------------
  |  |  292|    125|#define SC_APDU_CASE_2_SHORT		0x02
  ------------------
  706|    125|		break;
  707|      0|	default:
  ------------------
  |  Branch (707:2): [True: 0, False: 49.2k]
  ------------------
  708|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  709|  49.2k|	}
  710|  49.2k|	apdu.lc = pathlen;
  711|  49.2k|	apdu.data = path;
  712|  49.2k|	apdu.datalen = pathlen;
  713|       |
  714|  49.2k|	if (file_out != NULL) {
  ------------------
  |  Branch (714:6): [True: 31.9k, False: 17.2k]
  ------------------
  715|  31.9k|		apdu.p2 = 0;		/* first record, return FCI */
  716|  31.9k|		apdu.resp = buf;
  717|  31.9k|		apdu.resplen = sizeof(buf);
  718|  31.9k|		apdu.le = sc_get_max_recv_size(card) < 256 ? sc_get_max_recv_size(card) : 256;
  ------------------
  |  Branch (718:13): [True: 859, False: 31.1k]
  ------------------
  719|  31.9k|	}
  720|  17.2k|	else {
  721|  17.2k|		apdu.p2 = 0x0C;		/* first record, return nothing */
  722|  17.2k|		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
              		apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
  ------------------
  |  |  293|  34.5k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  |  Branch (722:14): [True: 0, False: 17.2k]
  ------------------
  723|  17.2k|	}
  724|       |
  725|  49.2k|	r = sc_transmit_apdu(card, &apdu);
  726|  49.2k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  49.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  49.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  49.2k|	int _ret = (r); \
  |  |  |  |  168|  49.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 386, False: 48.8k]
  |  |  |  |  ------------------
  |  |  |  |  169|    386|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    386|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    386|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    386|		return _ret; \
  |  |  |  |  172|    386|	} \
  |  |  |  |  173|  49.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 48.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  727|  48.8k|	if (file_out == NULL) {
  ------------------
  |  Branch (727:6): [True: 17.2k, False: 31.6k]
  ------------------
  728|       |		/* For some cards 'SELECT' can be only with request to return FCI/FCP. */
  729|  17.2k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  730|  17.2k|		if (apdu.sw1 == 0x6A && apdu.sw2 == 0x86)   {
  ------------------
  |  Branch (730:7): [True: 123, False: 17.1k]
  |  Branch (730:27): [True: 28, False: 95]
  ------------------
  731|     28|			apdu.p2 = 0x00;
  732|     28|			if (sc_transmit_apdu(card, &apdu) == SC_SUCCESS)
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  |  Branch (732:8): [True: 18, False: 10]
  ------------------
  733|     18|				r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  734|     28|		}
  735|  17.2k|		if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (735:7): [True: 0, False: 17.2k]
  ------------------
  736|  17.2k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  737|  17.2k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  17.2k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  17.2k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  17.2k|	int _ret = r; \
  |  |  |  |  155|  17.2k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 17.2k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  17.2k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  12.2k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 12.2k, False: 5.02k]
  |  |  |  |  ------------------
  |  |  |  |  157|  17.2k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  17.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|  17.2k|	return _ret; \
  |  |  |  |  163|  17.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  738|  17.2k|	}
  739|       |
  740|  31.6k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  741|  31.6k|	if (r)
  ------------------
  |  Branch (741:6): [True: 16.8k, False: 14.7k]
  ------------------
  742|  31.6k|		LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  16.8k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  16.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  16.8k|	int _ret = r; \
  |  |  |  |  155|  16.8k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 16.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  16.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  16.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 16.8k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  16.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  16.8k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  16.8k|	return _ret; \
  |  |  |  |  163|  16.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  743|       |
  744|  14.7k|	if (file_out && (apdu.resplen == 0))   {
  ------------------
  |  Branch (744:6): [True: 14.7k, False: 0]
  |  Branch (744:18): [True: 2.61k, False: 12.1k]
  ------------------
  745|       |		/* For some cards 'SELECT' MF or DF_NAME do not return FCI. */
  746|  2.61k|		if (select_mf || pathtype == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  2.11k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (746:7): [True: 498, False: 2.11k]
  |  Branch (746:20): [True: 1.12k, False: 985]
  ------------------
  747|  1.62k|			file = sc_file_new();
  748|  1.62k|			if (file == NULL)
  ------------------
  |  Branch (748:8): [True: 0, False: 1.62k]
  ------------------
  749|  1.62k|				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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  750|  1.62k|			file->path = *in_path;
  751|       |
  752|  1.62k|			*file_out = file;
  753|  1.62k|			LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  1.62k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.62k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.62k|	int _ret = r; \
  |  |  |  |  155|  1.62k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.62k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.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: 1.62k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.62k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.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|  1.62k|	return _ret; \
  |  |  |  |  163|  1.62k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  754|  1.62k|		}
  755|  2.61k|	}
  756|       |
  757|  13.0k|	if (apdu.resplen < 2)
  ------------------
  |  Branch (757:6): [True: 1.01k, False: 12.0k]
  ------------------
  758|  13.0k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  759|  12.0k|	switch (apdu.resp[0]) {
  760|  11.0k|	case ISO7816_TAG_FCI:
  ------------------
  |  |   15|  11.0k|#define ISO7816_TAG_FCI			0x6F
  ------------------
  |  Branch (760:2): [True: 11.0k, False: 1.05k]
  ------------------
  761|  11.6k|	case ISO7816_TAG_FCP:
  ------------------
  |  |   17|  11.6k|#define ISO7816_TAG_FCP			0x62
  ------------------
  |  Branch (761:2): [True: 673, False: 11.4k]
  ------------------
  762|  11.6k|		file = sc_file_new();
  763|  11.6k|		if (file == NULL)
  ------------------
  |  Branch (763:7): [True: 0, False: 11.6k]
  ------------------
  764|  11.6k|			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|  11.6k|		file->path = *in_path;
  766|  11.6k|		if (card->ops->process_fci == NULL) {
  ------------------
  |  Branch (766:7): [True: 0, False: 11.6k]
  ------------------
  767|      0|			sc_file_free(file);
  768|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  769|      0|		}
  770|  11.6k|		buffer = apdu.resp;
  771|  11.6k|		r = sc_asn1_read_tag(&buffer, apdu.resplen, &cla, &tag, &buffer_len);
  772|  11.6k|		if (r == SC_SUCCESS)
  ------------------
  |  |   28|  11.6k|#define SC_SUCCESS				0
  ------------------
  |  Branch (772:7): [True: 10.8k, False: 800]
  ------------------
  773|  10.8k|			card->ops->process_fci(card, file, buffer, buffer_len);
  774|  11.6k|		*file_out = file;
  775|  11.6k|		break;
  776|    108|	case 0x00: /* proprietary coding */
  ------------------
  |  Branch (776:2): [True: 108, False: 11.9k]
  ------------------
  777|    108|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    108|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    108|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    108|	int _ret = r; \
  |  |  |  |  155|    108|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 108, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    108|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    108|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 108, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    108|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    108|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    108|	return _ret; \
  |  |  |  |  163|    108|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  778|    275|	default:
  ------------------
  |  Branch (778:2): [True: 275, False: 11.8k]
  ------------------
  779|    275|		LOG_FUNC_RETURN(ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  164|    275|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    275|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    275|	int _ret = r; \
  |  |  |  |  155|    275|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 275, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    275|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    275|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 275, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    275|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    275|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    275|	return _ret; \
  |  |  |  |  163|    275|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  780|  12.0k|	}
  781|       |
  782|  11.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  11.6k|#define SC_SUCCESS				0
  ------------------
  783|  12.0k|}
iso7816.c:iso7816_get_response:
  906|  37.2k|{
  907|  37.2k|	struct sc_apdu apdu = {0};
  908|  37.2k|	int r;
  909|  37.2k|	size_t rlen;
  910|       |
  911|       |	/* request at most max_recv_size bytes */
  912|  37.2k|	if (*count > sc_get_max_recv_size(card))
  ------------------
  |  Branch (912:6): [True: 5.70k, False: 31.5k]
  ------------------
  913|  5.70k|		rlen = sc_get_max_recv_size(card);
  914|  31.5k|	else
  915|  31.5k|		rlen = *count;
  916|       |
  917|  37.2k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xC0, 0x00, 0x00);
  ------------------
  |  |  301|  37.2k|#define SC_APDU_CASE_2			0x22
  ------------------
  918|  37.2k|	apdu.le      = rlen;
  919|  37.2k|	apdu.resplen = rlen;
  920|  37.2k|	apdu.resp    = buf;
  921|       |	/* don't call GET RESPONSE recursively */
  922|  37.2k|	apdu.flags  |= SC_APDU_FLAGS_NO_GET_RESP;
  ------------------
  |  |  308|  37.2k|#define SC_APDU_FLAGS_NO_GET_RESP	0x00000002UL
  ------------------
  923|       |
  924|  37.2k|	r = sc_transmit_apdu(card, &apdu);
  925|  37.2k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  37.2k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  37.2k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  37.2k|	int _ret = (r); \
  |  |  |  |  168|  37.2k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 332, False: 36.9k]
  |  |  |  |  ------------------
  |  |  |  |  169|    332|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    332|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    332|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    332|		return _ret; \
  |  |  |  |  172|    332|	} \
  |  |  |  |  173|  37.2k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 36.9k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  926|       |
  927|  36.9k|	*count = apdu.resplen;
  928|       |
  929|  36.9k|	if (apdu.resplen == 0) {
  ------------------
  |  Branch (929:6): [True: 8.08k, False: 28.8k]
  ------------------
  930|  8.08k|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  164|  8.08k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  8.08k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  8.08k|	int _ret = r; \
  |  |  |  |  155|  8.08k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 8.08k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  8.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.90k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 3.90k, False: 4.17k]
  |  |  |  |  ------------------
  |  |  |  |  157|  8.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  8.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|  8.08k|	return _ret; \
  |  |  |  |  163|  8.08k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  931|  8.08k|	}
  932|  28.8k|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (932:6): [True: 13.8k, False: 14.9k]
  |  Branch (932:26): [True: 13.7k, False: 161]
  ------------------
  933|  13.7k|		r = 0;					/* no more data to read */
  934|  15.1k|	else if (apdu.sw1 == 0x61)
  ------------------
  |  Branch (934:11): [True: 11.0k, False: 4.07k]
  ------------------
  935|  11.0k|		r = apdu.sw2 == 0 ? 256 : apdu.sw2;	/* more data to read    */
  ------------------
  |  Branch (935:7): [True: 7.07k, False: 3.98k]
  ------------------
  936|  4.07k|	else if (apdu.sw1 == 0x62 && apdu.sw2 == 0x82)
  ------------------
  |  Branch (936:11): [True: 565, False: 3.51k]
  |  Branch (936:31): [True: 475, False: 90]
  ------------------
  937|    475|		r = 0; /* Le not reached but file/record ended */
  938|  3.60k|	else
  939|  3.60k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  940|       |
  941|  28.8k|	return r;
  942|  36.9k|}
iso7816.c:iso7816_restore_security_env:
 1078|     47|{
 1079|     47|	struct sc_apdu apdu;
 1080|     47|	int r;
 1081|       |
 1082|     47|	if (card == NULL) {
  ------------------
  |  Branch (1082:6): [True: 0, False: 47]
  ------------------
 1083|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1084|      0|	}
 1085|       |
 1086|     47|	sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
  ------------------
  |  |  291|     47|#define SC_APDU_CASE_1			0x01
  ------------------
 1087|       |
 1088|     47|	r = sc_transmit_apdu(card, &apdu);
 1089|     47|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     47|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     47|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     47|	int _ret = (r); \
  |  |  |  |  168|     47|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 15, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  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|     47|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 32]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1090|     32|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1091|     32|	LOG_TEST_RET(card->ctx, r, "Card returned 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: 15, False: 17]
  |  |  |  |  ------------------
  |  |  |  |  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|     32|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 17]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1092|       |
 1093|     17|	return r;
 1094|     32|}
iso7816.c:iso7816_set_security_env:
  983|  1.39k|{
  984|  1.39k|	struct sc_apdu apdu;
  985|  1.39k|	u8 sbuf[SC_MAX_APDU_BUFFER_SIZE];
  986|  1.39k|	u8 *p;
  987|  1.39k|	int r, locked = 0;
  988|       |
  989|  1.39k|	if (card == NULL || env == NULL) {
  ------------------
  |  Branch (989:6): [True: 0, False: 1.39k]
  |  Branch (989:22): [True: 0, False: 1.39k]
  ------------------
  990|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  991|      0|	}
  992|  1.39k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0x41, 0);
  ------------------
  |  |  293|  1.39k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  993|  1.39k|	switch (env->operation) {
  994|      0|	case SC_SEC_OPERATION_AUTHENTICATE:
  ------------------
  |  |   58|      0|#define SC_SEC_OPERATION_AUTHENTICATE	0x0003
  ------------------
  |  Branch (994:2): [True: 0, False: 1.39k]
  ------------------
  995|      0|		apdu.p2 = 0xA4;
  996|      0|		break;
  997|    349|	case SC_SEC_OPERATION_DECIPHER:
  ------------------
  |  |   56|    349|#define SC_SEC_OPERATION_DECIPHER	0x0001
  ------------------
  |  Branch (997:2): [True: 349, False: 1.04k]
  ------------------
  998|    349|	case SC_SEC_OPERATION_DERIVE:
  ------------------
  |  |   59|    349|#define SC_SEC_OPERATION_DERIVE         0x0004
  ------------------
  |  Branch (998:2): [True: 0, False: 1.39k]
  ------------------
  999|    349|		apdu.p2 = 0xB8;
 1000|    349|		break;
 1001|  1.04k|	case SC_SEC_OPERATION_SIGN:
  ------------------
  |  |   57|  1.04k|#define SC_SEC_OPERATION_SIGN		0x0002
  ------------------
  |  Branch (1001:2): [True: 1.04k, False: 349]
  ------------------
 1002|  1.04k|		apdu.p2 = 0xB6;
 1003|  1.04k|		break;
 1004|      0|	default:
  ------------------
  |  Branch (1004:2): [True: 0, False: 1.39k]
  ------------------
 1005|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1006|  1.39k|	}
 1007|  1.39k|	p = sbuf;
 1008|  1.39k|	if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
  ------------------
  |  |   65|  1.39k|#define SC_SEC_ENV_ALG_REF_PRESENT	0x0001
  ------------------
  |  Branch (1008:6): [True: 954, False: 444]
  ------------------
 1009|    954|		*p++ = 0x80;	/* algorithm reference */
 1010|    954|		*p++ = 0x01;
 1011|    954|		*p++ = env->algorithm_ref & 0xFF;
 1012|    954|	}
 1013|  1.39k|	if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
  ------------------
  |  |   66|  1.39k|#define SC_SEC_ENV_FILE_REF_PRESENT	0x0002
  ------------------
  |  Branch (1013:6): [True: 0, False: 1.39k]
  ------------------
 1014|      0|		if (env->file_ref.len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|      0|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (1014:7): [True: 0, False: 0]
  ------------------
 1015|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1016|      0|		if (sizeof(sbuf) - (p - sbuf) < env->file_ref.len + 2)
  ------------------
  |  Branch (1016:7): [True: 0, False: 0]
  ------------------
 1017|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1018|       |
 1019|      0|		*p++ = 0x81;
 1020|      0|		*p++ = (u8) env->file_ref.len;
 1021|      0|		memcpy(p, env->file_ref.value, env->file_ref.len);
 1022|      0|		p += env->file_ref.len;
 1023|      0|	}
 1024|  1.39k|	if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
  ------------------
  |  |   67|  1.39k|#define SC_SEC_ENV_KEY_REF_PRESENT	0x0004
  ------------------
  |  Branch (1024:6): [True: 1.39k, False: 0]
  ------------------
 1025|  1.39k|		if (sizeof(sbuf) - (p - sbuf) < env->key_ref_len + 2)
  ------------------
  |  Branch (1025:7): [True: 0, False: 1.39k]
  ------------------
 1026|      0|			return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      0|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
 1027|       |
 1028|  1.39k|		if (env->flags & SC_SEC_ENV_KEY_REF_SYMMETRIC)
  ------------------
  |  |   68|  1.39k|#define SC_SEC_ENV_KEY_REF_SYMMETRIC	0x0008
  ------------------
  |  Branch (1028:7): [True: 0, False: 1.39k]
  ------------------
 1029|      0|			*p++ = 0x83;
 1030|  1.39k|		else
 1031|  1.39k|			*p++ = 0x84;
 1032|  1.39k|		if (env->key_ref_len > SC_MAX_KEYREF_SIZE)
  ------------------
  |  |   53|  1.39k|#define SC_MAX_KEYREF_SIZE		8
  ------------------
  |  Branch (1032:7): [True: 0, False: 1.39k]
  ------------------
 1033|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1034|  1.39k|		*p++ = env->key_ref_len & 0xFF;
 1035|  1.39k|		memcpy(p, env->key_ref, env->key_ref_len);
 1036|  1.39k|		p += env->key_ref_len;
 1037|  1.39k|	}
 1038|  1.39k|	r = (int)(p - sbuf);
 1039|  1.39k|	apdu.lc = r;
 1040|  1.39k|	apdu.datalen = r;
 1041|  1.39k|	apdu.data = sbuf;
 1042|  1.39k|	if (se_num > 0) {
  ------------------
  |  Branch (1042:6): [True: 0, False: 1.39k]
  ------------------
 1043|      0|		r = sc_lock(card);
 1044|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1045|      0|		locked = 1;
 1046|      0|	}
 1047|  1.39k|	if (apdu.datalen != 0) {
  ------------------
  |  Branch (1047:6): [True: 1.39k, False: 0]
  ------------------
 1048|  1.39k|		r = sc_transmit_apdu(card, &apdu);
 1049|  1.39k|		if (r) {
  ------------------
  |  Branch (1049:7): [True: 19, False: 1.37k]
  ------------------
 1050|     19|			sc_log(card->ctx, "%s: APDU transmit failed", sc_strerror(r));
  ------------------
  |  |   71|     19|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1051|     19|			goto err;
 1052|     19|		}
 1053|  1.37k|		r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1054|  1.37k|		if (r) {
  ------------------
  |  Branch (1054:7): [True: 1.10k, False: 277]
  ------------------
 1055|  1.10k|			sc_log(card->ctx, "%s: Card returned error", sc_strerror(r));
  ------------------
  |  |   71|  1.10k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1056|  1.10k|			goto err;
 1057|  1.10k|		}
 1058|  1.37k|	}
 1059|    277|	if (se_num <= 0) {
  ------------------
  |  Branch (1059:6): [True: 277, False: 0]
  ------------------
 1060|    277|		r = SC_SUCCESS;
  ------------------
  |  |   28|    277|#define SC_SUCCESS				0
  ------------------
 1061|    277|		goto err;
 1062|    277|	}
 1063|      0|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
  ------------------
  |  |  293|      0|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
 1064|      0|	r = sc_transmit_apdu(card, &apdu);
 1065|      0|	sc_unlock(card);
 1066|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1067|       |
 1068|      0|	return sc_check_sw(card, apdu.sw1, apdu.sw2);
 1069|  1.39k|err:
 1070|  1.39k|	if (locked)
  ------------------
  |  Branch (1070:6): [True: 0, False: 1.39k]
  ------------------
 1071|      0|		sc_unlock(card);
 1072|  1.39k|	return r;
 1073|      0|}
iso7816.c:iso7816_decipher:
 1142|     27|{
 1143|     27|	int r;
 1144|     27|	struct sc_apdu apdu;
 1145|     27|	u8 *sbuf = NULL;
 1146|       |
 1147|     27|	if (card == NULL || crgram == NULL || out == NULL) {
  ------------------
  |  Branch (1147:6): [True: 0, False: 27]
  |  Branch (1147:22): [True: 0, False: 27]
  |  Branch (1147:40): [True: 0, False: 27]
  ------------------
 1148|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1149|      0|	}
 1150|     27|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     27|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     27|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     27|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     27|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 27]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1151|     27|	sc_log(card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1152|     27|	       "ISO7816 decipher: in-len %"SC_FORMAT_LEN_SIZE_T"u, out-len %"SC_FORMAT_LEN_SIZE_T"u",
 1153|     27|	       crgram_len, outlen);
 1154|       |
 1155|     27|	sbuf = malloc(crgram_len + 1);
 1156|     27|	if (sbuf == NULL)
  ------------------
  |  Branch (1156:6): [True: 0, False: 27]
  ------------------
 1157|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1158|       |
 1159|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1160|       |	 * P1:  0x80  Resp: Plain value
 1161|       |	 * P2:  0x86  Cmd: Padding indicator byte followed by cryptogram */
 1162|     27|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x80, 0x86);
  ------------------
  |  |  303|     27|#define SC_APDU_CASE_4			0x24
  ------------------
 1163|     27|	apdu.resp    = out;
 1164|     27|	apdu.resplen = outlen;
 1165|     27|	apdu.le      = outlen;
 1166|       |
 1167|     27|	sbuf[0] = 0; /* padding indicator byte, 0x00 = No further indication */
 1168|     27|	memcpy(sbuf + 1, crgram, crgram_len);
 1169|     27|	apdu.data = sbuf;
 1170|     27|	apdu.lc = crgram_len + 1;
 1171|     27|	apdu.datalen = crgram_len + 1;
 1172|       |
 1173|     27|	iso7816_fixup_transceive_length(card, &apdu);
 1174|     27|	r = sc_transmit_apdu(card, &apdu);
 1175|     27|	sc_mem_clear(sbuf, crgram_len + 1);
 1176|     27|	free(sbuf);
 1177|     27|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|     27|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|     27|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|     27|	int _ret = (r); \
  |  |  |  |  168|     27|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 4, False: 23]
  |  |  |  |  ------------------
  |  |  |  |  169|      4|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      4|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      4|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      4|		return _ret; \
  |  |  |  |  172|      4|	} \
  |  |  |  |  173|     27|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 23]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1178|       |
 1179|     23|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1179:6): [True: 16, False: 7]
  |  Branch (1179:26): [True: 13, False: 3]
  ------------------
 1180|     23|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 3, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  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|     10|	} else { \
  |  |  |  |  159|     10|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|     10|			"returning with: %d\n", _ret); \
  |  |  |  |  161|     10|	} \
  |  |  |  |  162|     13|	return _ret; \
  |  |  |  |  163|     13|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1181|     10|	else
 1182|     23|		LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1183|     23|}
iso7816.c:iso7816_compute_signature:
 1101|    143|{
 1102|    143|	int r;
 1103|    143|	struct sc_apdu apdu;
 1104|       |
 1105|    143|	if (card == NULL || data == NULL || out == NULL) {
  ------------------
  |  Branch (1105:6): [True: 0, False: 143]
  |  Branch (1105:22): [True: 0, False: 143]
  |  Branch (1105:38): [True: 0, False: 143]
  ------------------
 1106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1107|      0|	}
 1108|    143|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    143|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1109|    143|	sc_log(card->ctx,
  ------------------
  |  |   71|    143|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1110|    143|	       "ISO7816 compute signature: in-len %"SC_FORMAT_LEN_SIZE_T"u, out-len %"SC_FORMAT_LEN_SIZE_T"u",
 1111|    143|	       datalen, outlen);
 1112|       |
 1113|       |	/* INS: 0x2A  PERFORM SECURITY OPERATION
 1114|       |	 * P1:  0x9E  Resp: Digital Signature
 1115|       |	 * P2:  0x9A  Cmd: Input for Digital Signature */
 1116|    143|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4, 0x2A, 0x9E, 0x9A);
  ------------------
  |  |  303|    143|#define SC_APDU_CASE_4			0x24
  ------------------
 1117|    143|	apdu.resp = out;
 1118|    143|	apdu.resplen = outlen;
 1119|    143|	apdu.le = outlen;
 1120|       |
 1121|    143|	apdu.data = data;
 1122|    143|	apdu.lc = datalen;
 1123|    143|	apdu.datalen = datalen;
 1124|       |
 1125|    143|	iso7816_fixup_transceive_length(card, &apdu);
 1126|    143|	r = sc_transmit_apdu(card, &apdu);
 1127|    143|	LOG_TEST_RET(card->ctx, r, "APDU transmit 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: 37, False: 106]
  |  |  |  |  ------------------
  |  |  |  |  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|    143|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 106]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1128|    106|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (1128:6): [True: 75, False: 31]
  |  Branch (1128:26): [True: 56, False: 19]
  ------------------
 1129|    106|		LOG_FUNC_RETURN(card->ctx, (int)apdu.resplen);
  ------------------
  |  |  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: 24, False: 32]
  |  |  |  |  ------------------
  |  |  |  |  156|     24|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 24]
  |  |  |  |  ------------------
  |  |  |  |  157|     24|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|     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|     56|	return _ret; \
  |  |  |  |  163|     56|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1130|       |
 1131|     50|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1132|     50|	LOG_TEST_RET(card->ctx, r, "Card returned error");
  ------------------
  |  |  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: 50, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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|     50|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1133|       |
 1134|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1135|      0|}
iso7816.c:iso7816_check_sw:
  111|   402k|{
  112|   402k|	const int err_count = sizeof(iso7816_errors)/sizeof(iso7816_errors[0]);
  113|   402k|	int i;
  114|       |
  115|       |	/* Handle special cases here */
  116|   402k|	if (sw1 == 0x6C) {
  ------------------
  |  Branch (116:6): [True: 179, False: 402k]
  ------------------
  117|    179|		sc_log(card->ctx, "Wrong length; correct length is %d", sw2);
  ------------------
  |  |   71|    179|#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|    179|		return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|    179|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
  119|    179|	}
  120|   402k|	if (sw1 == 0x90 && sw2 == 0x00)
  ------------------
  |  Branch (120:6): [True: 146k, False: 255k]
  |  Branch (120:21): [True: 140k, False: 5.77k]
  ------------------
  121|   140k|		return SC_SUCCESS;
  ------------------
  |  |   28|   140k|#define SC_SUCCESS				0
  ------------------
  122|   261k|	if (sw1 == 0x63U && (sw2 & ~0x0fU) == 0xc0U) {
  ------------------
  |  Branch (122:6): [True: 793, False: 260k]
  |  Branch (122:22): [True: 137, False: 656]
  ------------------
  123|    137|		sc_log(card->ctx, "PIN not verified (remaining tries: %d)", (sw2 & 0x0f));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  124|    137|		return SC_ERROR_PIN_CODE_INCORRECT;
  ------------------
  |  |   64|    137|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  125|    137|	}
  126|  10.6M|	for (i = 0; i < err_count; i++)   {
  ------------------
  |  Branch (126:14): [True: 10.6M, False: 30.2k]
  ------------------
  127|  10.6M|		if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
  ------------------
  |  Branch (127:7): [True: 231k, False: 10.4M]
  ------------------
  128|   231k|			sc_log(card->ctx, "%s", iso7816_errors[i].errorstr);
  ------------------
  |  |   71|   231k|#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|   231k|			return iso7816_errors[i].errorno;
  130|   231k|		}
  131|  10.6M|	}
  132|       |
  133|  30.2k|	sc_log(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X", sw1, sw2);
  ------------------
  |  |   71|  30.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__
  |  |  ------------------
  ------------------
  134|  30.2k|	return SC_ERROR_CARD_CMD_FAILED;
  ------------------
  |  |   50|  30.2k|#define SC_ERROR_CARD_CMD_FAILED		-1200
  ------------------
  135|   261k|}
iso7816.c:iso7816_process_fci:
  431|  9.49k|{
  432|  9.49k|	struct sc_context *ctx = card->ctx;
  433|  9.49k|	const unsigned char *p, *end;
  434|  9.49k|	unsigned int cla = 0, tag = 0;
  435|  9.49k|	size_t length;
  436|       |
  437|  9.49k|	file->status = SC_FILE_STATUS_UNKNOWN;
  ------------------
  |  |  254|  9.49k|#define SC_FILE_STATUS_UNKNOWN		0xff /* if tag 0x8A is missing, there is no information about LCSB */
  ------------------
  438|       |
  439|  9.49k|	for (p = buf, length = buflen, end = buf + buflen;
  440|  27.5k|			p < end;
  ------------------
  |  Branch (440:4): [True: 24.3k, False: 3.28k]
  ------------------
  441|  24.3k|			p += length, length = end - p) {
  442|       |
  443|  24.3k|		if (SC_SUCCESS != sc_asn1_read_tag(&p, length, &cla, &tag, &length)
  ------------------
  |  |   28|  24.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (443:7): [True: 4.18k, False: 20.1k]
  ------------------
  444|  20.1k|				|| p == NULL) {
  ------------------
  |  Branch (444:8): [True: 2.02k, False: 18.0k]
  ------------------
  445|  6.21k|			break;
  446|  6.21k|		}
  447|  18.0k|		switch (cla | tag) {
  ------------------
  |  Branch (447:11): [True: 13.8k, False: 4.19k]
  ------------------
  448|  1.88k|			case 0x81:
  ------------------
  |  Branch (448:4): [True: 1.88k, False: 16.2k]
  ------------------
  449|  1.88k|				if (file->size != 0) {
  ------------------
  |  Branch (449:9): [True: 87, False: 1.79k]
  ------------------
  450|       |					/* don't overwrite existing file size excluding structural information */
  451|     87|					break;
  452|     87|				}
  453|       |				/* fall through */
  454|  3.81k|			case 0x80:
  ------------------
  |  Branch (454:4): [True: 2.01k, False: 16.0k]
  ------------------
  455|       |				/* determine the file size */
  456|  3.81k|				file->size = 0;
  457|  3.81k|				if (p && length <= sizeof(size_t)) {
  ------------------
  |  Branch (457:9): [True: 3.81k, False: 0]
  |  Branch (457:14): [True: 3.77k, False: 40]
  ------------------
  458|  3.77k|					size_t size = 0, i;
  459|  12.1k|					for (i = 0; i < length; i++) {
  ------------------
  |  Branch (459:18): [True: 8.37k, False: 3.77k]
  ------------------
  460|  8.37k|						size <<= 8;
  461|  8.37k|						size |= p[i];
  462|  8.37k|					}
  463|  3.77k|					if (size > MAX_FILE_SIZE) {
  ------------------
  |  |  229|  3.77k|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (463:10): [True: 479, False: 3.29k]
  ------------------
  464|    479|						file->size = MAX_FILE_SIZE;
  ------------------
  |  |  229|    479|#define MAX_FILE_SIZE 65535
  ------------------
  465|    479|						sc_log(ctx, "  file size truncated, encoded length: %"SC_FORMAT_LEN_SIZE_T"u", size);
  ------------------
  |  |   71|    479|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  466|  3.29k|					} else {
  467|  3.29k|						file->size = size;
  468|  3.29k|					}
  469|  3.77k|				}
  470|       |
  471|  3.81k|				sc_log(ctx, "  bytes in file: %"SC_FORMAT_LEN_SIZE_T"u", file->size);
  ------------------
  |  |   71|  3.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__
  |  |  ------------------
  ------------------
  472|  3.81k|				break;
  473|       |
  474|  1.97k|			case 0x82:
  ------------------
  |  Branch (474:4): [True: 1.97k, False: 16.1k]
  ------------------
  475|  1.97k|				if (length > 0) {
  ------------------
  |  Branch (475:9): [True: 1.73k, False: 240]
  ------------------
  476|  1.73k|					unsigned char byte = p[0];
  477|  1.73k|					const char *type;
  478|       |
  479|  1.73k|					file->shareable = byte & 0x40 ? 1 : 0;
  ------------------
  |  Branch (479:24): [True: 313, False: 1.42k]
  ------------------
  480|  1.73k|					sc_log(ctx, "  shareable: %s", (byte & 0x40) ? "yes" : "no");
  ------------------
  |  |   71|  3.47k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  |  Branch (71:122): [True: 313, False: 1.42k]
  |  |  ------------------
  ------------------
  481|  1.73k|					file->ef_structure = byte & 0x07;
  482|  1.73k|					switch ((byte >> 3) & 7) {
  483|  1.00k|						case 0:
  ------------------
  |  Branch (483:7): [True: 1.00k, False: 736]
  ------------------
  484|  1.00k|							type = "working EF";
  485|  1.00k|							file->type = SC_FILE_TYPE_WORKING_EF;
  ------------------
  |  |  216|  1.00k|#define SC_FILE_TYPE_WORKING_EF		0x01
  ------------------
  486|  1.00k|							break;
  487|    231|						case 1:
  ------------------
  |  Branch (487:7): [True: 231, False: 1.50k]
  ------------------
  488|    231|							type = "internal EF";
  489|    231|							file->type = SC_FILE_TYPE_INTERNAL_EF;
  ------------------
  |  |  215|    231|#define SC_FILE_TYPE_INTERNAL_EF	0x03
  ------------------
  490|    231|							break;
  491|    212|						case 7:
  ------------------
  |  Branch (491:7): [True: 212, False: 1.52k]
  ------------------
  492|    212|							type = "DF";
  493|    212|							file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    212|#define SC_FILE_TYPE_DF			0x04
  ------------------
  494|    212|							break;
  495|    293|						default:
  ------------------
  |  Branch (495:7): [True: 293, False: 1.44k]
  ------------------
  496|    293|							file->type = SC_FILE_TYPE_UNKNOWN;
  ------------------
  |  |  213|    293|#define SC_FILE_TYPE_UNKNOWN		0x00
  ------------------
  497|    293|							type = "unknown";
  498|    293|							break;
  499|  1.73k|					}
  500|  1.73k|					sc_log(ctx, "  type: %s", type);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  501|  1.73k|					sc_log(ctx, "  EF structure: %d", byte & 0x07);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  502|  1.73k|					sc_log(ctx, "  tag 0x82: 0x%02x", byte);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  503|       |
  504|       |					/* if possible, get additional information for non-DFs */
  505|  1.73k|					if (file->type != SC_FILE_TYPE_DF) {
  ------------------
  |  |  214|  1.73k|#define SC_FILE_TYPE_DF			0x04
  ------------------
  |  Branch (505:10): [True: 1.52k, False: 212]
  ------------------
  506|       |						/* max. record length for fixed- & variable-sized records */
  507|  1.52k|						if (length > 2 && byte & 0x06) {
  ------------------
  |  Branch (507:11): [True: 590, False: 934]
  |  Branch (507:25): [True: 449, False: 141]
  ------------------
  508|    449|							file->record_length = (length > 3)
  ------------------
  |  Branch (508:30): [True: 366, False: 83]
  ------------------
  509|    449|								? bebytes2ushort(p+2)
  510|    449|								: p[2];
  511|    449|							sc_log(ctx, "  record length: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   71|    449|#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|    449|								file->record_length);
  513|    449|						}
  514|       |
  515|       |						/* number of records */
  516|  1.52k|						if (length > 4) {
  ------------------
  |  Branch (516:11): [True: 304, False: 1.22k]
  ------------------
  517|    304|							file->record_count = (length > 5)
  ------------------
  |  Branch (517:29): [True: 69, False: 235]
  ------------------
  518|    304|								? bebytes2ushort(p+4)
  519|    304|								: p[4];
  520|    304|							sc_log(ctx, "  records: %"SC_FORMAT_LEN_SIZE_T"u",
  ------------------
  |  |   71|    304|#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|    304|								file->record_count);
  522|    304|						}
  523|  1.52k|					}
  524|       |
  525|  1.73k|					if (SC_SUCCESS != sc_file_set_type_attr(file, p, length))
  ------------------
  |  |   28|  1.73k|#define SC_SUCCESS				0
  ------------------
  |  Branch (525:10): [True: 0, False: 1.73k]
  ------------------
  526|      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__
  |  |  ------------------
  ------------------
  527|  1.73k|				}
  528|  1.97k|				break;
  529|       |
  530|  1.97k|			case 0x83:
  ------------------
  |  Branch (530:4): [True: 1.22k, False: 16.8k]
  ------------------
  531|  1.22k|				if (length == 2) {
  ------------------
  |  Branch (531:9): [True: 893, False: 334]
  ------------------
  532|    893|					file->id = (p[0] << 8) | p[1];
  533|    893|					sc_log(ctx, "  file identifier: 0x%02X%02X", p[0], p[1]);
  ------------------
  |  |   71|    893|#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|    893|				}
  535|  1.22k|				break;
  536|       |
  537|    608|			case 0x84:
  ------------------
  |  Branch (537:4): [True: 608, False: 17.4k]
  ------------------
  538|    608|				if (length > 0 && length <= 16) {
  ------------------
  |  Branch (538:9): [True: 402, False: 206]
  |  Branch (538:23): [True: 384, False: 18]
  ------------------
  539|    384|					memcpy(file->name, p, length);
  540|    384|					file->namelen = length;
  541|       |
  542|    384|					sc_log_hex(ctx, "  File name:", file->name, file->namelen);
  ------------------
  |  |  129|    384|    sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
  |  |  ------------------
  |  |  |  |  127|    384|    _sc_debug_hex(ctx, level, FILENAME, __LINE__, __FUNCTION__, label, data, len)
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  543|    384|					if (!file->type)
  ------------------
  |  Branch (543:10): [True: 243, False: 141]
  ------------------
  544|    243|						file->type = SC_FILE_TYPE_DF;
  ------------------
  |  |  214|    243|#define SC_FILE_TYPE_DF			0x04
  ------------------
  545|    384|				}
  546|    608|				break;
  547|       |
  548|  1.00k|			case 0x85:
  ------------------
  |  Branch (548:4): [True: 1.00k, False: 17.0k]
  ------------------
  549|  1.31k|			case 0xA5:
  ------------------
  |  Branch (549:4): [True: 316, False: 17.7k]
  ------------------
  550|  1.31k|				if (SC_SUCCESS != sc_file_set_prop_attr(file, p, length)) {
  ------------------
  |  |   28|  1.31k|#define SC_SUCCESS				0
  ------------------
  |  Branch (550:9): [True: 0, False: 1.31k]
  ------------------
  551|      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__
  |  |  ------------------
  ------------------
  552|      0|				}
  553|  1.31k|				break;
  554|       |
  555|  1.26k|			case 0x86:
  ------------------
  |  Branch (555:4): [True: 1.26k, False: 16.8k]
  ------------------
  556|  1.26k|				if (SC_SUCCESS != sc_file_set_sec_attr(file, p, length)) {
  ------------------
  |  |   28|  1.26k|#define SC_SUCCESS				0
  ------------------
  |  Branch (556:9): [True: 0, False: 1.26k]
  ------------------
  557|      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__
  |  |  ------------------
  ------------------
  558|      0|				}
  559|  1.26k|				break;
  560|       |
  561|    477|			case 0x88:
  ------------------
  |  Branch (561:4): [True: 477, False: 17.6k]
  ------------------
  562|    477|				if (length == 1) {
  ------------------
  |  Branch (562:9): [True: 102, False: 375]
  ------------------
  563|    102|					file->sid = *p;
  564|    102|					sc_log(ctx, "  short file identifier: 0x%02X", *p);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  565|    102|				}
  566|    477|				break;
  567|       |
  568|  1.50k|			case 0x8A:
  ------------------
  |  Branch (568:4): [True: 1.50k, False: 16.5k]
  ------------------
  569|  1.50k|				if (length == 1) {
  ------------------
  |  Branch (569:9): [True: 1.24k, False: 260]
  ------------------
  570|  1.24k|					switch (p[0]) {
  571|     67|						case 0:
  ------------------
  |  Branch (571:7): [True: 67, False: 1.17k]
  ------------------
  572|     67|							file->status =SC_FILE_STATUS_NO_INFO;
  ------------------
  |  |  243|     67|#define SC_FILE_STATUS_NO_INFO		0x04 /* ISO7816-4: No information given, (0) */
  ------------------
  573|     67|							break;
  574|     73|						case 1:
  ------------------
  |  Branch (574:7): [True: 73, False: 1.16k]
  ------------------
  575|     73|							file->status = SC_FILE_STATUS_CREATION;
  ------------------
  |  |  240|     73|#define SC_FILE_STATUS_CREATION		0x02 /* ISO7816-4: Creation state, (1) */
  ------------------
  576|     73|							break;
  577|     70|						case 3:
  ------------------
  |  Branch (577:7): [True: 70, False: 1.17k]
  ------------------
  578|     70|							file->status = SC_FILE_STATUS_INITIALISATION;
  ------------------
  |  |  242|     70|#define SC_FILE_STATUS_INITIALISATION	0x03 /* ISO7816-4: Initialisation state, (3) */
  ------------------
  579|     70|							break;
  580|     66|						case 4:
  ------------------
  |  Branch (580:7): [True: 66, False: 1.17k]
  ------------------
  581|    132|						case 6:
  ------------------
  |  Branch (581:7): [True: 66, False: 1.17k]
  ------------------
  582|    132|							file->status = SC_FILE_STATUS_INVALIDATED;
  ------------------
  |  |  237|    132|#define SC_FILE_STATUS_INVALIDATED	0x01 /* ISO7816-4: Operational state (deactivated) (4, 6) */
  ------------------
  583|    132|							break;
  584|    139|						case 5:
  ------------------
  |  Branch (584:7): [True: 139, False: 1.10k]
  ------------------
  585|    207|						case 7:
  ------------------
  |  Branch (585:7): [True: 68, False: 1.17k]
  ------------------
  586|    207|							file->status = SC_FILE_STATUS_ACTIVATED;
  ------------------
  |  |  236|    207|#define SC_FILE_STATUS_ACTIVATED	0x00 /* ISO7816-4: Operational state (activated)   (5, 7) */
  ------------------
  587|    207|							break;
  588|     66|						case 12:
  ------------------
  |  Branch (588:7): [True: 66, False: 1.17k]
  ------------------
  589|    132|						case 13:
  ------------------
  |  Branch (589:7): [True: 66, False: 1.17k]
  ------------------
  590|    204|						case 14:
  ------------------
  |  Branch (590:7): [True: 72, False: 1.16k]
  ------------------
  591|    270|						case 15:
  ------------------
  |  Branch (591:7): [True: 66, False: 1.17k]
  ------------------
  592|    270|							file->status = SC_FILE_STATUS_TERMINATION;
  ------------------
  |  |  244|    270|#define SC_FILE_STATUS_TERMINATION	0x0c /* ISO7816-4: Termination state (12,13,14,15) */
  ------------------
  593|    270|							break;
  594|     69|						case 2:
  ------------------
  |  Branch (594:7): [True: 69, False: 1.17k]
  ------------------
  595|     69|							file->status = SC_FILE_STATUS_RFU_2;
  ------------------
  |  |  248|     69|#define SC_FILE_STATUS_RFU_2		0x07 /* ISO7816-4: (0x02) */
  ------------------
  596|     69|							break;
  597|     70|						case 8:
  ------------------
  |  Branch (597:7): [True: 70, False: 1.17k]
  ------------------
  598|     70|							file->status = SC_FILE_STATUS_RFU_8;
  ------------------
  |  |  249|     70|#define SC_FILE_STATUS_RFU_8		0x08 /* ISO7816-4: (0x08) */
  ------------------
  599|     70|							break;
  600|     68|						case 9:
  ------------------
  |  Branch (600:7): [True: 68, False: 1.17k]
  ------------------
  601|     68|							file->status = SC_FILE_STATUS_RFU_9;
  ------------------
  |  |  250|     68|#define SC_FILE_STATUS_RFU_9		0x09 /* ISO7816-4: (0x09) */
  ------------------
  602|     68|							break;
  603|     70|						case 10:
  ------------------
  |  Branch (603:7): [True: 70, False: 1.17k]
  ------------------
  604|     70|							file->status = SC_FILE_STATUS_RFU_10;
  ------------------
  |  |  251|     70|#define SC_FILE_STATUS_RFU_10		0x0a /* ISO7816-4: (0x0a) */
  ------------------
  605|     70|							break;
  606|     67|						case 11:
  ------------------
  |  Branch (606:7): [True: 67, False: 1.17k]
  ------------------
  607|     67|							file->status = SC_FILE_STATUS_RFU_11;
  ------------------
  |  |  252|     67|#define SC_FILE_STATUS_RFU_11		0x0b /* ISO7816-4: (0x0b) */
  ------------------
  608|     67|							break;
  609|     77|						default:
  ------------------
  |  Branch (609:7): [True: 77, False: 1.16k]
  ------------------
  610|     77|							file->status = SC_FILE_STATUS_PROPRIETARY;
  ------------------
  |  |  245|     77|#define SC_FILE_STATUS_PROPRIETARY	0xf0 /* ISO7816-4: codes > 15 */
  ------------------
  611|  1.24k|					}
  612|  1.24k|				}
  613|  1.50k|				break;
  614|       |
  615|  1.50k|			case 0x62:
  ------------------
  |  Branch (615:4): [True: 973, False: 17.1k]
  ------------------
  616|  1.10k|			case 0x64:
  ------------------
  |  Branch (616:4): [True: 127, False: 17.9k]
  ------------------
  617|  1.62k|			case 0x6F:
  ------------------
  |  Branch (617:4): [True: 529, False: 17.5k]
  ------------------
  618|       |				/* allow nested FCP/FMD/FCI templates */
  619|  1.62k|				iso7816_process_fci(card, file, p, length);
  620|  18.0k|		}
  621|  18.0k|	}
  622|       |
  623|  9.49k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|  9.49k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  624|       |
  625|  9.49k|	return SC_SUCCESS;
  ------------------
  |  |   28|  9.49k|#define SC_SUCCESS				0
  ------------------
  626|  9.49k|}
iso7816.c:iso7816_pin_cmd:
 1288|  7.52k|{
 1289|  7.52k|	struct sc_apdu local_apdu, *apdu;
 1290|  7.52k|	int r;
 1291|  7.52k|	u8  sbuf[SC_MAX_APDU_BUFFER_SIZE];
 1292|       |
 1293|  7.52k|	data->pin1.tries_left = -1;
 1294|  7.52k|	if (tries_left != NULL) {
  ------------------
  |  Branch (1294:6): [True: 1.48k, False: 6.04k]
  ------------------
 1295|  1.48k|		*tries_left = data->pin1.tries_left;
 1296|  1.48k|	}
 1297|       |
 1298|       |	/* Many cards do support PIN status queries, but some cards don't and
 1299|       |	 * mistakenly count the command as a failed PIN attempt, so for now we
 1300|       |	 * allow cards with this flag.  In future this may be reduced to a
 1301|       |	 * blocklist, subject to testing more cards. */
 1302|  7.52k|	if (data->cmd == SC_PIN_CMD_GET_INFO &&
  ------------------
  |  |  425|  15.0k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1302:6): [True: 6.06k, False: 1.46k]
  ------------------
 1303|  6.06k|	    !(card->caps & SC_CARD_CAP_ISO7816_PIN_INFO)) {
  ------------------
  |  |  560|  6.06k|#define SC_CARD_CAP_ISO7816_PIN_INFO	0x00000008
  ------------------
  |  Branch (1303:6): [True: 133, False: 5.92k]
  ------------------
 1304|    133|		sc_log(card->ctx, "Card does not support PIN status queries");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1305|    133|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|    133|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1306|    133|	}
 1307|       |
 1308|       |	/* See if we've been called from another card driver, which is
 1309|       |	 * passing an APDU to us (this allows to write card drivers
 1310|       |	 * whose PIN functions behave "mostly like ISO" except in some
 1311|       |	 * special circumstances.
 1312|       |	 */
 1313|  7.39k|	if (data->apdu == NULL) {
  ------------------
  |  Branch (1313:6): [True: 7.39k, False: 5]
  ------------------
 1314|  7.39k|		r = iso7816_build_pin_apdu(card, &local_apdu, data, sbuf, sizeof(sbuf));
 1315|  7.39k|		if (r < 0)
  ------------------
  |  Branch (1315:7): [True: 77, False: 7.31k]
  ------------------
 1316|     77|			return r;
 1317|  7.31k|		data->apdu = &local_apdu;
 1318|  7.31k|	}
 1319|  7.31k|	apdu = data->apdu;
 1320|       |
 1321|  7.31k|	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  428|  7.31k|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
              	if (!(data->flags & SC_PIN_CMD_USE_PINPAD) || data->cmd == SC_PIN_CMD_GET_INFO) {
  ------------------
  |  |  425|      0|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1321:6): [True: 7.31k, False: 0]
  |  Branch (1321:48): [True: 0, False: 0]
  ------------------
 1322|       |		/* Transmit the APDU to the card */
 1323|  7.31k|		r = sc_transmit_apdu(card, apdu);
 1324|       |
 1325|       |		/* Clear the buffer - it may contain pins */
 1326|  7.31k|		sc_mem_clear(sbuf, sizeof(sbuf));
 1327|  7.31k|	}
 1328|      0|	else {
 1329|       |		/* Call the reader driver to collect
 1330|       |		 * the PIN and pass on the APDU to the card */
 1331|      0|		if (data->pin1.offset == 0) {
  ------------------
  |  Branch (1331:7): [True: 0, False: 0]
  ------------------
 1332|      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__
  |  |  ------------------
  ------------------
 1333|      0|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1334|      0|		}
 1335|      0|		if (card->reader && card->reader->ops && card->reader->ops->perform_verify) {
  ------------------
  |  Branch (1335:7): [True: 0, False: 0]
  |  Branch (1335:23): [True: 0, False: 0]
  |  Branch (1335:44): [True: 0, False: 0]
  ------------------
 1336|      0|			r = card->reader->ops->perform_verify(card->reader, data);
 1337|       |			/* sw1/sw2 filled in by reader driver */
 1338|      0|		}
 1339|      0|		else {
 1340|      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__
  |  |  ------------------
  ------------------
 1341|      0|					"PIN entry through reader key pad");
 1342|      0|			r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
 1343|      0|		}
 1344|      0|	}
 1345|       |
 1346|       |	/* Don't pass references to local variables up to the caller. */
 1347|  7.31k|	if (data->apdu == &local_apdu)
  ------------------
  |  Branch (1347:6): [True: 7.31k, False: 5]
  ------------------
 1348|  7.31k|		data->apdu = NULL;
 1349|       |
 1350|  7.31k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  7.31k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  7.31k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  7.31k|	int _ret = (r); \
  |  |  |  |  168|  7.31k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 44, False: 7.27k]
  |  |  |  |  ------------------
  |  |  |  |  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|  7.31k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 7.27k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1351|  7.27k|	r = sc_check_sw(card, apdu->sw1, apdu->sw2);
 1352|       |
 1353|  7.27k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  7.27k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1353:6): [True: 1.86k, False: 5.41k]
  ------------------
 1354|  1.86k|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_IN;
  ------------------
  |  |  439|  1.86k|#define SC_PIN_STATE_LOGGED_IN  2
  ------------------
 1355|  5.41k|	} else if (r == SC_ERROR_PIN_CODE_INCORRECT) {
  ------------------
  |  |   64|  5.41k|#define SC_ERROR_PIN_CODE_INCORRECT		-1214
  ------------------
  |  Branch (1355:13): [True: 40, False: 5.37k]
  ------------------
 1356|     40|		data->pin1.tries_left = apdu->sw2 & 0xF;
 1357|     40|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|     40|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1358|     40|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|     40|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1358:7): [True: 16, False: 24]
  ------------------
 1359|     16|			r = SC_SUCCESS;
  ------------------
  |  |   28|     16|#define SC_SUCCESS				0
  ------------------
 1360|  5.37k|	} else if (r == SC_ERROR_AUTH_METHOD_BLOCKED) {
  ------------------
  |  |   62|  5.37k|#define SC_ERROR_AUTH_METHOD_BLOCKED		-1212
  ------------------
  |  Branch (1360:13): [True: 6, False: 5.36k]
  ------------------
 1361|      6|		data->pin1.tries_left = 0;
 1362|      6|		data->pin1.logged_in = SC_PIN_STATE_LOGGED_OUT;
  ------------------
  |  |  438|      6|#define SC_PIN_STATE_LOGGED_OUT 1
  ------------------
 1363|      6|		if (data->cmd == SC_PIN_CMD_GET_INFO)
  ------------------
  |  |  425|      6|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (1363:7): [True: 3, False: 3]
  ------------------
 1364|      3|			r = SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
 1365|      6|	}
 1366|  7.27k|	if (tries_left != NULL) {
  ------------------
  |  Branch (1366:6): [True: 1.37k, False: 5.89k]
  ------------------
 1367|  1.37k|		*tries_left = data->pin1.tries_left;
 1368|  1.37k|	}
 1369|       |
 1370|  7.27k|	return r;
 1371|  7.31k|}
iso7816.c:iso7816_get_data:
 1375|    209|{
 1376|    209|	int                             r, cse;
 1377|    209|	struct sc_apdu                  apdu;
 1378|       |
 1379|    209|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|    209|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    209|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    209|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 209]
  |  |  ------------------
  ------------------
 1380|       |
 1381|    209|	if (buf && len)
  ------------------
  |  Branch (1381:6): [True: 209, False: 0]
  |  Branch (1381:13): [True: 209, False: 0]
  ------------------
 1382|    209|		cse = SC_APDU_CASE_2;
  ------------------
  |  |  301|    209|#define SC_APDU_CASE_2			0x22
  ------------------
 1383|      0|	else
 1384|      0|		cse = SC_APDU_CASE_1;
  ------------------
  |  |  291|      0|#define SC_APDU_CASE_1			0x01
  ------------------
 1385|       |
 1386|    209|	sc_format_apdu(card, &apdu, cse, 0xCA, (tag >> 8) & 0xff, tag & 0xff);
 1387|    209|	apdu.le = len;
 1388|    209|	apdu.resp = buf;
 1389|    209|	apdu.resplen = len;
 1390|    209|	r = sc_transmit_apdu(card, &apdu);
 1391|    209|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    209|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    209|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    209|	int _ret = (r); \
  |  |  |  |  168|    209|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 5, False: 204]
  |  |  |  |  ------------------
  |  |  |  |  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|    209|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 204]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1392|       |
 1393|    204|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
 1394|    204|	LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
  ------------------
  |  |  174|    204|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    204|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    204|	int _ret = (r); \
  |  |  |  |  168|    204|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 54, False: 150]
  |  |  |  |  ------------------
  |  |  |  |  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|    204|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 150]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1395|       |
 1396|    150|	if (apdu.resplen > len)
  ------------------
  |  Branch (1396:6): [True: 0, False: 150]
  ------------------
 1397|      0|		r = SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 1398|    150|	else
 1399|    150|		r = (int)apdu.resplen;
 1400|       |
 1401|    150|	LOG_FUNC_RETURN(card->ctx, r);
  ------------------
  |  |  164|    150|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    150|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    150|	int _ret = r; \
  |  |  |  |  155|    150|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 37, False: 113]
  |  |  |  |  ------------------
  |  |  |  |  156|     37|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 37]
  |  |  |  |  ------------------
  |  |  |  |  157|     37|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    113|	} else { \
  |  |  |  |  159|    113|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|    113|			"returning with: %d\n", _ret); \
  |  |  |  |  161|    113|	} \
  |  |  |  |  162|    150|	return _ret; \
  |  |  |  |  163|    150|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1402|    150|}
iso7816.c:iso7816_read_binary:
  140|  28.8k|{
  141|  28.8k|	struct sc_context *ctx = card->ctx;
  142|  28.8k|	struct sc_apdu apdu;
  143|  28.8k|	int r;
  144|       |
  145|  28.8k|	if (idx > 0x7FFF) {
  ------------------
  |  Branch (145:6): [True: 1, False: 28.8k]
  ------------------
  146|      1|		sc_log(ctx, "invalid EF offset: 0x%X > 0x7FFF", idx);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  147|      1|		return SC_ERROR_OFFSET_TOO_LARGE;
  ------------------
  |  |   96|      1|#define SC_ERROR_OFFSET_TOO_LARGE		-1415
  ------------------
  148|      1|	}
  149|       |
  150|  28.8k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0xB0, (idx >> 8) & 0x7F, idx & 0xFF);
  ------------------
  |  |  301|  28.8k|#define SC_APDU_CASE_2			0x22
  ------------------
  151|  28.8k|	apdu.le = count;
  152|  28.8k|	apdu.resplen = count;
  153|  28.8k|	apdu.resp = buf;
  154|       |
  155|  28.8k|	iso7816_fixup_transceive_length(card, &apdu);
  156|  28.8k|	r = sc_transmit_apdu(card, &apdu);
  157|  28.8k|	LOG_TEST_RET(ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  28.8k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  28.8k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  28.8k|	int _ret = (r); \
  |  |  |  |  168|  28.8k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 285, False: 28.5k]
  |  |  |  |  ------------------
  |  |  |  |  169|    285|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    285|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    285|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    285|		return _ret; \
  |  |  |  |  172|    285|	} \
  |  |  |  |  173|  28.8k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 28.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  158|       |
  159|  28.5k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
  160|  28.5k|	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   69|  57.0k|#define SC_ERROR_FILE_END_REACHED		-1219
  ------------------
              	if (r == SC_ERROR_FILE_END_REACHED || r == SC_ERROR_INCORRECT_PARAMETERS)
  ------------------
  |  |   55|  27.2k|#define SC_ERROR_INCORRECT_PARAMETERS		-1205
  ------------------
  |  Branch (160:6): [True: 1.25k, False: 27.2k]
  |  Branch (160:40): [True: 481, False: 26.7k]
  ------------------
  161|  28.5k|		LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  1.73k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  1.73k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  1.73k|	int _ret = r; \
  |  |  |  |  155|  1.73k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 549, False: 1.18k]
  |  |  |  |  ------------------
  |  |  |  |  156|    549|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 549]
  |  |  |  |  ------------------
  |  |  |  |  157|    549|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  1.18k|	} else { \
  |  |  |  |  159|  1.18k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  1.18k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  1.18k|	} \
  |  |  |  |  162|  1.73k|	return _ret; \
  |  |  |  |  163|  1.73k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  162|  26.7k|	LOG_TEST_RET(ctx, r, "Check SW error");
  ------------------
  |  |  174|  26.7k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  26.7k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  26.7k|	int _ret = (r); \
  |  |  |  |  168|  26.7k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 2.61k, False: 24.1k]
  |  |  |  |  ------------------
  |  |  |  |  169|  2.61k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  2.61k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  2.61k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  2.61k|		return _ret; \
  |  |  |  |  172|  2.61k|	} \
  |  |  |  |  173|  26.7k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 24.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  163|       |
  164|  24.1k|	LOG_FUNC_RETURN(ctx, (int)apdu.resplen);
  ------------------
  |  |  164|  24.1k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  24.1k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  24.1k|	int _ret = r; \
  |  |  |  |  155|  24.1k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1.44k, False: 22.7k]
  |  |  |  |  ------------------
  |  |  |  |  156|  1.44k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1.44k]
  |  |  |  |  ------------------
  |  |  |  |  157|  1.44k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  22.7k|	} else { \
  |  |  |  |  159|  22.7k|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|  22.7k|			"returning with: %d\n", _ret); \
  |  |  |  |  161|  22.7k|	} \
  |  |  |  |  162|  24.1k|	return _ret; \
  |  |  |  |  163|  24.1k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  165|  24.1k|}

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

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

msc_list_objects:
   37|  15.3k|int msc_list_objects(sc_card_t* card, u8 next, mscfs_file_t* file) {
   38|  15.3k|	sc_apdu_t apdu;
   39|  15.3k|	u8 fileData[14];
   40|  15.3k|	int r;
   41|       |
   42|  15.3k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_2, 0x58, next, 0x00);
  ------------------
  |  |  301|  15.3k|#define SC_APDU_CASE_2			0x22
  ------------------
   43|  15.3k|	apdu.le = 14;
   44|  15.3k|	apdu.resplen = 14;
   45|  15.3k|	apdu.resp = fileData;
   46|  15.3k|	r = sc_transmit_apdu(card, &apdu);
   47|  15.3k|	if (r)
  ------------------
  |  Branch (47:6): [True: 30, False: 15.3k]
  ------------------
   48|     30|		return r;
   49|       |
   50|  15.3k|	if(apdu.sw1 == 0x9C && apdu.sw2 == 0x12) {
  ------------------
  |  Branch (50:5): [True: 277, False: 15.0k]
  |  Branch (50:25): [True: 125, False: 152]
  ------------------
   51|    125|		return 0;
   52|    125|	}
   53|  15.2k|	r = sc_check_sw(card, apdu.sw1, apdu.sw2);
   54|  15.2k|	if (r)
  ------------------
  |  Branch (54:6): [True: 952, False: 14.2k]
  ------------------
   55|    952|		return r;
   56|  14.2k|	if(apdu.resplen == 0) /* No more left */
  ------------------
  |  Branch (56:5): [True: 69, False: 14.1k]
  ------------------
   57|     69|		return 0;
   58|  14.1k|	if (apdu.resplen != 14) {
  ------------------
  |  Branch (58:6): [True: 31, False: 14.1k]
  ------------------
   59|     31|		sc_log(card->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__
  |  |  ------------------
  ------------------
   60|     31|			 "expected 14 bytes, got %"SC_FORMAT_LEN_SIZE_T"u.\n",
   61|     31|			 apdu.resplen);
   62|     31|		return SC_ERROR_UNKNOWN_DATA_RECEIVED;
  ------------------
  |  |   63|     31|#define SC_ERROR_UNKNOWN_DATA_RECEIVED		-1213
  ------------------
   63|     31|	}
   64|  14.1k|	memcpy(file->objectId.id, fileData, 4);
   65|  14.1k|	file->size = bebytes2ulong(fileData + 4);
   66|  14.1k|	file->read = bebytes2ushort(fileData + 8);
   67|  14.1k|	file->write = bebytes2ushort(fileData + 10);
   68|  14.1k|	file->delete = bebytes2ushort(fileData + 12);
   69|       |
   70|  14.1k|	return 1;
   71|  14.1k|}
msc_partial_read_object:
   74|    397|{
   75|    397|	u8 buffer[9];
   76|    397|	sc_apdu_t apdu;
   77|    397|	int r;
   78|       |
   79|    397|	sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x56, 0x00, 0x00);
  ------------------
  |  |  294|    397|#define SC_APDU_CASE_4_SHORT		0x04
  ------------------
   80|       |
   81|    397|	sc_log(card->ctx,
  ------------------
  |  |   71|    397|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
   82|    397|		"READ: Offset: %x\tLength: %"SC_FORMAT_LEN_SIZE_T"u\n", offset,
   83|    397|		 dataLength);
   84|    397|	memcpy(buffer, objectId.id, 4);
   85|    397|	ulong2bebytes(buffer + 4, offset);
   86|    397|	buffer[8] = (u8)dataLength;
   87|    397|	apdu.data = buffer;
   88|    397|	apdu.datalen = 9;
   89|    397|	apdu.lc = 9;
   90|    397|	apdu.le = dataLength;
   91|    397|	apdu.resplen = dataLength;
   92|    397|	apdu.resp = data;
   93|    397|	r = sc_transmit_apdu(card, &apdu);
   94|    397|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|    397|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    397|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    397|	int _ret = (r); \
  |  |  |  |  168|    397|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 9, False: 388]
  |  |  |  |  ------------------
  |  |  |  |  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|    397|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 388]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   95|    388|	if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && dataLength <= apdu.resplen)
  ------------------
  |  Branch (95:6): [True: 306, False: 82]
  |  Branch (95:26): [True: 301, False: 5]
  |  Branch (95:46): [True: 293, False: 8]
  ------------------
   96|    293|		return (int)dataLength;
   97|     95|	if (apdu.sw1 == 0x9C) {
  ------------------
  |  Branch (97:6): [True: 8, False: 87]
  ------------------
   98|      8|		if (apdu.sw2 == 0x07) {
  ------------------
  |  Branch (98:7): [True: 1, False: 7]
  ------------------
   99|      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]
  |  |  ------------------
  ------------------
  100|      7|		} else if (apdu.sw2 == 0x06) {
  ------------------
  |  Branch (100:14): [True: 1, False: 6]
  ------------------
  101|      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]
  |  |  ------------------
  ------------------
  102|      6|		} else if (apdu.sw2 == 0x0F) {
  ------------------
  |  Branch (102:14): [True: 1, False: 5]
  ------------------
  103|       |			/* GUESSED */
  104|      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]
  |  |  ------------------
  ------------------
  105|      1|		}
  106|      8|	}
  107|     92|	sc_log(card->ctx,
  ------------------
  |  |   71|     92|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  108|     92|		"got strange SWs: 0x%02X 0x%02X\n", apdu.sw1, apdu.sw2);
  109|     92|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_UNKNOWN_DATA_RECEIVED);
  ------------------
  |  |  153|     92|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|     92|	int _ret = r; \
  |  |  155|     92|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 92, False: 0]
  |  |  ------------------
  |  |  156|     92|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|     92|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 92, False: 0]
  |  |  ------------------
  |  |  157|     92|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|     92|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|     92|	return _ret; \
  |  |  163|     92|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  110|     92|}
msc_read_object:
  113|    397|{
  114|    397|	int r = 0;
  115|    397|	unsigned int i;
  116|    397|	size_t max_read_unit = MSC_MAX_READ;
  ------------------
  |  |   35|    397|#define MSC_MAX_READ (card->max_recv_size > 0 ? card->max_recv_size : 255)
  |  |  ------------------
  |  |  |  Branch (35:23): [True: 397, False: 0]
  |  |  ------------------
  ------------------
  117|       |
  118|    690|	for (i = 0; i < dataLength; i += r) {
  ------------------
  |  Branch (118:14): [True: 397, False: 293]
  ------------------
  119|    397|		r = msc_partial_read_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_read_unit));
  ------------------
  |  |   70|    397|#define MIN(x, y) (((x) < (y)) ? (x) : (y))
  |  |  ------------------
  |  |  |  Branch (70:20): [True: 156, False: 241]
  |  |  ------------------
  ------------------
  120|    397|		LOG_TEST_RET(card->ctx, r, "Error in partial object read");
  ------------------
  |  |  174|    397|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    397|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    397|	int _ret = (r); \
  |  |  |  |  168|    397|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 104, False: 293]
  |  |  |  |  ------------------
  |  |  |  |  169|    104|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    104|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    104|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    104|		return _ret; \
  |  |  |  |  172|    104|	} \
  |  |  |  |  173|    397|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 293]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  121|    293|		if (r == 0)
  ------------------
  |  Branch (121:7): [True: 0, False: 293]
  ------------------
  122|      0|			break;
  123|    293|	}
  124|    293|	return (int)dataLength;
  125|    397|}
msc_select_applet:
  262|  6.00k|{
  263|  6.00k|	sc_apdu_t apdu;
  264|  6.00k|	int r;
  265|       |
  266|  6.00k|	sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xA4, 4, 0);
  ------------------
  |  |  293|  6.00k|#define SC_APDU_CASE_3_SHORT		0x03
  ------------------
  267|  6.00k|	apdu.lc = appletIdLength;
  268|  6.00k|	apdu.data = appletId;
  269|  6.00k|	apdu.datalen = appletIdLength;
  270|  6.00k|	apdu.resplen = 0;
  271|  6.00k|	apdu.le = 0;
  272|       |
  273|  6.00k|	r = sc_transmit_apdu(card, &apdu);
  274|  6.00k|	LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
  ------------------
  |  |  174|  6.00k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  6.00k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  6.00k|	int _ret = (r); \
  |  |  |  |  168|  6.00k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 18, False: 5.98k]
  |  |  |  |  ------------------
  |  |  |  |  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|  6.00k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 5.98k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  275|  5.98k|	if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
  ------------------
  |  Branch (275:5): [True: 526, False: 5.46k]
  |  Branch (275:25): [True: 489, False: 37]
  ------------------
  276|    489|		return 1;
  277|       |
  278|  5.50k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,  SC_ERROR_CARD_CMD_FAILED);
  ------------------
  |  |  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|  5.50k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 5.50k, False: 0]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  279|  5.50k|}

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

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

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

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

sc_pkcs15emu_cardos_init_ex:
  172|  7.37k|{
  173|  7.37k|	if (cardos_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (173:6): [True: 6.97k, False: 401]
  ------------------
  174|  6.97k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.97k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  175|       |
  176|    401|	return sc_pkcs15emu_cardos_init(p15card, aid);
  177|  7.37k|}
pkcs15-cardos.c:cardos_pkcs15emu_detect_card:
  138|  7.37k|{
  139|  7.37k|	if (p15card->card->type <  SC_CARD_TYPE_CARDOS_BASE)
  ------------------
  |  Branch (139:6): [True: 241, False: 7.13k]
  ------------------
  140|    241|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|    241|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  141|       |
  142|  7.13k|	if (p15card->card->type >= SC_CARD_TYPE_CARDOS_BASE + 1000)
  ------------------
  |  Branch (142:6): [True: 6.73k, False: 401]
  ------------------
  143|  6.73k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.73k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  144|       |
  145|    401|	return SC_SUCCESS;
  ------------------
  |  |   28|    401|#define SC_SUCCESS				0
  ------------------
  146|  7.13k|}
pkcs15-cardos.c:sc_pkcs15emu_cardos_init:
  151|    401|{
  152|    401|	sc_card_t *card = p15card->card;
  153|    401|	int r;
  154|       |
  155|    401|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    401|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    401|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    401|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    401|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 401]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  156|       |
  157|    401|	r = sc_pkcs15_bind_internal(p15card, aid);
  158|    401|	LOG_TEST_RET(card->ctx, r, "sc_pkcs15_bind_internal 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: 391, False: 10]
  |  |  |  |  ------------------
  |  |  |  |  169|    391|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    391|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    391|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    391|		return _ret; \
  |  |  |  |  172|    391|	} \
  |  |  |  |  173|    401|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 10]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  159|       |
  160|       |	/* If card has created algorithms, return  */
  161|     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__
  |  |  ------------------
  ------------------
  162|     10|	if (!card->algorithms && card->algorithm_count == 0) {
  ------------------
  |  Branch (162:6): [True: 9, False: 1]
  |  Branch (162:27): [True: 9, False: 0]
  ------------------
  163|      9|		r = cardos_fix_token_info(p15card);
  164|      9|	}
  165|       |
  166|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  167|     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
  ------------------
  |  |  111|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   93|      0|						| SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  113|      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;
  ------------------
  |  |  120|      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) */
  |  |  ------------------
  |  |  |  |  118|      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) */
  |  |  ------------------
  |  |  |  |  119|      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
  ------------------
  |  |  111|      0|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  100|      0|					| SC_ALGORITHM_RSA_PAD_NONE;
  ------------------
  |  |  113|      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;
  ------------------
  |  |  143|      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;
  ------------------
  |  |  183|      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;
  ------------------
  |  |  105|      1|#define SC_ALGORITHM_SPECIFIC_FLAGS	0x001FFFFF
  ------------------
              				passed->new_flags = (passed->used_flags & ~SC_ALGORITHM_SPECIFIC_FLAGS) | SC_ALGORITHM_RSA_PAD_PKCS1;
  ------------------
  |  |  120|      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) */
  |  |  ------------------
  |  |  |  |  118|      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) */
  |  |  ------------------
  |  |  |  |  119|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  122|      1|			} else
  123|      8|				passed->new_flags = passed->used_flags; /* from default cardos_init */
  124|      9|		}
  125|      9|	}
  126|       |
  127|      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__
  |  |  ------------------
  ------------------
  128|       |
  129|      9|	passed->pass = 2; /* tell card driver to use the new flags */
  130|      9|	r = sc_card_ctl(p15card->card, SC_CARDCTL_CARDOS_PASS_ALGO_FLAGS, passed);
  131|       |
  132|      9|	free(passed);
  133|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  134|      9|}

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

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

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

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

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

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

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

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

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

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

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

sc_pkcs15emu_iasecc_init_ex:
  257|  9.52k|{
  258|  9.52k|	if (iasecc_pkcs15emu_detect_card(p15card))
  ------------------
  |  Branch (258:6): [True: 9.01k, False: 512]
  ------------------
  259|  9.01k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.01k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  260|       |
  261|    512|	return sc_pkcs15emu_iasecc_init(p15card, aid);
  262|  9.52k|}
pkcs15-iasecc.c:iasecc_pkcs15emu_detect_card:
  228|  9.52k|{
  229|  9.52k|	if (p15card->card->type < SC_CARD_TYPE_IASECC_BASE)
  ------------------
  |  Branch (229:6): [True: 6.83k, False: 2.68k]
  ------------------
  230|  6.83k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  6.83k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  231|       |
  232|  2.68k|	if (p15card->card->type > SC_CARD_TYPE_IASECC_BASE + 10)
  ------------------
  |  Branch (232:6): [True: 2.17k, False: 512]
  ------------------
  233|  2.17k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  2.17k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  234|       |
  235|    512|	return SC_SUCCESS;
  ------------------
  |  |   28|    512|#define SC_SUCCESS				0
  ------------------
  236|  2.68k|}
pkcs15-iasecc.c:sc_pkcs15emu_iasecc_init:
  241|    512|{
  242|    512|	struct sc_context *ctx = p15card->card->ctx;
  243|    512|	int rv;
  244|       |
  245|    512|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|    512|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    512|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    512|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    512|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 512]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  246|       |
  247|    512|	rv = sc_pkcs15_bind_internal(p15card, aid);
  248|       |
  249|    512|	p15card->ops.parse_df = _iasecc_parse_df;
  250|       |
  251|    512|	LOG_FUNC_RETURN(ctx, rv);
  ------------------
  |  |  164|    512|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    512|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    512|	int _ret = r; \
  |  |  |  |  155|    512|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 512, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    512|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    507|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 507, False: 5]
  |  |  |  |  ------------------
  |  |  |  |  157|    512|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    512|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    512|	return _ret; \
  |  |  |  |  163|    512|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  252|    512|}

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

sc_pkcs15emu_itacns_init_ex:
  881|  11.6k|{
  882|  11.6k|	sc_card_t *card = p15card->card;
  883|  11.6k|	SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|  11.6k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  11.6k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  11.6k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 11.6k]
  |  |  ------------------
  ------------------
  884|       |
  885|       |	/* Check card */
  886|  11.6k|	if (! (
  887|  11.6k|			(card->type > SC_CARD_TYPE_ITACNS_BASE &&
  ------------------
  |  Branch (887:5): [True: 3.98k, False: 7.68k]
  ------------------
  888|  3.98k|			card->type < SC_CARD_TYPE_ITACNS_BASE + 1000)
  ------------------
  |  Branch (888:4): [True: 234, False: 3.75k]
  ------------------
  889|  11.4k|		|| card->type == SC_CARD_TYPE_CARDOS_CIE_V1)
  ------------------
  |  Branch (889:6): [True: 0, False: 11.4k]
  ------------------
  890|  11.6k|		)
  891|  11.4k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  11.4k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  892|       |
  893|       |	/* Init card */
  894|    234|	return itacns_init(p15card);
  895|  11.6k|}
pkcs15-itacns.c:itacns_init:
  761|    234|{
  762|    234|	int r;
  763|    234|	sc_path_t path;
  764|    234|	int certificate_count = 0;
  765|    234|	int found_certs;
  766|    234|	int card_is_cie_v1, cns0_secenv;
  767|       |
  768|    234|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    234|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    234|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    234|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 234]
  |  |  ------------------
  ------------------
  769|       |
  770|    234|	set_string(&p15card->tokeninfo->label, p15card->card->name);
  771|    234|	if(p15card->card->drv_data) {
  ------------------
  |  Branch (771:5): [True: 234, False: 0]
  ------------------
  772|    234|		unsigned int mask_code, ic_code;
  773|    234|		char buffer[256];
  774|    234|		itacns_drv_data_t *data =
  775|    234|			(itacns_drv_data_t*) p15card->card->drv_data;
  776|    234|		mask_code = data->mask_manufacturer_code;
  777|    234|		if (mask_code >= sizeof(itacns_mask_manufacturers)
  ------------------
  |  Branch (777:7): [True: 188, False: 46]
  ------------------
  778|    234|			/sizeof(itacns_mask_manufacturers[0]))
  779|    188|			mask_code = 0;
  780|    234|		ic_code = data->ic_manufacturer_code;
  781|    234|		if (ic_code >= sizeof(iso7816_ic_manufacturers)
  ------------------
  |  Branch (781:7): [True: 207, False: 27]
  ------------------
  782|    234|			/sizeof(iso7816_ic_manufacturers[0]))
  783|    207|			ic_code = 0;
  784|    234|		snprintf(buffer, sizeof(buffer), "IC: %s; mask: %s",
  785|    234|			iso7816_ic_manufacturers[ic_code],
  786|    234|			itacns_mask_manufacturers[mask_code]);
  787|    234|		set_string(&p15card->tokeninfo->manufacturer_id, buffer);
  788|    234|	}
  789|       |
  790|       |	/* Read and set serial */
  791|    234|	{
  792|    234|		u8 serial[17];
  793|    234|		int bytes;
  794|    234|		sc_format_path(path_serial, &path);
  795|    234|		bytes = loadFile(p15card, &path, serial, 16);
  796|    234|		if (bytes < 0) return bytes;
  ------------------
  |  Branch (796:7): [True: 78, False: 156]
  ------------------
  797|    156|		if (bytes > 16) return -1;
  ------------------
  |  Branch (797:7): [True: 0, False: 156]
  ------------------
  798|    156|		serial[bytes] = '\0';
  799|    156|		set_string(&p15card->tokeninfo->serial_number, (char*)serial);
  800|    156|	}
  801|       |
  802|       |	/* Is the card a CIE v1? */
  803|      0|	card_is_cie_v1 =
  804|    156|		   (p15card->card->type == SC_CARD_TYPE_ITACNS_CIE_V1)
  ------------------
  |  Branch (804:6): [True: 1, False: 155]
  ------------------
  805|    155|		|| (p15card->card->type == SC_CARD_TYPE_CARDOS_CIE_V1);
  ------------------
  |  Branch (805:6): [True: 0, False: 155]
  ------------------
  806|    156|	cns0_secenv = (card_is_cie_v1 ? 0x31 : 0x01);
  ------------------
  |  Branch (806:17): [True: 1, False: 155]
  ------------------
  807|       |
  808|       |	/* If it's a Siemens CIE v1 card, set algo flags accordingly. */
  809|    156|	if (card_is_cie_v1) {
  ------------------
  |  Branch (809:6): [True: 1, False: 155]
  ------------------
  810|      1|		int i;
  811|      2|		for (i = 0; i < p15card->card->algorithm_count; i++) {
  ------------------
  |  Branch (811:15): [True: 1, False: 1]
  ------------------
  812|      1|			sc_algorithm_info_t *info =
  813|      1|				&p15card->card->algorithms[i];
  814|       |
  815|      1|			if (info->algorithm != SC_ALGORITHM_RSA)
  ------------------
  |  |   78|      1|#define SC_ALGORITHM_RSA		0
  ------------------
  |  Branch (815:8): [True: 0, False: 1]
  ------------------
  816|      0|				continue;
  817|      1|			info->flags &= ~(SC_ALGORITHM_RSA_RAW
  ------------------
  |  |  111|      1|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
  818|      1|				| SC_ALGORITHM_RSA_HASH_NONE);
  ------------------
  |  |  142|      1|#define SC_ALGORITHM_RSA_HASH_NONE	0x00000100 /* only applies to PKCS1 padding */
  ------------------
  819|      1|			info->flags |= (SC_ALGORITHM_RSA_PAD_PKCS1
  ------------------
  |  |  120|      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) */
  |  |  ------------------
  |  |  |  |  118|      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) */
  |  |  ------------------
  |  |  |  |  119|      1|#define SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02	0x00000080 /* PKCS#1 v1.5 padding type 2 */
  |  |  ------------------
  ------------------
  820|      1|				| SC_ALGORITHM_RSA_HASHES);
  ------------------
  |  |  151|      1|#define SC_ALGORITHM_RSA_HASHES		0x0001FF00
  ------------------
  821|      1|		}
  822|      1|	}
  823|       |
  824|       |	/* Data files */
  825|    156|	r = itacns_add_data_files(p15card);
  826|    156|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    156|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    156|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    156|	int _ret = (r); \
  |  |  |  |  178|    156|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 0, False: 156]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|      0|		goto err; \
  |  |  |  |  182|      0|	} \
  |  |  |  |  183|    156|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 156]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  827|    156|		"Could not add data files");
  828|       |
  829|       |	/*** Certificate and keys. ***/
  830|       |	/* Standard CNS */
  831|    156|	r = itacns_check_and_add_keyset(p15card, "CNS0", cns0_secenv,
  832|    156|		0, "3F0011001101", "3F003F01", NULL,
  833|    156|		0x10, &found_certs);
  834|    156|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    156|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    156|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    156|	int _ret = (r); \
  |  |  |  |  178|    156|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 47, False: 109]
  |  |  |  |  ------------------
  |  |  |  |  179|     47|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     47|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  180|     47|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     47|		goto err; \
  |  |  |  |  182|     47|	} \
  |  |  |  |  183|    156|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 109]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  835|    109|		"Could not add CNS0");
  836|    109|	certificate_count += found_certs;
  837|       |
  838|       |	/* Infocamere 1204 */
  839|    109|	r = itacns_check_and_add_keyset(p15card, "CNS01", 0x21,
  840|    109|		5, "3F002FFF8228", NULL, "3F002FFF0000",
  841|    109|		0x10, &found_certs);
  842|    109|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|    109|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|    109|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|    109|	int _ret = (r); \
  |  |  |  |  178|    109|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 45, False: 64]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     45|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     45|		goto err; \
  |  |  |  |  182|     45|	} \
  |  |  |  |  183|    109|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 64]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  843|     64|		"Could not add CNS01");
  844|     64|	certificate_count += found_certs;
  845|       |
  846|       |	/* Digital signature */
  847|     64|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x10,
  848|     64|		0, "3F0014009010", "3F00140081108010", "3F0014008110",
  849|     64|		0x1a, &found_certs);
  850|     64|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  184|     64|#define LOG_TEST_GOTO_ERR(ctx, r, text) SC_TEST_GOTO_ERR((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  176|     64|#define SC_TEST_GOTO_ERR(ctx, level, r, text) do { \
  |  |  |  |  177|     64|	int _ret = (r); \
  |  |  |  |  178|     64|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:6): [True: 49, False: 15]
  |  |  |  |  ------------------
  |  |  |  |  179|     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
  |  |  |  |  ------------------
  |  |  |  |  180|     49|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  181|     49|		goto err; \
  |  |  |  |  182|     49|	} \
  |  |  |  |  183|     64|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 15]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  851|     15|		"Could not add CNS1");
  852|     15|	certificate_count += found_certs;
  853|       |
  854|       |	/* Idemia card */
  855|     15|	r = itacns_check_and_add_keyset(p15card, "CNS1", 0x02,
  856|     15|		0, "3F00140090012002", "3F0011001102", "3F0014009002",
  857|     15|		0x10, &found_certs);
  858|     15|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  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: 9, False: 6]
  |  |  |  |  ------------------
  |  |  |  |  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|     15|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 6]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  859|      6|		"Could not add CNS1");
  860|      6|	certificate_count += found_certs;
  861|       |
  862|       |	/* Did we find anything? */
  863|      6|	if (certificate_count == 0)
  ------------------
  |  Branch (863:6): [True: 6, False: 0]
  ------------------
  864|      6|		sc_debug(p15card->card->ctx, SC_LOG_DEBUG_NORMAL,
  ------------------
  |  |   70|      6|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  865|      6|			"Warning: no certificates found!");
  866|       |
  867|       |	/* Back to Master File */
  868|      6|	sc_format_path("3F00", &path);
  869|      6|	r = sc_select_file(p15card->card, &path, NULL);
  870|      6|	LOG_TEST_GOTO_ERR(p15card->card->ctx, r,
  ------------------
  |  |  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: 5, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  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|      6|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (183:9): [Folded, False: 1]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  871|      1|		"Could not select master file again");
  872|       |
  873|      1|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  164|      1|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      1|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      1|	int _ret = r; \
  |  |  |  |  155|      1|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 1, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      1|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 1]
  |  |  |  |  ------------------
  |  |  |  |  157|      1|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      1|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      1|	return _ret; \
  |  |  |  |  163|      1|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  874|       |
  875|    146|err:
  876|    146|	sc_pkcs15_card_clear(p15card);
  877|    146|	LOG_FUNC_RETURN(p15card->card->ctx, r);
  ------------------
  |  |  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|    146|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 146, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|    146|}
pkcs15-itacns.c:loadFile:
  169|    331|{
  170|    331|	int sc_res;
  171|    331|	SC_FUNC_CALLED(p15card->card->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]
  |  |  ------------------
  ------------------
  172|       |
  173|    331|	sc_res = sc_select_file(p15card->card, path, NULL);
  174|    331|	if(sc_res != SC_SUCCESS)
  ------------------
  |  |   28|    331|#define SC_SUCCESS				0
  ------------------
  |  Branch (174:5): [True: 76, False: 255]
  ------------------
  175|     76|		return sc_res;
  176|       |
  177|    255|	sc_res = sc_read_binary(p15card->card, 0, buf, buflen, 0);
  178|    255|	return sc_res;
  179|    331|}
pkcs15-itacns.c:itacns_add_data_files:
  482|    156|{
  483|    156|	const size_t array_size =
  484|    156|		sizeof(itacns_data_files)/sizeof(itacns_data_files[0]);
  485|    156|	unsigned int i;
  486|    156|	int rv;
  487|    156|	sc_pkcs15_data_t *p15_personaldata = NULL;
  488|    156|	sc_pkcs15_data_info_t dinfo;
  489|    156|	struct sc_pkcs15_object *objs[32];
  490|    156|	struct sc_pkcs15_data_info *cinfo;
  491|    156|	int private_obj;
  492|       |
  493|  2.34k|	for(i=0; i < array_size; i++) {
  ------------------
  |  Branch (493:11): [True: 2.18k, False: 156]
  ------------------
  494|  2.18k|		sc_path_t path;
  495|  2.18k|		sc_pkcs15_data_info_t data;
  496|  2.18k|		sc_pkcs15_object_t    obj;
  497|       |
  498|  2.18k|		if (itacns_data_files[i].cie_only &&
  ------------------
  |  Branch (498:7): [True: 624, False: 1.56k]
  ------------------
  499|    624|			p15card->card->type != SC_CARD_TYPE_ITACNS_CIE_V2)
  ------------------
  |  Branch (499:4): [True: 368, False: 256]
  ------------------
  500|    368|			continue;
  501|       |
  502|  1.81k|		sc_format_path(itacns_data_files[i].path, &path);
  503|       |
  504|  1.81k|		memset(&data, 0, sizeof(data));
  505|  1.81k|		memset(&obj, 0, sizeof(obj));
  506|  1.81k|		strlcpy(data.app_label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.81k|#define strlcpy _strlcpy
  ------------------
  507|  1.81k|			sizeof(data.app_label));
  508|  1.81k|		strlcpy(obj.label, itacns_data_files[i].label,
  ------------------
  |  |   43|  1.81k|#define strlcpy _strlcpy
  ------------------
  509|  1.81k|			sizeof(obj.label));
  510|  1.81k|		data.path = path;
  511|  1.81k|		rv = sc_pkcs15emu_add_data_object(p15card, &obj, &data);
  512|  1.81k|		LOG_TEST_RET(p15card->card->ctx, rv,
  ------------------
  |  |  174|  1.81k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.81k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.81k|	int _ret = (r); \
  |  |  |  |  168|  1.81k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 1.81k]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#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.81k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 1.81k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  513|  1.81k|			"Could not add data file");
  514|  1.81k|	}
  515|       |
  516|       |	/*
  517|       |	 * If we got this far, we can read the Personal Data file and glean
  518|       |	 * the user's full name. Thus we can use it to put together a
  519|       |	 * user-friendlier card name.
  520|       |	 */
  521|    156|	memset(&dinfo, 0, sizeof(dinfo));
  522|    156|	strlcpy(dinfo.app_label, "EF_DatiPersonali", sizeof(dinfo.app_label));
  ------------------
  |  |   43|    156|#define strlcpy _strlcpy
  ------------------
  523|       |
  524|       |	/* Find EF_DatiPersonali */
  525|       |
  526|    156|	rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_DATA_OBJECT,
  ------------------
  |  |  442|    156|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  527|    156|		objs, 32);
  528|    156|	if(rv < 0) {
  ------------------
  |  Branch (528:5): [True: 0, False: 156]
  ------------------
  529|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  530|      0|			"Data enumeration failed");
  531|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  532|      0|	}
  533|       |
  534|    532|	for(i=0; i<32; i++) {
  ------------------
  |  Branch (534:11): [True: 532, False: 0]
  ------------------
  535|    532|		cinfo = (struct sc_pkcs15_data_info *) objs[i]->data;
  536|    532|		if(!strcmp("EF_DatiPersonali", objs[i]->label))
  ------------------
  |  Branch (536:6): [True: 156, False: 376]
  ------------------
  537|    156|			break;
  538|    532|	}
  539|       |
  540|    156|	if(i>=32) {
  ------------------
  |  Branch (540:5): [True: 0, False: 156]
  ------------------
  541|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  542|      0|			"Could not find EF_DatiPersonali: "
  543|      0|			"keeping generic card name");
  544|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  545|      0|	}
  546|       |
  547|    156|	private_obj = objs[i]->flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    156|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  548|    156|	rv = sc_pkcs15_read_data_object(p15card, cinfo, private_obj, &p15_personaldata);
  549|    156|	if (rv) {
  ------------------
  |  Branch (549:6): [True: 28, False: 128]
  ------------------
  550|     28|		sc_log(p15card->card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  551|     28|			"Could not read EF_DatiPersonali: "
  552|     28|			"keeping generic card name");
  553|     28|		return SC_SUCCESS;
  ------------------
  |  |   28|     28|#define SC_SUCCESS				0
  ------------------
  554|     28|	}
  555|       |
  556|    128|	if (p15_personaldata->data) {
  ------------------
  |  Branch (556:6): [True: 126, False: 2]
  ------------------
  557|    126|		char fullname[160];
  558|    126|		if (get_name_from_EF_DatiPersonali(p15_personaldata->data,
  ------------------
  |  Branch (558:7): [True: 125, False: 1]
  ------------------
  559|    126|			p15_personaldata->data_len, fullname, sizeof(fullname))) {
  560|    125|			sc_log(p15card->card->ctx,
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  561|    125|				"Could not parse EF_DatiPersonali: "
  562|    125|				"keeping generic card name");
  563|    125|			sc_pkcs15_free_data_object(p15_personaldata);
  564|    125|			free(cinfo->data.value);
  565|    125|			cinfo->data.value = NULL;
  566|    125|			return SC_SUCCESS;
  ------------------
  |  |   28|    125|#define SC_SUCCESS				0
  ------------------
  567|    125|		}
  568|      1|		set_string(&p15card->tokeninfo->label, fullname);
  569|      1|	}
  570|      3|	free(cinfo->data.value);
  571|      3|	cinfo->data.value = NULL;
  572|      3|	sc_pkcs15_free_data_object(p15_personaldata);
  573|      3|	return SC_SUCCESS;
  ------------------
  |  |   28|      3|#define SC_SUCCESS				0
  ------------------
  574|    128|}
pkcs15-itacns.c:get_name_from_EF_DatiPersonali:
  387|    126|{
  388|    126|	const unsigned int EF_personaldata_maxlen = 400;
  389|    126|	const unsigned int tlv_length_size = 6;
  390|    126|	char *file = NULL;
  391|    126|	int file_size;
  392|       |
  393|       |	/*
  394|       |	 * Bytes 0-5 contain the ASCII encoding of the following TLV
  395|       |	 * structure's total size, in base 16.
  396|       |	 */
  397|    126|	if (EFdata_len < tlv_length_size) {
  ------------------
  |  Branch (397:6): [True: 6, False: 120]
  ------------------
  398|       |		/* We need at least 6 bytes for file length here */
  399|      6|		return -1;
  400|      6|	}
  401|    120|	file_size = hextoint((char*)EFdata, tlv_length_size);
  402|    120|	if (EFdata_len < (file_size + tlv_length_size)) {
  ------------------
  |  Branch (402:6): [True: 11, False: 109]
  ------------------
  403|       |		/* Inconsistent external file length and internal file length
  404|       |		 * suggests we are trying to process junk data.
  405|       |		 * If the internal data length is shorter, the data can be padded,
  406|       |		 * but we should be fine as we will not go behind the buffer limits */
  407|     11|		return -1;
  408|     11|	}
  409|    109|	file = (char*)&EFdata[tlv_length_size];
  410|       |
  411|    109|	enum {
  412|    109|		f_issuer_code = 0,
  413|    109|		f_issuing_date,
  414|    109|		f_expiry_date,
  415|    109|		f_last_name,
  416|    109|		f_first_name,
  417|    109|		f_birth_date,
  418|    109|		f_sex,
  419|    109|		f_height,
  420|    109|		f_codice_fiscale,
  421|    109|		f_citizenship_code,
  422|    109|		f_birth_township_code,
  423|    109|		f_birth_country,
  424|    109|		f_birth_certificate,
  425|    109|		f_residence_township_code,
  426|    109|		f_residence_address,
  427|    109|		f_expat_notes
  428|    109|	};
  429|       |
  430|       |	/* Read the fields up to f_first_name */
  431|    109|	struct {
  432|    109|		int len;
  433|    109|		char value[256];
  434|    109|	} fields[f_first_name+1];
  435|    109|	int i=0; /* offset inside the file */
  436|    109|	int f; /* field number */
  437|       |
  438|    109|	if (file_size < 0)
  ------------------
  |  Branch (438:6): [True: 101, False: 8]
  ------------------
  439|    101|		return -1;
  440|       |
  441|       |	/*
  442|       |	 * This shouldn't happen, but let us be protected against wrong
  443|       |	 * or malicious cards
  444|       |	 */
  445|      8|	if(file_size > (int)EF_personaldata_maxlen - (int)tlv_length_size)
  ------------------
  |  Branch (445:5): [True: 1, False: 7]
  ------------------
  446|      1|		file_size = EF_personaldata_maxlen - tlv_length_size;
  447|       |
  448|       |
  449|      8|	memset(fields, 0, sizeof(fields));
  450|       |
  451|     24|	for(f=0; f<f_first_name+1; f++) {
  ------------------
  |  Branch (451:11): [True: 22, False: 2]
  ------------------
  452|     22|		int field_size;
  453|       |
  454|       |		/* Don't read beyond the allocated buffer */
  455|     22|		if(i+2 > file_size)
  ------------------
  |  Branch (455:6): [True: 1, False: 21]
  ------------------
  456|      1|			return -1;
  457|     21|		field_size = hextoint((char*) &file[i], 2);
  458|     21|		i += 2;
  459|       |
  460|     21|		if (field_size < 0
  ------------------
  |  Branch (460:7): [True: 1, False: 20]
  ------------------
  461|     20|				|| i + field_size > file_size
  ------------------
  |  Branch (461:8): [True: 4, False: 16]
  ------------------
  462|     16|				|| field_size >= (int)sizeof(fields[f].value))
  ------------------
  |  Branch (462:8): [True: 0, False: 16]
  ------------------
  463|      5|			return -1;
  464|       |
  465|     16|		fields[f].len = field_size;
  466|     16|		strncpy(fields[f].value, &file[i], field_size);
  467|     16|		fields[f].value[field_size] = '\0';
  468|     16|		i += field_size;
  469|     16|	}
  470|       |
  471|      2|	if (fields[f_first_name].len + fields[f_last_name].len + 1 >= name_len)
  ------------------
  |  Branch (471:6): [True: 1, False: 1]
  ------------------
  472|      1|		return -1;
  473|       |
  474|       |	/* the lengths are already checked that they will fit in buffer */
  475|      1|	snprintf(name, name_len, "%.*s %.*s",
  476|      1|		fields[f_first_name].len, fields[f_first_name].value,
  477|      1|		fields[f_last_name].len, fields[f_last_name].value);
  478|      1|	return 0;
  479|      2|}
pkcs15-itacns.c:hextoint:
  370|    141|{
  371|    141|	char hex[16];
  372|    141|	char *end;
  373|    141|	int res;
  374|       |
  375|    141|	if(len >= sizeof(hex))
  ------------------
  |  Branch (375:5): [True: 0, False: 141]
  ------------------
  376|      0|		return -1;
  377|    141|	strncpy(hex, src, len);
  378|    141|	hex[len] = '\0';
  379|    141|	res = (int)strtol(hex, &end, 0x10);
  380|    141|	if(end != (char*)&hex[len])
  ------------------
  |  Branch (380:5): [True: 102, False: 39]
  ------------------
  381|    102|		return -1;
  382|     39|	return res;
  383|    141|}
pkcs15-itacns.c:itacns_check_and_add_keyset:
  654|    344|{
  655|    344|	int r;
  656|    344|	sc_path_t path;
  657|    344|	sc_pkcs15_id_t cert_id;
  658|    344|	int ext_info_ok;
  659|    344|	int ku = 0, xku = 0;
  660|    344|	size_t modulus_len = 0;
  661|    344|	int pubkey_usage_flags = 0, prkey_usage_flags = 0;
  662|       |
  663|    344|	cert_id.len = 1;
  664|    344|	cert_id.value[0] = sec_env;
  665|    344|	*found_certificates = 0;
  666|       |
  667|       |	/* Certificate */
  668|    344|	if (!cert_path) {
  ------------------
  |  Branch (668:6): [True: 0, False: 344]
  ------------------
  669|      0|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|      0|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  670|      0|			"We cannot use keys without a matching certificate");
  671|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  672|      0|	}
  673|       |
  674|    344|	sc_format_path(cert_path, &path);
  675|    344|	r = sc_select_file(p15card->card, &path, NULL);
  676|    344|	if (r == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|    344|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (676:6): [True: 8, False: 336]
  ------------------
  677|      8|		return 0;
  678|    336|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    336|#define SC_SUCCESS				0
  ------------------
  |  Branch (678:6): [True: 103, False: 233]
  ------------------
  679|    103|		sc_log(p15card->card->ctx,
  ------------------
  |  |   71|    103|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  680|    103|			"Could not find certificate for %s", label);
  681|    103|		return r;
  682|    103|	}
  683|       |
  684|       |	/*
  685|       |	 * Infocamere 1204 (and others?) store a more complex structure. We
  686|       |	 * are going to read the first bytes to guess its length, and invoke
  687|       |	 * itacns_add_cert so that it only reads the certificate.
  688|       |	 */
  689|    233|	if (cert_offset) {
  ------------------
  |  Branch (689:6): [True: 97, False: 136]
  ------------------
  690|     97|		u8 certlen[3];
  691|     97|		memset(certlen, 0, sizeof certlen);
  692|     97|		r = loadFile(p15card, &path, certlen, sizeof(certlen));
  693|     97|		LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  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: 3, False: 94]
  |  |  |  |  ------------------
  |  |  |  |  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|     97|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 94]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  694|     94|			"Could not read certificate file");
  695|     94|		if (r < 3)
  ------------------
  |  Branch (695:7): [True: 5, False: 89]
  ------------------
  696|      5|			return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|      5|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  697|     89|		path.index = (int)cert_offset;
  698|     89|		path.count = (certlen[1] << 8) + certlen[2];
  699|       |		/* If those bytes are 00, then we are probably dealing with an
  700|       |		 * empty file. */
  701|     89|		if (path.count == 0)
  ------------------
  |  Branch (701:7): [True: 3, False: 86]
  ------------------
  702|      3|			return 0;
  703|     89|	}
  704|       |
  705|    222|	r = itacns_add_cert(p15card, SC_PKCS15_TYPE_CERT_X509, 0,
  ------------------
  |  |  439|    222|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  706|    222|		&path, &cert_id, label, 0, &ext_info_ok, &ku, &xku, &modulus_len);
  707|    222|	if (r == SC_ERROR_INVALID_ASN1_OBJECT)
  ------------------
  |  |   82|    222|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
  |  Branch (707:6): [True: 183, False: 39]
  ------------------
  708|    183|		return 0;
  709|     39|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  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: 39, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|     39|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|     39|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|     39|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|     39|		return _ret; \
  |  |  |  |  172|     39|	} \
  |  |  |  |  173|     39|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  710|      0|		"Could not add certificate");
  711|      0|	(*found_certificates)++;
  712|       |
  713|       |	/* Set usage flags */
  714|      0|	if(ext_info_ok) {
  ------------------
  |  Branch (714:5): [True: 0, False: 0]
  ------------------
  715|      0|#ifdef ENABLE_OPENSSL
  716|      0|		if (ku & KU_DIGITAL_SIGNATURE) {
  ------------------
  |  Branch (716:7): [True: 0, False: 0]
  ------------------
  717|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  718|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_SIGN;
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  719|      0|		}
  720|      0|		if (ku & KU_NON_REPUDIATION) {
  ------------------
  |  Branch (720:7): [True: 0, False: 0]
  ------------------
  721|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_VERIFY;
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  722|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_NONREPUDIATION;
  ------------------
  |  |  314|      0|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  723|      0|		}
  724|      0|		if (ku & KU_KEY_ENCIPHERMENT || ku & KU_KEY_AGREEMENT
  ------------------
  |  Branch (724:7): [True: 0, False: 0]
  |  Branch (724:35): [True: 0, False: 0]
  ------------------
  725|      0|			|| xku & XKU_SSL_CLIENT) {
  ------------------
  |  Branch (725:7): [True: 0, False: 0]
  ------------------
  726|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|      0|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  727|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  728|      0|		}
  729|      0|		if (ku & KU_DATA_ENCIPHERMENT || xku & XKU_SMIME) {
  ------------------
  |  Branch (729:7): [True: 0, False: 0]
  |  Branch (729:36): [True: 0, False: 0]
  ------------------
  730|      0|			pubkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_ENCRYPT;
  ------------------
  |  |  305|      0|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
  731|      0|			prkey_usage_flags |= SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|      0|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
  732|      0|		}
  733|       |#else /* ENABLE_OPENSSL */
  734|       |		sc_log(p15card->card->ctx,
  735|       |			"Extended certificate info retrieved without OpenSSL. "
  736|       |			"How is this possible?");
  737|       |		return SC_ERROR_INTERNAL;
  738|       |#endif /* ENABLE_OPENSSL */
  739|      0|	} else {
  740|       |		/* Certificate info not retrieved; fall back onto defaults */
  741|      0|		pubkey_usage_flags =
  742|      0|			  SC_PKCS15_PRKEY_USAGE_VERIFY
  ------------------
  |  |  311|      0|#define SC_PKCS15_PRKEY_USAGE_VERIFY		0x40
  ------------------
  743|      0|			| SC_PKCS15_PRKEY_USAGE_WRAP;
  ------------------
  |  |  309|      0|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
  744|      0|		prkey_usage_flags =
  745|      0|			  SC_PKCS15_PRKEY_USAGE_SIGN
  ------------------
  |  |  307|      0|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  746|      0|			| SC_PKCS15_PRKEY_USAGE_UNWRAP;
  ------------------
  |  |  310|      0|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
  747|      0|	}
  748|       |
  749|      0|	r = itacns_add_keyset(p15card, label, sec_env, &cert_id,
  750|      0|		pubkey_path, prkey_path, pubkey_usage_flags, prkey_usage_flags,
  751|      0|		pin_ref, modulus_len);
  752|      0|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|      0|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|      0|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|      0|	int _ret = (r); \
  |  |  |  |  168|      0|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|      0|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|      0|		return _ret; \
  |  |  |  |  172|      0|	} \
  |  |  |  |  173|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  753|      0|		"Could not add keys for this certificate");
  754|       |
  755|      0|	return r;
  756|      0|}
pkcs15-itacns.c:itacns_add_cert:
  189|    222|{
  190|    222|	int r;
  191|       |	/* const char *label = "Certificate"; */
  192|    222|	sc_pkcs15_cert_info_t info;
  193|    222|	sc_pkcs15_object_t    obj;
  194|    222|#ifdef ENABLE_OPENSSL
  195|    222|	X509 *x509;
  196|    222|	sc_pkcs15_cert_t *cert;
  197|    222|	int private_obj;
  198|    222|#endif
  199|       |
  200|    222|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_NORMAL);
  ------------------
  |  |  148|    222|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|    222|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|    222|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 222]
  |  |  ------------------
  ------------------
  201|       |
  202|    222|	if(type != SC_PKCS15_TYPE_CERT_X509) {
  ------------------
  |  |  439|    222|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  |  Branch (202:5): [True: 0, False: 222]
  ------------------
  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|    222|	*ext_info_ok = 0;
  209|       |
  210|       |
  211|    222|	memset(&info, 0, sizeof(info));
  212|    222|	memset(&obj,  0, sizeof(obj));
  213|       |
  214|    222|	info.id                = *id;
  215|    222|	info.authority         = authority;
  216|    222|	if (path)
  ------------------
  |  Branch (216:6): [True: 222, False: 0]
  ------------------
  217|    222|		info.path = *path;
  218|       |
  219|    222|	strlcpy(obj.label, label, sizeof(obj.label));
  ------------------
  |  |   43|    222|#define strlcpy _strlcpy
  ------------------
  220|       |
  221|       |	/* If we have OpenSSL, read keyUsage */
  222|    222|#ifdef ENABLE_OPENSSL
  223|    222|	private_obj = obj_flags & SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|    222|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  224|    222|	r = sc_pkcs15_read_certificate(p15card, &info, private_obj, &cert);
  225|    222|	LOG_TEST_RET(p15card->card->ctx, r,
  ------------------
  |  |  174|    222|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    222|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    222|	int _ret = (r); \
  |  |  |  |  168|    222|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 222, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    222|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    222|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    222|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    222|		return _ret; \
  |  |  |  |  172|    222|	} \
  |  |  |  |  173|    222|} 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) {
  ------------------
  |  |   78|      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:
  240|  9.52k|{
  241|  9.52k|	if (p15card->card->type != SC_CARD_TYPE_JPKI_BASE)
  ------------------
  |  Branch (241:6): [True: 9.45k, False: 67]
  ------------------
  242|  9.45k|		return SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  9.45k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  243|     67|	return sc_pkcs15emu_jpki_init(p15card);
  244|  9.52k|}
pkcs15-jpki.c:sc_pkcs15emu_jpki_init:
   38|     67|{
   39|     67|	sc_card_t *card = p15card->card;
   40|     67|	struct jpki_private_data *drvdata = JPKI_DRVDATA(card);
  ------------------
  |  |   36|     67|#define JPKI_DRVDATA(card) ((struct jpki_private_data *) ((card)->drv_data))
  ------------------
   41|     67|	int i, rc;
   42|       |
   43|     67|	LOG_FUNC_CALLED(p15card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   44|       |
   45|     67|	set_string(&p15card->tokeninfo->label, "JPKI");
   46|     67|	set_string(&p15card->tokeninfo->manufacturer_id, "JPKI");
   47|       |	/* set dummy until we found serial number */
   48|     67|	set_string(&p15card->tokeninfo->serial_number, "00000000");
   49|       |
   50|       |	/* Select application directory */
   51|     67|	if (drvdata->selected != SELECT_JPKI_AP) {
  ------------------
  |  |   25|     67|#define SELECT_JPKI_AP 1
  ------------------
  |  Branch (51:6): [True: 67, False: 0]
  ------------------
   52|     67|		rc = jpki_select_ap(card);
   53|     67|		LOG_TEST_RET(card->ctx, rc, "select AP 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: 10, False: 57]
  |  |  |  |  ------------------
  |  |  |  |  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|     67|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 57]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   54|     57|		drvdata->selected = SELECT_JPKI_AP;
  ------------------
  |  |   25|     57|#define SELECT_JPKI_AP 1
  ------------------
   55|     57|	}
   56|       |
   57|       |	/* add certificates */
   58|    285|	for (i = 0; i < 4; i++) {
  ------------------
  |  Branch (58:14): [True: 228, False: 57]
  ------------------
   59|    228|		static const char *jpki_cert_names[4] = {
   60|    228|			"User Authentication Certificate",
   61|    228|			"Digital Signature Certificate",
   62|    228|			"User Authentication Certificate CA",
   63|    228|			"Digital Signature Certificate CA"
   64|    228|		};
   65|    228|		static char const *jpki_cert_paths[4] = {
   66|    228|			"000A",
   67|    228|			"0001",
   68|    228|			"000B",
   69|    228|			"0002"
   70|    228|		};
   71|    228|		static int jpki_cert_ids[4] = { 1, 2, 3, 4 };
   72|    228|		static int jpki_cert_flags[4] = {
   73|    228|			0,
   74|    228|			SC_PKCS15_CO_FLAG_PRIVATE,
  ------------------
  |  |   50|    228|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
   75|    228|			0,
   76|    228|			0,
   77|    228|		};
   78|    228|		static int jpki_cert_authority[4] = {0, 0, 1, 1};
   79|    228|		struct sc_pkcs15_cert_info cert_info;
   80|    228|		struct sc_pkcs15_object cert_obj;
   81|    228|		memset(&cert_info, 0, sizeof(cert_info));
   82|    228|		memset(&cert_obj, 0, sizeof(cert_obj));
   83|       |
   84|    228|		cert_info.id.value[0] = jpki_cert_ids[i];
   85|    228|		cert_info.id.len = 1;
   86|    228|		sc_format_path(jpki_cert_paths[i], &cert_info.path);
   87|    228|		cert_info.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|    228|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
   88|       |
   89|    228|		strlcpy(cert_obj.label, jpki_cert_names[i], sizeof(cert_obj.label));
  ------------------
  |  |   43|    228|#define strlcpy _strlcpy
  ------------------
   90|    228|		cert_info.authority = jpki_cert_authority[i];
   91|    228|		cert_obj.flags = jpki_cert_flags[i];
   92|    228|		rc = sc_pkcs15emu_add_x509_cert(p15card, &cert_obj, &cert_info);
   93|    228|		if (rc < 0) {
  ------------------
  |  Branch (93:7): [True: 0, False: 228]
  ------------------
   94|      0|			sc_pkcs15_card_clear(p15card);
   95|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   96|      0|		}
   97|       |
   98|    228|	}
   99|       |
  100|       |	/* add pins */
  101|    138|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (101:14): [True: 102, False: 36]
  ------------------
  102|    102|		static const char *jpki_pin_names[2] = {
  103|    102|			"User Authentication PIN",
  104|    102|			"Digital Signature PIN"
  105|    102|		};
  106|    102|		static const int jpki_pin_min[2] = { 4, 6 };
  107|    102|		static const int jpki_pin_max[2] = { 4, 16 };
  108|    102|		static const int jpki_pin_ref[2] = { 1, 2 };
  109|    102|		static const int jpki_pin_authid[2] = { 1, 2 };
  110|    102|		static const int jpki_pin_flags[2] = {
  111|    102|			SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    102|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  112|    102|			SC_PKCS15_PIN_FLAG_LOCAL,
  ------------------
  |  |   55|    102|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  113|    102|			SC_PKCS15_PIN_FLAG_INITIALIZED |
  ------------------
  |  |   58|    102|#define SC_PKCS15_PIN_FLAG_INITIALIZED			0x0010
  ------------------
  114|    102|			SC_PKCS15_PIN_FLAG_LOCAL
  ------------------
  |  |   55|    102|#define SC_PKCS15_PIN_FLAG_LOCAL			0x0002
  ------------------
  115|    102|		};
  116|    102|		static const int jpki_pin_max_tries[2] = {
  117|    102|			JPKI_AUTH_PIN_MAX_TRIES,
  ------------------
  |  |   30|    102|#define JPKI_AUTH_PIN_MAX_TRIES 3
  ------------------
  118|    102|			JPKI_SIGN_PIN_MAX_TRIES
  ------------------
  |  |   34|    102|#define JPKI_SIGN_PIN_MAX_TRIES 5
  ------------------
  119|    102|		};
  120|       |
  121|    102|		struct sc_pkcs15_auth_info pin_info;
  122|    102|		struct sc_pkcs15_object pin_obj;
  123|    102|		struct sc_pin_cmd_data pin_cmd_data;
  124|    102|		memset(&pin_info, 0, sizeof (pin_info));
  125|    102|		memset(&pin_obj, 0, sizeof (pin_obj));
  126|    102|		memset(&pin_cmd_data, 0, sizeof(pin_cmd_data));
  127|       |
  128|    102|		pin_info.auth_id.len = 1;
  129|    102|		pin_info.auth_id.value[0] = jpki_pin_authid[i];
  130|    102|		pin_info.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|    102|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  131|    102|		pin_info.attrs.pin.reference = jpki_pin_ref[i];
  132|    102|		pin_info.attrs.pin.flags = jpki_pin_flags[i];
  133|    102|		pin_info.attrs.pin.type = SC_PKCS15_PIN_TYPE_ASCII_NUMERIC;
  ------------------
  |  |   89|    102|#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC		1
  ------------------
  134|    102|		pin_info.attrs.pin.min_length = jpki_pin_min[i];
  135|    102|		pin_info.attrs.pin.stored_length = 0;
  136|    102|		pin_info.attrs.pin.max_length = jpki_pin_max[i];
  137|    102|		pin_info.attrs.pin.pad_char = '\0';
  138|    102|		pin_info.max_tries = jpki_pin_max_tries[i];
  139|    102|		pin_info.tries_left = -1;
  140|    102|		pin_info.logged_in = SC_PIN_STATE_UNKNOWN;
  ------------------
  |  |  437|    102|#define SC_PIN_STATE_UNKNOWN	0
  ------------------
  141|       |
  142|    102|		pin_cmd_data.cmd = SC_PIN_CMD_GET_INFO;
  ------------------
  |  |  425|    102|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  143|    102|		pin_cmd_data.pin_type = SC_AC_CHV;
  ------------------
  |  |  151|    102|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  144|    102|		pin_cmd_data.pin_reference = jpki_pin_ref[i];
  145|    102|		rc = sc_pin_cmd(card, &pin_cmd_data, &pin_info.tries_left);
  146|    102|		LOG_TEST_RET(card->ctx, rc, "sc_pin_cmd 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: 21, False: 81]
  |  |  |  |  ------------------
  |  |  |  |  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|    102|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 81]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  147|     81|		strlcpy(pin_obj.label, jpki_pin_names[i], sizeof(pin_obj.label));
  ------------------
  |  |   43|     81|#define strlcpy _strlcpy
  ------------------
  148|     81|		pin_obj.flags = jpki_pin_flags[i];
  149|       |
  150|     81|		rc = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
  151|     81|		if (rc < 0) {
  ------------------
  |  Branch (151:7): [True: 0, False: 81]
  ------------------
  152|      0|			sc_pkcs15_card_clear(p15card);
  153|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  154|      0|		}
  155|     81|	}
  156|       |
  157|       |	/* add private keys */
  158|    108|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (158:14): [True: 72, False: 36]
  ------------------
  159|     72|		static int prkey_pin[2] = { 1, 2 };
  160|     72|		static int prkey_usage[2] = {
  161|     72|			SC_PKCS15_PRKEY_USAGE_SIGN,
  ------------------
  |  |  307|     72|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
  162|     72|			SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  307|     72|#define SC_PKCS15_PRKEY_USAGE_SIGN		0x04
  ------------------
              			SC_PKCS15_PRKEY_USAGE_SIGN | SC_PKCS15_PRKEY_USAGE_NONREPUDIATION
  ------------------
  |  |  314|     72|#define SC_PKCS15_PRKEY_USAGE_NONREPUDIATION	0x200
  ------------------
  163|     72|		};
  164|     72|		static const char *prkey_name[2] = {
  165|     72|			"User Authentication Key",
  166|     72|			"Digital Signature Key"
  167|     72|		};
  168|     72|		static int prkey_user_consent[2] = { 0, 1 };
  169|     72|		struct sc_pkcs15_prkey_info prkey_info;
  170|     72|		struct sc_pkcs15_object prkey_obj;
  171|       |
  172|     72|		memset(&prkey_info, 0, sizeof (prkey_info));
  173|     72|		memset(&prkey_obj, 0, sizeof (prkey_obj));
  174|       |
  175|     72|		prkey_info.id.len = 1;
  176|     72|		prkey_info.id.value[0] = prkey_pin[i];
  177|     72|		prkey_info.usage = prkey_usage[i];
  178|     72|		prkey_info.native = 1;
  179|     72|		prkey_info.key_reference = i + 1;
  180|     72|		prkey_info.modulus_length = 2048;
  181|       |
  182|     72|		strlcpy(prkey_obj.label, prkey_name[i], sizeof (prkey_obj.label));
  ------------------
  |  |   43|     72|#define strlcpy _strlcpy
  ------------------
  183|     72|		prkey_obj.auth_id.len = 1;
  184|     72|		prkey_obj.auth_id.value[0] = prkey_pin[i];
  185|     72|		prkey_obj.user_consent = prkey_user_consent[i];
  186|     72|		prkey_obj.flags = SC_PKCS15_CO_FLAG_PRIVATE;
  ------------------
  |  |   50|     72|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  187|       |
  188|     72|		rc = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
  189|     72|		if (rc < 0) {
  ------------------
  |  Branch (189:7): [True: 0, False: 72]
  ------------------
  190|      0|			sc_pkcs15_card_clear(p15card);
  191|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  192|      0|		}
  193|     72|	}
  194|       |
  195|       |	/* add public keys */
  196|    108|	for (i = 0; i < 2; i++) {
  ------------------
  |  Branch (196:14): [True: 72, False: 36]
  ------------------
  197|     72|		static int pubkey_id[2] = { 1, 2 };
  198|     72|		static const char *jpki_pubkey_names[2] = {
  199|     72|			"User Authentication Public Key",
  200|     72|			"Digital Signature Public Key"
  201|     72|		};
  202|     72|		static int jpki_pubkey_flags[2] = {
  203|     72|				0,
  204|     72|				SC_PKCS15_CO_FLAG_PRIVATE};
  ------------------
  |  |   50|     72|#define SC_PKCS15_CO_FLAG_PRIVATE	0x00000001
  ------------------
  205|     72|		static int jpki_pubkey_auth_id[2] = {0, 2};
  206|     72|		struct sc_pkcs15_pubkey_info pubkey_info;
  207|     72|		struct sc_pkcs15_object pubkey_obj;
  208|     72|		static char const *jpki_pubkey_paths[2] = {
  209|     72|			"000A",
  210|     72|			"0001"
  211|     72|		};
  212|       |
  213|     72|		memset(&pubkey_info, 0, sizeof (pubkey_info));
  214|     72|		memset(&pubkey_obj, 0, sizeof (pubkey_obj));
  215|       |
  216|     72|		strlcpy(pubkey_obj.label, jpki_pubkey_names[i], sizeof (pubkey_obj.label));
  ------------------
  |  |   43|     72|#define strlcpy _strlcpy
  ------------------
  217|     72|		pubkey_info.id.len = 1;
  218|     72|		pubkey_info.id.value[0] = pubkey_id[i];
  219|     72|		pubkey_info.native = 1;
  220|     72|		pubkey_info.key_reference = i + 1;
  221|       |
  222|     72|		sc_format_path(jpki_pubkey_paths[i], &pubkey_info.path);
  223|     72|		pubkey_info.path.type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|     72|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  224|     72|		pubkey_obj.flags = jpki_pubkey_flags[i];
  225|     72|		pubkey_obj.auth_id.len = 1;
  226|     72|		pubkey_obj.auth_id.value[0] = jpki_pubkey_auth_id[i];
  227|       |
  228|     72|		rc = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
  229|     72|		if (rc < 0) {
  ------------------
  |  Branch (229:7): [True: 0, False: 72]
  ------------------
  230|      0|			sc_pkcs15_card_clear(p15card);
  231|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  232|      0|		}
  233|     72|	}
  234|     36|	LOG_FUNC_RETURN(card->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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  235|     36|}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

sc_pkcs15_is_emulation_only:
   89|  12.5k|{
   90|  12.5k|	switch (card->type) {
   91|    787|		case SC_CARD_TYPE_GEMSAFEV1_PTEID:
  ------------------
  |  Branch (91:3): [True: 787, False: 11.7k]
  ------------------
   92|    790|		case SC_CARD_TYPE_OPENPGP_V1:
  ------------------
  |  Branch (92:3): [True: 3, False: 12.5k]
  ------------------
   93|    801|		case SC_CARD_TYPE_OPENPGP_V2:
  ------------------
  |  Branch (93:3): [True: 11, False: 12.5k]
  ------------------
   94|    928|		case SC_CARD_TYPE_OPENPGP_GNUK:
  ------------------
  |  Branch (94:3): [True: 127, False: 12.4k]
  ------------------
   95|    931|		case SC_CARD_TYPE_OPENPGP_V3:
  ------------------
  |  Branch (95:3): [True: 3, False: 12.5k]
  ------------------
   96|    931|		case SC_CARD_TYPE_SC_HSM:
  ------------------
  |  Branch (96:3): [True: 0, False: 12.5k]
  ------------------
   97|    931|		case SC_CARD_TYPE_SC_HSM_SOC:
  ------------------
  |  Branch (97:3): [True: 0, False: 12.5k]
  ------------------
   98|    931|		case SC_CARD_TYPE_DNIE_BASE:
  ------------------
  |  Branch (98:3): [True: 0, False: 12.5k]
  ------------------
   99|    931|		case SC_CARD_TYPE_DNIE_BLANK:
  ------------------
  |  Branch (99:3): [True: 0, False: 12.5k]
  ------------------
  100|    931|		case SC_CARD_TYPE_DNIE_ADMIN:
  ------------------
  |  Branch (100:3): [True: 0, False: 12.5k]
  ------------------
  101|  1.44k|		case SC_CARD_TYPE_DNIE_USER:
  ------------------
  |  Branch (101:3): [True: 510, False: 12.0k]
  ------------------
  102|  1.44k|		case SC_CARD_TYPE_DNIE_TERMINATED:
  ------------------
  |  Branch (102:3): [True: 0, False: 12.5k]
  ------------------
  103|  1.44k|		case SC_CARD_TYPE_IASECC_GEMALTO:
  ------------------
  |  Branch (103:3): [True: 5, False: 12.5k]
  ------------------
  104|  1.51k|		case SC_CARD_TYPE_IASECC_CPX:
  ------------------
  |  Branch (104:3): [True: 69, False: 12.4k]
  ------------------
  105|  1.51k|		case SC_CARD_TYPE_IASECC_CPXCL:
  ------------------
  |  Branch (105:3): [True: 1, False: 12.5k]
  ------------------
  106|  1.51k|		case SC_CARD_TYPE_PIV_II_GENERIC:
  ------------------
  |  Branch (106:3): [True: 0, False: 12.5k]
  ------------------
  107|  1.60k|		case SC_CARD_TYPE_PIV_II_HIST:
  ------------------
  |  Branch (107:3): [True: 89, False: 12.4k]
  ------------------
  108|  1.87k|		case SC_CARD_TYPE_PIV_II_NEO:
  ------------------
  |  Branch (108:3): [True: 272, False: 12.2k]
  ------------------
  109|  1.98k|		case SC_CARD_TYPE_PIV_II_YUBIKEY4:
  ------------------
  |  Branch (109:3): [True: 111, False: 12.4k]
  ------------------
  110|  1.98k|		case SC_CARD_TYPE_PIV_II_SWISSBIT:
  ------------------
  |  Branch (110:3): [True: 0, False: 12.5k]
  ------------------
  111|  2.04k|		case SC_CARD_TYPE_ESTEID_2018:
  ------------------
  |  Branch (111:3): [True: 58, False: 12.4k]
  ------------------
  112|  2.18k|		case SC_CARD_TYPE_CARDOS_V5_0:
  ------------------
  |  Branch (112:3): [True: 138, False: 12.4k]
  ------------------
  113|  2.45k|		case SC_CARD_TYPE_CARDOS_V5_3:
  ------------------
  |  Branch (113:3): [True: 272, False: 12.2k]
  ------------------
  114|  2.64k|		case SC_CARD_TYPE_NQ_APPLET:
  ------------------
  |  Branch (114:3): [True: 186, False: 12.3k]
  ------------------
  115|  2.64k|		case SC_CARD_TYPE_NQ_APPLET_RFID:
  ------------------
  |  Branch (115:3): [True: 0, False: 12.5k]
  ------------------
  116|  2.79k|		case SC_CARD_TYPE_STARCOS_V3_4_ESIGN:
  ------------------
  |  Branch (116:3): [True: 153, False: 12.3k]
  ------------------
  117|  2.79k|		case SC_CARD_TYPE_STARCOS_V3_5_ESIGN:
  ------------------
  |  Branch (117:3): [True: 0, False: 12.5k]
  ------------------
  118|  2.81k|		case SC_CARD_TYPE_SKEID_V3:
  ------------------
  |  Branch (118:3): [True: 16, False: 12.5k]
  ------------------
  119|  2.82k|		case SC_CARD_TYPE_EOI:
  ------------------
  |  Branch (119:3): [True: 10, False: 12.5k]
  ------------------
  120|  2.82k|		case SC_CARD_TYPE_EOI_CONTACTLESS:
  ------------------
  |  Branch (120:3): [True: 0, False: 12.5k]
  ------------------
  121|  2.82k|		case SC_CARD_TYPE_DTRUST_V4_1_STD:
  ------------------
  |  Branch (121:3): [True: 0, False: 12.5k]
  ------------------
  122|  2.82k|		case SC_CARD_TYPE_DTRUST_V4_4_STD:
  ------------------
  |  Branch (122:3): [True: 0, False: 12.5k]
  ------------------
  123|  2.82k|		case SC_CARD_TYPE_DTRUST_V4_1_MULTI:
  ------------------
  |  Branch (123:3): [True: 0, False: 12.5k]
  ------------------
  124|  2.82k|		case SC_CARD_TYPE_DTRUST_V4_1_M100:
  ------------------
  |  Branch (124:3): [True: 0, False: 12.5k]
  ------------------
  125|  2.82k|		case SC_CARD_TYPE_DTRUST_V4_4_MULTI:
  ------------------
  |  Branch (125:3): [True: 0, False: 12.5k]
  ------------------
  126|  2.82k|		case SC_CARD_TYPE_DTRUST_V5_1_STD:
  ------------------
  |  Branch (126:3): [True: 0, False: 12.5k]
  ------------------
  127|  2.82k|		case SC_CARD_TYPE_DTRUST_V5_4_STD:
  ------------------
  |  Branch (127:3): [True: 0, False: 12.5k]
  ------------------
  128|  2.82k|		case SC_CARD_TYPE_DTRUST_V5_1_MULTI:
  ------------------
  |  Branch (128:3): [True: 0, False: 12.5k]
  ------------------
  129|  2.82k|		case SC_CARD_TYPE_DTRUST_V5_1_M100:
  ------------------
  |  Branch (129:3): [True: 0, False: 12.5k]
  ------------------
  130|  2.82k|		case SC_CARD_TYPE_DTRUST_V5_4_MULTI:
  ------------------
  |  Branch (130:3): [True: 0, False: 12.5k]
  ------------------
  131|  2.82k|		case SC_CARD_TYPE_LTEID:
  ------------------
  |  Branch (131:3): [True: 0, False: 12.5k]
  ------------------
  132|  2.82k|			return 1;
  133|  9.72k|		default:
  ------------------
  |  Branch (133:3): [True: 9.72k, False: 2.82k]
  ------------------
  134|  9.72k|			return 0;
  135|  12.5k|	}
  136|  12.5k|}
sc_pkcs15_bind_synthetic:
  140|  12.3k|{
  141|  12.3k|	sc_context_t		*ctx = p15card->card->ctx;
  142|  12.3k|	scconf_block		*conf_block, **blocks, *blk;
  143|  12.3k|	int			i, r = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  12.3k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  144|       |
  145|  12.3k|	SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  146|  12.3k|	conf_block = NULL;
  147|       |
  148|  12.3k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
  149|       |
  150|  12.3k|	if (!conf_block) {
  ------------------
  |  Branch (150:6): [True: 12.3k, False: 0]
  ------------------
  151|       |		/* no conf file found => try builtin drivers  */
  152|  12.3k|		sc_log(ctx, "no conf file (or section), trying all builtin emulators");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  153|   265k|		for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (153:15): [True: 258k, False: 7.11k]
  ------------------
  154|   258k|			sc_log(ctx, "trying %s", builtin_emulators[i].name);
  ------------------
  |  |   71|   258k|#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|   258k|			r = builtin_emulators[i].handler(p15card, aid);
  156|   258k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|   258k|#define SC_SUCCESS				0
  ------------------
  |  Branch (156:8): [True: 5.21k, False: 253k]
  ------------------
  157|       |				/* we got a hit */
  158|  5.21k|				goto out;
  159|   258k|		}
  160|  12.3k|	} else {
  161|       |		/* we have a conf file => let's use it */
  162|      0|		int builtin_enabled;
  163|      0|		const scconf_list *list;
  164|       |
  165|      0|		builtin_enabled = scconf_get_bool(conf_block, "enable_builtin_emulation", 1);
  166|      0|		list = scconf_find_list(conf_block, "builtin_emulators"); /* FIXME: rename to enabled_emulators */
  167|       |
  168|      0|		if (builtin_enabled && list) {
  ------------------
  |  Branch (168:7): [True: 0, False: 0]
  |  Branch (168:26): [True: 0, False: 0]
  ------------------
  169|       |			/* filter enabled emulation drivers from conf file */
  170|      0|			struct _sc_pkcs15_emulators filtered_emulators;
  171|      0|			struct sc_pkcs15_emulator_handler** lst;
  172|      0|			int ret;
  173|       |
  174|      0|			filtered_emulators.ccount = 0;
  175|      0|			ret = set_emulators(ctx, &filtered_emulators, list, builtin_emulators, old_emulators);
  176|      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 (176:8): [True: 0, False: 0]
  |  Branch (176:29): [True: 0, False: 0]
  ------------------
  177|      0|				lst = filtered_emulators.list_of_handlers;
  178|       |
  179|      0|				if (ret == SC_ERROR_TOO_MANY_OBJECTS)
  ------------------
  |  |   86|      0|#define SC_ERROR_TOO_MANY_OBJECTS		-1405
  ------------------
  |  Branch (179:9): [True: 0, False: 0]
  ------------------
  180|      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)
  |  |  ------------------
  |  |  |  |  180|      0|					sc_log(ctx, "trying first %d emulators from conf file", SC_MAX_PKCS15_EMULATORS);
  |  |  |  |  ------------------
  |  |  |  |  |  |   52|      0|#define SC_MAX_PKCS15_EMULATORS	48
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  181|       |
  182|      0|				for (i = 0; lst[i]; i++) {
  ------------------
  |  Branch (182:17): [True: 0, False: 0]
  ------------------
  183|      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__
  |  |  ------------------
  ------------------
  184|      0|					r = lst[i]->handler(p15card, aid);
  185|      0|					if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (185:10): [True: 0, False: 0]
  ------------------
  186|       |						/* we got a hit */
  187|      0|						goto out;
  188|      0|				}
  189|      0|			} else {
  190|      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__
  |  |  ------------------
  ------------------
  191|      0|			}
  192|      0|		}
  193|      0|		else if (builtin_enabled) {
  ------------------
  |  Branch (193:12): [True: 0, False: 0]
  ------------------
  194|      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__
  |  |  ------------------
  ------------------
  195|      0|			for (i = 0; builtin_emulators[i].name; i++) {
  ------------------
  |  Branch (195:16): [True: 0, False: 0]
  ------------------
  196|      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__
  |  |  ------------------
  ------------------
  197|      0|				r = builtin_emulators[i].handler(p15card, aid);
  198|      0|				if (r == SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (198:9): [True: 0, False: 0]
  ------------------
  199|       |					/* we got a hit */
  200|      0|					goto out;
  201|      0|			}
  202|      0|		}
  203|       |
  204|       |		/* search for 'emulate foo { ... }' entries in the conf file */
  205|      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__
  |  |  ------------------
  ------------------
  206|      0|		blocks = scconf_find_blocks(ctx->conf, conf_block, "emulate", NULL);
  207|      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__
  |  |  ------------------
  ------------------
  208|      0|		for (i = 0; blocks && (blk = blocks[i]) != NULL; i++) {
  ------------------
  |  Branch (208:15): [True: 0, False: 0]
  |  Branch (208:25): [True: 0, False: 0]
  ------------------
  209|      0|			const char *name = blk->name->data;
  210|      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__
  |  |  ------------------
  ------------------
  211|      0|			r = parse_emu_block(p15card, aid, blk);
  212|      0|			if (r == SC_SUCCESS) {
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (212:8): [True: 0, False: 0]
  ------------------
  213|      0|				free(blocks);
  214|      0|				goto out;
  215|      0|			}
  216|      0|		}
  217|      0|		if (blocks)
  ------------------
  |  Branch (217:7): [True: 0, False: 0]
  ------------------
  218|      0|			free(blocks);
  219|      0|	}
  220|       |
  221|  12.3k|out:
  222|  12.3k|	if (r == SC_SUCCESS) {
  ------------------
  |  |   28|  12.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (222:6): [True: 5.21k, False: 7.11k]
  ------------------
  223|  5.21k|		p15card->magic  = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  5.21k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  224|  5.21k|		p15card->flags |= SC_PKCS15_CARD_FLAG_EMULATED;
  ------------------
  |  |  601|  5.21k|#define SC_PKCS15_CARD_FLAG_EMULATED			0x02000000
  ------------------
  225|  7.11k|	} else {
  226|  7.11k|		if (r != SC_ERROR_WRONG_CARD)
  ------------------
  |  |   94|  7.11k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
  |  Branch (226:7): [True: 100, False: 7.01k]
  ------------------
  227|    100|			sc_log(ctx, "Failed to load card emulator: %s", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  228|  7.11k|	}
  229|       |
  230|  12.3k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  12.3k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.3k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.3k|	int _ret = r; \
  |  |  |  |  155|  12.3k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.3k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.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|  7.11k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.11k, False: 5.21k]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.3k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.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|  12.3k|	return _ret; \
  |  |  |  |  163|  12.3k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  231|  12.3k|}
sc_pkcs15emu_add_pin_obj:
  367|  6.66k|{
  368|  6.66k|	sc_pkcs15_auth_info_t pin = *in_pin;
  369|       |
  370|  6.66k|	pin.auth_type = SC_PKCS15_PIN_AUTH_TYPE_PIN;
  ------------------
  |  |   94|  6.66k|#define SC_PKCS15_PIN_AUTH_TYPE_PIN			0
  ------------------
  371|  6.66k|	if(!pin.auth_method) /* or SC_AC_NONE */
  ------------------
  |  Branch (371:5): [True: 6.11k, False: 548]
  ------------------
  372|  6.11k|		pin.auth_method = SC_AC_CHV;
  ------------------
  |  |  151|  6.11k|#define SC_AC_CHV			0x00000001 /* Card Holder Verif. */
  ------------------
  373|       |
  374|  6.66k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_AUTH_PIN, obj, &pin);
  ------------------
  |  |  445|  6.66k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  375|  6.66k|}
sc_pkcs15emu_add_rsa_prkey:
  379|  2.41k|{
  380|  2.41k|	sc_pkcs15_prkey_info_t key = *in_key;
  381|       |
  382|  2.41k|	if (key.access_flags == 0)
  ------------------
  |  Branch (382:6): [True: 2.41k, False: 0]
  ------------------
  383|  2.41k|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|  2.41k|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  384|  2.41k|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|  2.41k|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  385|  2.41k|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|  2.41k|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  386|  2.41k|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|  2.41k|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  387|       |
  388|  2.41k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_RSA, obj, &key);
  ------------------
  |  |  419|  2.41k|#define SC_PKCS15_TYPE_PRKEY_RSA		0x101
  ------------------
  389|  2.41k|}
sc_pkcs15emu_add_rsa_pubkey:
  393|    492|{
  394|    492|	sc_pkcs15_pubkey_info_t key = *in_key;
  395|       |
  396|    492|	if (key.access_flags == 0)
  ------------------
  |  Branch (396:6): [True: 492, False: 0]
  ------------------
  397|    492|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    492|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  398|       |
  399|    492|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_RSA, obj, &key);
  ------------------
  |  |  426|    492|#define SC_PKCS15_TYPE_PUBKEY_RSA		0x201
  ------------------
  400|    492|}
sc_pkcs15emu_add_ec_prkey:
  404|    845|{
  405|    845|	sc_pkcs15_prkey_info_t key = *in_key;
  406|       |
  407|    845|	if (key.access_flags == 0)
  ------------------
  |  Branch (407:6): [True: 845, False: 0]
  ------------------
  408|    845|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_SENSITIVE
  ------------------
  |  |  316|    845|#define SC_PKCS15_PRKEY_ACCESS_SENSITIVE	0x01
  ------------------
  409|    845|				| SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE
  ------------------
  |  |  318|    845|#define SC_PKCS15_PRKEY_ACCESS_ALWAYSSENSITIVE	0x04
  ------------------
  410|    845|				| SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE
  ------------------
  |  |  319|    845|#define SC_PKCS15_PRKEY_ACCESS_NEVEREXTRACTABLE	0x08
  ------------------
  411|    845|				| SC_PKCS15_PRKEY_ACCESS_LOCAL;
  ------------------
  |  |  320|    845|#define SC_PKCS15_PRKEY_ACCESS_LOCAL		0x10
  ------------------
  412|       |
  413|    845|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PRKEY_EC, obj, &key);
  ------------------
  |  |  421|    845|#define SC_PKCS15_TYPE_PRKEY_EC		0x104
  ------------------
  414|    845|}
sc_pkcs15emu_add_ec_pubkey:
  418|    849|{
  419|    849|	sc_pkcs15_pubkey_info_t key = *in_key;
  420|       |
  421|    849|	if (key.access_flags == 0)
  ------------------
  |  Branch (421:6): [True: 849, False: 0]
  ------------------
  422|    849|		key.access_flags = SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE;
  ------------------
  |  |  317|    849|#define SC_PKCS15_PRKEY_ACCESS_EXTRACTABLE	0x02
  ------------------
  423|       |
  424|    849|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_PUBKEY_EC, obj, &key);
  ------------------
  |  |  428|    849|#define SC_PKCS15_TYPE_PUBKEY_EC		0x204
  ------------------
  425|    849|}
sc_pkcs15emu_add_x509_cert:
  479|  2.69k|{
  480|  2.69k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_CERT_X509, obj, cert);
  ------------------
  |  |  439|  2.69k|#define SC_PKCS15_TYPE_CERT_X509		0x401
  ------------------
  481|  2.69k|}
sc_pkcs15emu_add_data_object:
  485|  1.88k|{
  486|  1.88k|	return sc_pkcs15emu_object_add(p15card, SC_PKCS15_TYPE_DATA_OBJECT, obj, data);
  ------------------
  |  |  442|  1.88k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  487|  1.88k|}
sc_pkcs15emu_object_add:
  491|  34.9k|{
  492|  34.9k|	sc_pkcs15_object_t *obj;
  493|  34.9k|	unsigned int	df_type;
  494|  34.9k|	size_t		data_len;
  495|       |
  496|  34.9k|	SC_FUNC_CALLED(p15card->card->ctx, SC_LOG_DEBUG_VERBOSE);
  ------------------
  |  |  148|  34.9k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  149|  34.9k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  150|  34.9k|} while (0)
  |  |  ------------------
  |  |  |  Branch (150:10): [Folded, False: 34.9k]
  |  |  ------------------
  ------------------
  497|       |
  498|  34.9k|	obj = calloc(1, sizeof(*obj));
  499|  34.9k|	if (!obj) {
  ------------------
  |  Branch (499:6): [True: 0, False: 34.9k]
  ------------------
  500|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  501|      0|	}
  502|       |
  503|  34.9k|	memcpy(obj, in_obj, sizeof(*obj));
  504|  34.9k|	obj->type = type;
  505|       |
  506|  34.9k|	switch (type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  34.9k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  507|  6.66k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  6.66k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (507:2): [True: 6.66k, False: 28.2k]
  ------------------
  508|  6.66k|		df_type  = SC_PKCS15_AODF;
  ------------------
  |  |  496|  6.66k|#define SC_PKCS15_AODF			8
  ------------------
  509|  6.66k|		data_len = sizeof(struct sc_pkcs15_auth_info);
  510|  6.66k|		break;
  511|  4.12k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  4.12k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (511:2): [True: 4.12k, False: 30.7k]
  ------------------
  512|  4.12k|		df_type  = SC_PKCS15_PRKDF;
  ------------------
  |  |  488|  4.12k|#define SC_PKCS15_PRKDF			0
  ------------------
  513|  4.12k|		data_len = sizeof(struct sc_pkcs15_prkey_info);
  514|  4.12k|		break;
  515|  1.58k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.58k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (515:2): [True: 1.58k, False: 33.3k]
  ------------------
  516|  1.58k|		df_type = SC_PKCS15_PUKDF;
  ------------------
  |  |  489|  1.58k|#define SC_PKCS15_PUKDF			1
  ------------------
  517|  1.58k|		data_len = sizeof(struct sc_pkcs15_pubkey_info);
  518|  1.58k|		break;
  519|  3.00k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  3.00k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (519:2): [True: 3.00k, False: 31.9k]
  ------------------
  520|  3.00k|		df_type = SC_PKCS15_CDF;
  ------------------
  |  |  492|  3.00k|#define SC_PKCS15_CDF			4
  ------------------
  521|  3.00k|		data_len = sizeof(struct sc_pkcs15_cert_info);
  522|  3.00k|		break;
  523|  19.5k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  19.5k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (523:2): [True: 19.5k, False: 15.3k]
  ------------------
  524|  19.5k|		df_type = SC_PKCS15_DODF;
  ------------------
  |  |  495|  19.5k|#define SC_PKCS15_DODF			7
  ------------------
  525|  19.5k|		data_len = sizeof(struct sc_pkcs15_data_info);
  526|  19.5k|		break;
  527|      0|	default:
  ------------------
  |  Branch (527:2): [True: 0, False: 34.9k]
  ------------------
  528|      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__
  |  |  ------------------
  ------------------
  529|      0|		free(obj);
  530|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  531|  34.9k|	}
  532|       |
  533|  34.9k|	obj->data = calloc(1, data_len);
  534|  34.9k|	if (obj->data == NULL) {
  ------------------
  |  Branch (534:6): [True: 0, False: 34.9k]
  ------------------
  535|      0|		free(obj);
  536|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  537|      0|	}
  538|  34.9k|	memcpy(obj->data, data, data_len);
  539|       |
  540|  34.9k|	obj->df = sc_pkcs15emu_get_df(p15card, df_type);
  541|  34.9k|	sc_pkcs15_add_object(p15card, obj);
  542|       |
  543|  34.9k|	LOG_FUNC_RETURN(p15card->card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|  34.9k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  34.9k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  34.9k|	int _ret = r; \
  |  |  |  |  155|  34.9k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 34.9k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  34.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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 34.9k]
  |  |  |  |  ------------------
  |  |  |  |  157|  34.9k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  34.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|  34.9k|	return _ret; \
  |  |  |  |  163|  34.9k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  544|  34.9k|}
pkcs15-syn.c:sc_pkcs15emu_get_df:
  338|  34.9k|{
  339|  34.9k|	sc_pkcs15_df_t	*df;
  340|  34.9k|	sc_file_t	*file;
  341|  34.9k|	int		created = 0;
  342|       |
  343|  45.0k|	while (1) {
  ------------------
  |  Branch (343:9): [True: 45.0k, Folded]
  ------------------
  344|  84.0k|		for (df = p15card->df_list; df; df = df->next) {
  ------------------
  |  Branch (344:31): [True: 73.8k, False: 10.1k]
  ------------------
  345|  73.8k|			if (df->type == type) {
  ------------------
  |  Branch (345:8): [True: 34.9k, False: 38.9k]
  ------------------
  346|  34.9k|				if (created)
  ------------------
  |  Branch (346:9): [True: 10.1k, False: 24.7k]
  ------------------
  347|  10.1k|					df->enumerated = 1;
  348|  34.9k|				return df;
  349|  34.9k|			}
  350|  73.8k|		}
  351|       |
  352|  10.1k|		if (created != 0)
  ------------------
  |  Branch (352:7): [True: 0, False: 10.1k]
  ------------------
  353|      0|			return NULL;
  354|       |
  355|  10.1k|		file = sc_file_new();
  356|  10.1k|		if (!file)
  ------------------
  |  Branch (356:7): [True: 0, False: 10.1k]
  ------------------
  357|      0|			return NULL;
  358|  10.1k|		sc_format_path("11001101", &file->path);
  359|  10.1k|		sc_pkcs15_add_df(p15card, type, &file->path);
  360|  10.1k|		sc_file_free(file);
  361|  10.1k|		created++;
  362|  10.1k|	}
  363|  34.9k|}

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

sc_pkcs15_parse_tokeninfo:
  145|    812|{
  146|    812|	int r;
  147|    812|	size_t ii;
  148|    812|	u8 serial[128];
  149|    812|	size_t serial_len = sizeof(serial);
  150|    812|	u8 mnfid[SC_PKCS15_MAX_LABEL_SIZE];
  151|    812|	size_t mnfid_len  = sizeof(mnfid) - 1;
  152|    812|	u8 label[SC_PKCS15_MAX_LABEL_SIZE];
  153|    812|	size_t label_len = sizeof(label) - 1;
  154|    812|	u8 last_update[32], profile_indication[SC_PKCS15_MAX_LABEL_SIZE];
  155|    812|	size_t lupdate_len = sizeof(last_update) - 1, pi_len = sizeof(profile_indication) - 1;
  156|    812|	size_t flags_len   = sizeof(ti->flags);
  157|    812|	u8 preferred_language[3];
  158|    812|	size_t lang_length = sizeof(preferred_language);
  159|    812|	struct sc_asn1_entry asn1_supported_algorithms[SC_MAX_SUPPORTED_ALGORITHMS + 1],
  160|    812|			asn1_algo_infos[SC_MAX_SUPPORTED_ALGORITHMS][7],
  161|    812|			asn1_algo_infos_parameters[SC_MAX_SUPPORTED_ALGORITHMS][3];
  162|    812|	size_t reference_len = sizeof(ti->supported_algos[0].reference);
  163|    812|	size_t mechanism_len = sizeof(ti->supported_algos[0].mechanism);
  164|    812|	size_t parameter_len = sizeof(ti->supported_algos[0].parameters);
  165|    812|	size_t operations_len = sizeof(ti->supported_algos[0].operations);
  166|    812|	size_t algo_ref_len = sizeof(ti->supported_algos[0].algo_ref);
  167|       |
  168|    812|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  169|    812|	struct sc_asn1_entry asn1_profile_indication[C_ASN1_PROFILE_INDICATION_SIZE];
  170|    812|	struct sc_asn1_entry asn1_toki_attrs[C_ASN1_TOKI_ATTRS_SIZE], asn1_tokeninfo[3], asn1_twlabel[3];
  171|       |
  172|    812|	memset(last_update, 0, sizeof(last_update));
  173|    812|	memset(label, 0, sizeof(label));
  174|    812|	memset(profile_indication, 0, sizeof(profile_indication));
  175|    812|	memset(mnfid, 0, sizeof(mnfid));
  176|       |
  177|    812|	sc_copy_asn1_entry(c_asn1_twlabel, asn1_twlabel);
  178|    812|	sc_copy_asn1_entry(c_asn1_toki_attrs, asn1_toki_attrs);
  179|    812|	sc_copy_asn1_entry(c_asn1_tokeninfo, asn1_tokeninfo);
  180|    812|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  181|    812|	sc_format_asn1_entry(asn1_twlabel, label, &label_len, 0);
  182|    812|	sc_copy_asn1_entry(c_asn1_profile_indication, asn1_profile_indication);
  183|       |
  184|  13.8k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++) {
  ------------------
  |  |   61|  13.8k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (184:13): [True: 12.9k, False: 812]
  ------------------
  185|  12.9k|		sc_copy_asn1_entry(c_asn1_algorithm_info, asn1_algo_infos[ii]);
  186|  12.9k|		sc_copy_asn1_entry(c_asn1_algorithm_info_parameters,
  187|  12.9k|			asn1_algo_infos_parameters[ii]);
  188|  12.9k|	}
  189|    812|	sc_copy_asn1_entry(c_asn1_supported_algorithms, asn1_supported_algorithms);
  190|       |
  191|  13.8k|	for (ii=0; ii<SC_MAX_SUPPORTED_ALGORITHMS; ii++)   {
  ------------------
  |  |   61|  13.8k|#define SC_MAX_SUPPORTED_ALGORITHMS	16
  ------------------
  |  Branch (191:13): [True: 12.9k, False: 812]
  ------------------
  192|  12.9k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 0, &ti->supported_algos[ii].reference, &reference_len, 0);
  193|  12.9k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 1, &ti->supported_algos[ii].mechanism, &mechanism_len, 0);
  194|  12.9k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 2,
  195|  12.9k|			asn1_algo_infos_parameters[ii], NULL, 0);
  196|  12.9k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 0,
  197|  12.9k|			NULL, NULL, 0);
  198|  12.9k|		sc_format_asn1_entry(asn1_algo_infos_parameters[ii] + 1,
  199|  12.9k|			&ti->supported_algos[ii].parameters, &parameter_len, 0);
  200|  12.9k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 3, &ti->supported_algos[ii].operations, &operations_len, 0);
  201|  12.9k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 4, &ti->supported_algos[ii].algo_id, NULL, 1);
  202|  12.9k|		sc_format_asn1_entry(asn1_algo_infos[ii] + 5, &ti->supported_algos[ii].algo_ref, &algo_ref_len, 0);
  203|  12.9k|		sc_format_asn1_entry(asn1_supported_algorithms + ii, asn1_algo_infos[ii], NULL, 0);
  204|  12.9k|	}
  205|       |
  206|    812|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  207|    812|	sc_format_asn1_entry(asn1_last_update + 1, &ti->last_update.path, NULL, 0);
  208|       |
  209|    812|	sc_format_asn1_entry(asn1_profile_indication + 0, &ti->profile_indication.oid, NULL, 0);
  210|    812|	sc_format_asn1_entry(asn1_profile_indication + 1, profile_indication, &pi_len, 0);
  211|       |
  212|    812|	sc_format_asn1_entry(asn1_toki_attrs + 0, &ti->version, NULL, 0);
  213|    812|	sc_format_asn1_entry(asn1_toki_attrs + 1, serial, &serial_len, 0);
  214|    812|	sc_format_asn1_entry(asn1_toki_attrs + 2, mnfid, &mnfid_len, 0);
  215|    812|	sc_format_asn1_entry(asn1_toki_attrs + 3, label, &label_len, 0);
  216|    812|	sc_format_asn1_entry(asn1_toki_attrs + 4, asn1_twlabel, NULL, 0);
  217|    812|	sc_format_asn1_entry(asn1_toki_attrs + 5, &ti->flags, &flags_len, 0);
  218|    812|	sc_format_asn1_entry(asn1_toki_attrs + 6, &ti->seInfo, &ti->num_seInfo, 0);
  219|    812|	sc_format_asn1_entry(asn1_toki_attrs + 7, NULL, NULL, 0);
  220|    812|	sc_format_asn1_entry(asn1_toki_attrs + 8, asn1_supported_algorithms, NULL, 0);
  221|    812|	sc_format_asn1_entry(asn1_toki_attrs + 9, NULL, NULL, 0);
  222|    812|	sc_format_asn1_entry(asn1_toki_attrs + 10, NULL, NULL, 0);
  223|    812|	sc_format_asn1_entry(asn1_toki_attrs + 11, asn1_last_update, NULL, 0);
  224|    812|	sc_format_asn1_entry(asn1_toki_attrs + 12, preferred_language, &lang_length, 0);
  225|    812|	sc_format_asn1_entry(asn1_toki_attrs + 13, asn1_profile_indication, NULL, 0);
  226|    812|	sc_format_asn1_entry(asn1_tokeninfo, asn1_toki_attrs, NULL, 0);
  227|       |
  228|    812|	r = sc_asn1_decode(ctx, asn1_tokeninfo, buf, blen, NULL, NULL);
  229|    812|	if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    812|#define SC_SUCCESS				0
  ------------------
  |  Branch (229:6): [True: 407, False: 405]
  ------------------
  230|       |		/* The decoding could have allocated something we need to free */
  231|    407|		sc_pkcs15_clear_tokeninfo(ti);
  232|    407|		LOG_TEST_RET(ctx, r, "ASN.1 parsing of EF(TokenInfo) failed");
  ------------------
  |  |  174|    407|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|    407|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|    407|	int _ret = (r); \
  |  |  |  |  168|    407|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 407, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  169|    407|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, SC_COLOR_FG_RED, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    407|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|    407|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|    407|		return _ret; \
  |  |  |  |  172|    407|	} \
  |  |  |  |  173|    407|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  233|    407|	}
  234|       |
  235|    405|	if (asn1_toki_attrs[1].flags & SC_ASN1_PRESENT && serial_len > 0)   {
  ------------------
  |  |  147|    810|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (235:6): [True: 324, False: 81]
  |  Branch (235:52): [True: 313, False: 11]
  ------------------
  236|    313|		free(ti->serial_number);
  237|    313|		ti->serial_number = malloc(serial_len * 2 + 1);
  238|    313|		if (ti->serial_number == NULL)
  ------------------
  |  Branch (238:7): [True: 0, False: 313]
  ------------------
  239|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  240|    313|		sc_bin_to_hex(serial, serial_len, ti->serial_number, serial_len * 2 + 1, 0);
  241|    313|		sc_log(ctx, "TokenInfo.serialNunmber '%s'", ti->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  242|    313|	}
  243|       |
  244|    405|	if (ti->manufacturer_id == NULL) {
  ------------------
  |  Branch (244:6): [True: 405, False: 0]
  ------------------
  245|    405|		if (asn1_toki_attrs[2].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    405|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (245:7): [True: 11, False: 394]
  ------------------
  246|     11|			ti->manufacturer_id = strdup((char *) mnfid);
  247|    394|		else
  248|    394|			ti->manufacturer_id = strdup("(unknown)");
  249|    405|		if (ti->manufacturer_id == NULL)
  ------------------
  |  Branch (249:7): [True: 0, False: 405]
  ------------------
  250|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  251|    405|	}
  252|    405|	if (ti->label == NULL) {
  ------------------
  |  Branch (252:6): [True: 405, False: 0]
  ------------------
  253|    405|		if (asn1_toki_attrs[3].flags & SC_ASN1_PRESENT ||
  ------------------
  |  |  147|    810|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (253:7): [True: 16, False: 389]
  ------------------
  254|    389|		    asn1_toki_attrs[4].flags & SC_ASN1_PRESENT)
  ------------------
  |  |  147|    389|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (254:7): [True: 0, False: 389]
  ------------------
  255|     16|			ti->label = strdup((char *) label);
  256|    389|		else
  257|    389|			ti->label = strdup("(unknown)");
  258|    405|		if (ti->label == NULL)
  ------------------
  |  Branch (258:7): [True: 0, False: 405]
  ------------------
  259|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  260|    405|	}
  261|    405|	if (asn1_toki_attrs[11].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    405|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (261:6): [True: 100, False: 305]
  ------------------
  262|    100|		if (asn1_last_update[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    100|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (262:7): [True: 12, False: 88]
  ------------------
  263|     12|			sc_log(ctx, "LastUpdate.generalizedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  264|     12|			ti->last_update.gtime = strdup((char *)last_update);
  265|     12|			if (ti->last_update.gtime == NULL)
  ------------------
  |  Branch (265:8): [True: 0, False: 12]
  ------------------
  266|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  267|     12|		}
  268|     88|		else if (asn1_last_update[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|     88|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (268:12): [True: 71, False: 17]
  ------------------
  269|     71|			sc_log(ctx, "LastUpdate.referencedTime present");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
  270|     71|		}
  271|    100|	}
  272|    405|	if (asn1_toki_attrs[12].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    405|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (272:6): [True: 13, False: 392]
  ------------------
  273|     13|		preferred_language[2] = 0;
  274|     13|		ti->preferred_language = strdup((char *)preferred_language);
  275|     13|		if (ti->preferred_language == NULL)
  ------------------
  |  Branch (275:7): [True: 0, False: 13]
  ------------------
  276|      0|			return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  277|     13|	}
  278|       |
  279|    405|	sc_init_oid(&ti->profile_indication.oid);
  280|    405|	if (asn1_toki_attrs[13].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|    405|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (280:6): [True: 180, False: 225]
  ------------------
  281|    180|		if (asn1_profile_indication[0].flags & SC_ASN1_PRESENT)   {
  ------------------
  |  |  147|    180|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (281:7): [True: 3, False: 177]
  ------------------
  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|    177|		else if (asn1_profile_indication[1].flags & SC_ASN1_PRESENT)  {
  ------------------
  |  |  147|    177|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (284:12): [True: 174, False: 3]
  ------------------
  285|    174|			sc_log(ctx, "ProfileIndication.name present");
  ------------------
  |  |   71|    174|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  286|    174|			ti->profile_indication.name = strdup((char *)profile_indication);
  287|    174|			if (ti->profile_indication.name == NULL)
  ------------------
  |  Branch (287:8): [True: 0, False: 174]
  ------------------
  288|      0|				return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  289|    174|		}
  290|    180|	}
  291|       |
  292|    405|	sc_log(ctx, "LastUpdate.path '%s'", sc_print_path(&ti->last_update.path));
  ------------------
  |  |   71|    405|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  293|    405|	sc_log(ctx, "ProfileIndication.name '%s'",  ti->profile_indication.name);
  ------------------
  |  |   71|    405|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  294|    405|	return SC_SUCCESS;
  ------------------
  |  |   28|    405|#define SC_SUCCESS				0
  ------------------
  295|    405|}
sc_pkcs15_get_lastupdate:
  535|  2.88k|{
  536|  2.88k|	struct sc_context *ctx  = p15card->card->ctx;
  537|  2.88k|	struct sc_file *file = NULL;
  538|  2.88k|	struct sc_asn1_entry asn1_last_update[C_ASN1_LAST_UPDATE_SIZE];
  539|  2.88k|	unsigned char *content, last_update[32] = {0};
  540|  2.88k|	size_t lupdate_len = sizeof(last_update) - 1;
  541|  2.88k|	int r, content_len;
  542|  2.88k|	size_t size;
  543|       |
  544|  2.88k|	if (p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (544:6): [True: 39, False: 2.84k]
  ------------------
  545|     39|		goto done;
  546|       |
  547|  2.84k|	if (!p15card->tokeninfo->last_update.path.len)
  ------------------
  |  Branch (547:6): [True: 2.25k, False: 591]
  ------------------
  548|  2.25k|		return NULL;
  549|       |
  550|    591|	r = sc_select_file(p15card->card, &p15card->tokeninfo->last_update.path, &file);
  551|    591|	if (r < 0)
  ------------------
  |  Branch (551:6): [True: 500, False: 91]
  ------------------
  552|    500|		return NULL;
  553|       |
  554|     91|	size = file->size ? file->size : 1024;
  ------------------
  |  Branch (554:9): [True: 61, False: 30]
  ------------------
  555|     91|	sc_file_free(file);
  556|       |
  557|     91|	content = calloc(1, size);
  558|     91|	if (!content)
  ------------------
  |  Branch (558:6): [True: 0, False: 91]
  ------------------
  559|      0|		return NULL;
  560|       |
  561|     91|	r = sc_read_binary(p15card->card, 0, content, size, 0);
  562|     91|	if (r < 0) {
  ------------------
  |  Branch (562:6): [True: 35, False: 56]
  ------------------
  563|     35|		free(content);
  564|     35|		return NULL;
  565|     35|	}
  566|     56|	content_len = r;
  567|       |
  568|     56|	sc_copy_asn1_entry(c_asn1_last_update, asn1_last_update);
  569|     56|	sc_format_asn1_entry(asn1_last_update + 0, last_update, &lupdate_len, 0);
  570|       |
  571|     56|	r = sc_asn1_decode(ctx, asn1_last_update, content, content_len, NULL, NULL);
  572|     56|	free(content);
  573|     56|	if (r < 0)
  ------------------
  |  Branch (573:6): [True: 15, False: 41]
  ------------------
  574|     15|		return NULL;
  575|       |
  576|     41|	if (asn1_last_update[0].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     41|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (576:6): [True: 1, False: 40]
  ------------------
  577|      1|		p15card->tokeninfo->last_update.gtime = strdup((char *)last_update);
  578|      1|		if (!p15card->tokeninfo->last_update.gtime)
  ------------------
  |  Branch (578:7): [True: 0, False: 1]
  ------------------
  579|      0|			return NULL;
  580|      1|	}
  581|     80|done:
  582|     80|	sc_log(ctx, "lastUpdate.gtime '%s'", p15card->tokeninfo->last_update.gtime);
  ------------------
  |  |   71|     80|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  583|     80|	return p15card->tokeninfo->last_update.gtime;
  584|     41|}
sc_pkcs15_card_new:
  713|  12.5k|{
  714|  12.5k|	struct sc_pkcs15_card *p15card;
  715|       |
  716|  12.5k|	p15card = calloc(1, sizeof(struct sc_pkcs15_card));
  717|  12.5k|	if (p15card == NULL)
  ------------------
  |  Branch (717:6): [True: 0, False: 12.5k]
  ------------------
  718|      0|		return NULL;
  719|       |
  720|  12.5k|	p15card->tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  721|  12.5k|	if (p15card->tokeninfo == NULL) {
  ------------------
  |  Branch (721:6): [True: 0, False: 12.5k]
  ------------------
  722|      0|		free(p15card);
  723|      0|		return NULL;
  724|      0|	}
  725|       |
  726|  12.5k|	p15card->magic = SC_PKCS15_CARD_MAGIC;
  ------------------
  |  |  519|  12.5k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  727|  12.5k|	return p15card;
  728|  12.5k|}
sc_pkcs15_tokeninfo_new:
  733|  9.04k|{
  734|  9.04k|	struct sc_pkcs15_tokeninfo *tokeninfo;
  735|       |
  736|  9.04k|	tokeninfo = calloc(1, sizeof(struct sc_pkcs15_tokeninfo));
  737|  9.04k|	if (tokeninfo == NULL) {
  ------------------
  |  Branch (737:6): [True: 0, False: 9.04k]
  ------------------
  738|      0|		return NULL;
  739|      0|	}
  740|       |
  741|  9.04k|	sc_init_oid(&tokeninfo->profile_indication.oid);
  742|       |
  743|  9.04k|	return tokeninfo;
  744|  9.04k|}
sc_pkcs15_free_tokeninfo:
  775|  22.9k|{
  776|  22.9k|	if (!tokeninfo)
  ------------------
  |  Branch (776:6): [True: 1.33k, False: 21.5k]
  ------------------
  777|  1.33k|		return;
  778|       |
  779|  21.5k|	sc_pkcs15_clear_tokeninfo(tokeninfo);
  780|  21.5k|	free(tokeninfo);
  781|  21.5k|}
sc_pkcs15_free_app:
  785|  40.4k|{
  786|  40.4k|	if (p15card && p15card->app) {
  ------------------
  |  Branch (786:6): [True: 40.4k, False: 0]
  |  Branch (786:17): [True: 697, False: 39.7k]
  ------------------
  787|    697|		free(p15card->app->label);
  788|    697|		free(p15card->app->ddo.value);
  789|    697|		free(p15card->app);
  790|       |		p15card->app = NULL;
  791|    697|	}
  792|  40.4k|}
sc_pkcs15_card_free:
  797|  12.5k|{
  798|  12.5k|	if (p15card == NULL || p15card->magic != SC_PKCS15_CARD_MAGIC)
  ------------------
  |  |  519|  12.5k|#define SC_PKCS15_CARD_MAGIC		0x10203040
  ------------------
  |  Branch (798:6): [True: 0, False: 12.5k]
  |  Branch (798:25): [True: 0, False: 12.5k]
  ------------------
  799|      0|		return;
  800|       |
  801|  12.5k|	if (p15card->ops.clear)
  ------------------
  |  Branch (801:6): [True: 833, False: 11.7k]
  ------------------
  802|    833|		p15card->ops.clear(p15card);
  803|       |
  804|       |	/* For more complicated MD data a dedicated release procedure
  805|       |	 * has to be implemented. */
  806|  12.5k|	if (p15card->md_data)
  ------------------
  |  Branch (806:6): [True: 0, False: 12.5k]
  ------------------
  807|      0|		free(p15card->md_data);
  808|       |
  809|  12.5k|	sc_pkcs15_free_app(p15card);
  810|  12.5k|	sc_pkcs15_remove_objects(p15card);
  811|  12.5k|	sc_pkcs15_remove_dfs(p15card);
  812|  12.5k|	sc_pkcs15_free_unusedspace(p15card);
  813|  12.5k|	p15card->unusedspace_read = 0;
  814|       |
  815|  12.5k|	sc_file_free(p15card->file_app);
  816|  12.5k|	sc_file_free(p15card->file_tokeninfo);
  817|  12.5k|	sc_file_free(p15card->file_odf);
  818|  12.5k|	sc_file_free(p15card->file_unusedspace);
  819|       |
  820|  12.5k|	p15card->magic = 0;
  821|  12.5k|	sc_pkcs15_free_tokeninfo(p15card->tokeninfo);
  822|  12.5k|	sc_pkcs15_free_app(p15card);
  823|  12.5k|	free(p15card);
  824|  12.5k|}
sc_pkcs15_card_clear:
  829|  14.9k|{
  830|  14.9k|	if (p15card == NULL)
  ------------------
  |  Branch (830:6): [True: 0, False: 14.9k]
  ------------------
  831|      0|		return;
  832|       |
  833|  14.9k|	if (p15card->ops.clear)
  ------------------
  |  Branch (833:6): [True: 706, False: 14.2k]
  ------------------
  834|    706|		p15card->ops.clear(p15card);
  835|       |
  836|  14.9k|	p15card->flags = 0;
  837|  14.9k|	p15card->tokeninfo->version = 0;
  838|  14.9k|	p15card->tokeninfo->flags   = 0;
  839|       |
  840|  14.9k|	sc_pkcs15_remove_objects(p15card);
  841|  14.9k|	sc_pkcs15_remove_dfs(p15card);
  842|       |
  843|  14.9k|	p15card->df_list = NULL;
  844|  14.9k|	sc_file_free(p15card->file_app);
  845|  14.9k|	p15card->file_app = NULL;
  846|  14.9k|	sc_file_free(p15card->file_tokeninfo);
  847|  14.9k|	p15card->file_tokeninfo = NULL;
  848|  14.9k|	sc_file_free(p15card->file_odf);
  849|  14.9k|	p15card->file_odf = NULL;
  850|  14.9k|	sc_file_free(p15card->file_unusedspace);
  851|  14.9k|	p15card->file_unusedspace = NULL;
  852|       |
  853|  14.9k|	free(p15card->tokeninfo->label);
  854|  14.9k|	p15card->tokeninfo->label = NULL;
  855|  14.9k|	free(p15card->tokeninfo->serial_number);
  856|  14.9k|	p15card->tokeninfo->serial_number = NULL;
  857|  14.9k|	free(p15card->tokeninfo->manufacturer_id);
  858|  14.9k|	p15card->tokeninfo->manufacturer_id = NULL;
  859|  14.9k|	free(p15card->tokeninfo->last_update.gtime);
  860|  14.9k|	p15card->tokeninfo->last_update.gtime = NULL;
  861|  14.9k|	free(p15card->tokeninfo->preferred_language);
  862|  14.9k|	p15card->tokeninfo->preferred_language = NULL;
  863|  14.9k|	free(p15card->tokeninfo->profile_indication.name);
  864|  14.9k|	p15card->tokeninfo->profile_indication.name = NULL;
  865|  14.9k|	if (p15card->tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (865:6): [True: 32, False: 14.8k]
  ------------------
  866|     32|		size_t i;
  867|     32|		for (i = 0; i < p15card->tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (867:15): [True: 0, False: 32]
  ------------------
  868|      0|			free(p15card->tokeninfo->seInfo[i]);
  869|     32|		free(p15card->tokeninfo->seInfo);
  870|     32|		p15card->tokeninfo->seInfo     = NULL;
  871|     32|		p15card->tokeninfo->num_seInfo = 0;
  872|     32|	}
  873|       |
  874|  14.9k|	sc_pkcs15_free_app(p15card);
  875|  14.9k|}
sc_find_app:
  880|  12.1k|{
  881|  12.1k|	int ii;
  882|       |
  883|  12.1k|	if (card->app_count <= 0)
  ------------------
  |  Branch (883:6): [True: 11.6k, False: 462]
  ------------------
  884|  11.6k|		return NULL;
  885|       |
  886|    462|	if (!aid || !aid->len)
  ------------------
  |  Branch (886:6): [True: 462, False: 0]
  |  Branch (886:14): [True: 0, False: 0]
  ------------------
  887|    462|		return card->app[0];
  888|       |
  889|      0|	for (ii=0; ii < card->app_count; ii++) {
  ------------------
  |  Branch (889:13): [True: 0, False: 0]
  ------------------
  890|      0|		if (card->app[ii]->aid.len != aid->len)
  ------------------
  |  Branch (890:7): [True: 0, False: 0]
  ------------------
  891|      0|			continue;
  892|      0|		if (memcmp(card->app[ii]->aid.value, aid->value, aid->len))
  ------------------
  |  Branch (892:7): [True: 0, False: 0]
  ------------------
  893|      0|			continue;
  894|      0|		return card->app[ii];
  895|      0|	}
  896|      0|	return NULL;
  897|      0|}
sc_pkcs15_bind_internal:
  978|  12.1k|{
  979|  12.1k|	struct sc_path tmppath;
  980|  12.1k|	struct sc_card    *card = p15card->card;
  981|  12.1k|	struct sc_context *ctx  = card->ctx;
  982|  12.1k|	struct sc_pkcs15_tokeninfo tokeninfo;
  983|  12.1k|	struct sc_pkcs15_df *df;
  984|  12.1k|	const struct sc_app_info *info = NULL;
  985|  12.1k|	unsigned char *buf = NULL;
  986|  12.1k|	size_t len;
  987|  12.1k|	int    err, ok = 0;
  988|       |
  989|  12.1k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.1k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.1k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.1k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.1k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.1k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  990|       |	/* Enumerate apps now */
  991|  12.1k|	if (card->app_count < 0) {
  ------------------
  |  Branch (991:6): [True: 11.2k, False: 903]
  ------------------
  992|  11.2k|		err = sc_enum_apps(card);
  993|  11.2k|		if (err != SC_SUCCESS)
  ------------------
  |  |   28|  11.2k|#define SC_SUCCESS				0
  ------------------
  |  Branch (993:7): [True: 10.9k, False: 300]
  ------------------
  994|  10.9k|			sc_log(ctx, "unable to enumerate apps: %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__
  |  |  ------------------
  ------------------
  995|  11.2k|	}
  996|  12.1k|	sc_file_free(p15card->file_app);
  997|  12.1k|	p15card->file_app = sc_file_new();
  998|  12.1k|	if (p15card->file_app == NULL) {
  ------------------
  |  Branch (998:6): [True: 0, False: 12.1k]
  ------------------
  999|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1000|      0|		goto end;
 1001|      0|	}
 1002|       |
 1003|  12.1k|	sc_format_path("3F005015", &p15card->file_app->path);
 1004|       |
 1005|  12.1k|	info = sc_find_app(card, aid);
 1006|  12.1k|	if (info)   {
  ------------------
  |  Branch (1006:6): [True: 462, False: 11.6k]
  ------------------
 1007|    462|		sc_log(ctx, "bind to application('%s',aid:'%s')", info->label, sc_dump_hex(info->aid.value, info->aid.len));
  ------------------
  |  |   71|    462|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1008|    462|		sc_pkcs15_free_app(p15card);
 1009|    462|		p15card->app = sc_dup_app_info(info);
 1010|    462|		if (!p15card->app)   {
  ------------------
  |  Branch (1010:7): [True: 0, False: 462]
  ------------------
 1011|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1012|      0|			goto end;
 1013|      0|		}
 1014|       |
 1015|    462|		if (info->path.len)
  ------------------
  |  Branch (1015:7): [True: 419, False: 43]
  ------------------
 1016|    419|			p15card->file_app->path = info->path;
 1017|       |
 1018|    462|		if (info->ddo.value && info->ddo.len)
  ------------------
  |  Branch (1018:7): [True: 51, False: 411]
  |  Branch (1018:26): [True: 48, False: 3]
  ------------------
 1019|     48|			parse_ddo(p15card, info->ddo.value, info->ddo.len);
 1020|       |
 1021|    462|	}
 1022|  11.6k|	else if (aid)   {
  ------------------
  |  Branch (1022:11): [True: 0, False: 11.6k]
  ------------------
 1023|      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__
  |  |  ------------------
  ------------------
 1024|      0|		err = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1025|      0|		goto end;
 1026|      0|	}
 1027|  12.1k|	sc_log(ctx, "application path '%s'", sc_print_path(&p15card->file_app->path));
  ------------------
  |  |   71|  12.1k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1028|       |
 1029|       |	/* Check if pkcs15 directory exists */
 1030|  12.1k|	err = sc_select_file(card, &p15card->file_app->path, NULL);
 1031|       |
 1032|       |	/* If the above test failed on cards without EF(DIR),
 1033|       |	 * try to continue read ODF from 3F005031. -aet
 1034|       |	 */
 1035|  12.1k|	if ((err != SC_SUCCESS) && (card->app_count < 1)) {
  ------------------
  |  |   28|  12.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1035:6): [True: 10.2k, False: 1.83k]
  |  Branch (1035:29): [True: 9.91k, False: 354]
  ------------------
 1036|  9.91k|		sc_format_path("3F00", &p15card->file_app->path);
 1037|  9.91k|		err = SC_SUCCESS;
  ------------------
  |  |   28|  9.91k|#define SC_SUCCESS				0
  ------------------
 1038|  9.91k|	}
 1039|       |
 1040|  12.1k|	if (err < 0)   {
  ------------------
  |  Branch (1040:6): [True: 354, False: 11.7k]
  ------------------
 1041|    354|		sc_log (ctx, "Cannot select application path");
  ------------------
  |  |   71|    354|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1042|    354|		goto end;
 1043|    354|	}
 1044|       |
 1045|  11.7k|	if (p15card->file_odf == NULL) {
  ------------------
  |  Branch (1045:6): [True: 11.7k, False: 8]
  ------------------
 1046|       |		/* check if an ODF is present; we don't know yet whether we have a pkcs15 card */
 1047|  11.7k|		sc_format_path("5031", &tmppath);
 1048|  11.7k|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1049|  11.7k|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|  11.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1049:7): [True: 3, False: 11.7k]
  ------------------
 1050|      3|			sc_log(ctx, "Cannot make absolute path to EF(ODF); 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__
  |  |  ------------------
  ------------------
 1051|      3|			goto end;
 1052|      3|		}
 1053|  11.7k|		sc_log(ctx, "absolute path to EF(ODF) %s", sc_print_path(&tmppath));
  ------------------
  |  |   71|  11.7k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1054|  11.7k|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1055|  11.7k|	}
 1056|      8|	else {
 1057|      8|		tmppath = p15card->file_odf->path;
 1058|      8|		sc_file_free(p15card->file_odf);
 1059|      8|		p15card->file_odf = NULL;
 1060|      8|		err = sc_select_file(card, &tmppath, &p15card->file_odf);
 1061|      8|	}
 1062|       |
 1063|  11.7k|	if (err != SC_SUCCESS) {
  ------------------
  |  |   28|  11.7k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1063:6): [True: 10.7k, False: 989]
  ------------------
 1064|  10.7k|		sc_log(ctx, "EF(ODF) not found in '%s'", sc_print_path(&tmppath));
  ------------------
  |  |   71|  10.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__
  |  |  ------------------
  ------------------
 1065|  10.7k|		goto end;
 1066|  10.7k|	}
 1067|       |
 1068|    989|	len = p15card->file_odf->size;
 1069|    989|	if (!len) {
  ------------------
  |  Branch (1069:6): [True: 155, False: 834]
  ------------------
 1070|    155|		sc_log(ctx, "EF(ODF) is empty");
  ------------------
  |  |   71|    155|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1071|    155|		goto end;
 1072|    155|	}
 1073|    834|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|    834|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1073:6): [True: 34, False: 800]
  ------------------
 1074|     34|		sc_log(ctx, "EF(ODF) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1075|     34|		goto end;
 1076|     34|	}
 1077|    800|	buf = malloc(len);
 1078|    800|	if(buf == NULL) {
  ------------------
  |  Branch (1078:5): [True: 0, False: 800]
  ------------------
 1079|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1080|      0|		goto end;
 1081|      0|	}
 1082|       |
 1083|    800|	err = -1; /* file state: not in cache */
 1084|    800|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1084:6): [True: 160, False: 640]
  ------------------
 1085|    160|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1086|    160|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|    160|#define SC_SUCCESS				0
  ------------------
  |  Branch (1086:7): [True: 1, False: 159]
  ------------------
 1087|      1|			err = (int)len;
 1088|    160|	}
 1089|    800|	if (err < 0) {
  ------------------
  |  Branch (1089:6): [True: 799, False: 1]
  ------------------
 1090|    799|		err = sc_read_binary(card, 0, buf, len, 0);
 1091|    799|		if (err < 2) {
  ------------------
  |  Branch (1091:7): [True: 371, False: 428]
  ------------------
 1092|    371|			if (err < 0) {
  ------------------
  |  Branch (1092:8): [True: 335, False: 36]
  ------------------
 1093|    335|				sc_log(ctx, "read EF(ODF) file error: %s", sc_strerror(err));
  ------------------
  |  |   71|    335|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1094|    335|			} else {
 1095|     36|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|     36|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1096|     36|				sc_log(ctx, "Invalid content of EF(ODF): %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1097|     36|			}
 1098|    371|			goto end;
 1099|    371|		}
 1100|       |		/* sc_read_binary may return less than requested */
 1101|    428|		len = err;
 1102|       |
 1103|    428|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1103:7): [True: 85, False: 343]
  ------------------
 1104|     85|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1105|     85|		}
 1106|    428|	}
 1107|       |
 1108|    429|	if (parse_odf(buf, len, p15card)) {
  ------------------
  |  Branch (1108:6): [True: 184, False: 245]
  ------------------
 1109|    184|		err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|    184|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1110|    184|		sc_log(ctx, "Unable to parse ODF");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1111|    184|		goto end;
 1112|    184|	}
 1113|    245|	free(buf);
 1114|    245|	buf = NULL;
 1115|       |
 1116|    245|	sc_log(ctx, "The following DFs were found:");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1117|  1.27k|	for (df = p15card->df_list; df; df = df->next)
  ------------------
  |  Branch (1117:30): [True: 1.02k, False: 245]
  ------------------
 1118|  1.02k|		sc_log(ctx, "  DF type %u, path %s, index %u, count %d", df->type,
  ------------------
  |  |   71|  1.27k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1119|    245|				sc_print_path(&df->path), df->path.index, df->path.count);
 1120|       |
 1121|    245|	if (p15card->file_tokeninfo == NULL) {
  ------------------
  |  Branch (1121:6): [True: 245, False: 0]
  ------------------
 1122|    245|		sc_format_path("5032", &tmppath);
 1123|    245|		err = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &tmppath);
 1124|    245|		if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|    245|#define SC_SUCCESS				0
  ------------------
  |  Branch (1124:7): [True: 0, False: 245]
  ------------------
 1125|      0|			sc_log(ctx, "Cannot make absolute path to EF(TokenInfo); 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__
  |  |  ------------------
  ------------------
 1126|      0|			goto end;
 1127|      0|		}
 1128|    245|		sc_log(ctx, "absolute path to EF(TokenInfo) %s", sc_print_path(&tmppath));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1129|    245|	}
 1130|      0|	else {
 1131|      0|		tmppath = p15card->file_tokeninfo->path;
 1132|      0|		sc_file_free(p15card->file_tokeninfo);
 1133|      0|		p15card->file_tokeninfo = NULL;
 1134|      0|	}
 1135|       |
 1136|    245|	err = sc_select_file(card, &tmppath, &p15card->file_tokeninfo);
 1137|    245|	if (err)   {
  ------------------
  |  Branch (1137:6): [True: 117, False: 128]
  ------------------
 1138|    117|		sc_log(ctx, "cannot select EF(TokenInfo) file: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1139|    117|		goto end;
 1140|    117|	}
 1141|       |
 1142|    128|	len = p15card->file_tokeninfo->size;
 1143|    128|	if (!len) {
  ------------------
  |  Branch (1143:6): [True: 3, False: 125]
  ------------------
 1144|      3|		sc_log(ctx, "EF(TokenInfo) is empty");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1145|      3|		goto end;
 1146|      3|	}
 1147|    125|	if (len > MAX_FILE_SIZE) {
  ------------------
  |  |  229|    125|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (1147:6): [True: 33, False: 92]
  ------------------
 1148|     33|		sc_log(ctx, "EF(TokenInfo) too large");
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1149|     33|		goto end;
 1150|     33|	}
 1151|     92|	buf = malloc(len);
 1152|     92|	if(buf == NULL) {
  ------------------
  |  Branch (1152:5): [True: 0, False: 92]
  ------------------
 1153|      0|		err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1154|      0|		goto end;
 1155|      0|	}
 1156|       |
 1157|     92|	err = -1; /* file state: not in cache */
 1158|     92|	if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1158:6): [True: 30, False: 62]
  ------------------
 1159|     30|		err = sc_pkcs15_read_cached_file(p15card, &tmppath, &buf, &len);
 1160|     30|		if (err == SC_SUCCESS)
  ------------------
  |  |   28|     30|#define SC_SUCCESS				0
  ------------------
  |  Branch (1160:7): [True: 0, False: 30]
  ------------------
 1161|      0|			err = (int)len;
 1162|     30|	}
 1163|     92|	if (err < 0) {
  ------------------
  |  Branch (1163:6): [True: 92, False: 0]
  ------------------
 1164|     92|		err = sc_read_binary(card, 0, buf, len, 0);
 1165|     92|		if (err <= 2) {
  ------------------
  |  Branch (1165:7): [True: 50, False: 42]
  ------------------
 1166|     50|			if (err < 0)   {
  ------------------
  |  Branch (1166:8): [True: 41, False: 9]
  ------------------
 1167|     41|				sc_log(ctx, "read EF(TokenInfo) file error: %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__
  |  |  ------------------
  ------------------
 1168|     41|			} else {
 1169|      9|				err = SC_ERROR_PKCS15_APP_NOT_FOUND;
  ------------------
  |  |  131|      9|#define SC_ERROR_PKCS15_APP_NOT_FOUND		-1901
  ------------------
 1170|      9|				sc_log(ctx, "Invalid content of EF(TokenInfo): %s", sc_strerror(err));
  ------------------
  |  |   71|      9|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 1171|      9|			}
 1172|     50|			goto end;
 1173|     50|		}
 1174|       |		/* sc_read_binary may return less than requested */
 1175|     42|		len = err;
 1176|       |
 1177|     42|		if (p15card->opts.use_file_cache) {
  ------------------
  |  Branch (1177:7): [True: 7, False: 35]
  ------------------
 1178|      7|			sc_pkcs15_cache_file(p15card, &tmppath, buf, len);
 1179|      7|		}
 1180|     42|	}
 1181|       |
 1182|     42|	memset(&tokeninfo, 0, sizeof(tokeninfo));
 1183|     42|	err = sc_pkcs15_parse_tokeninfo(ctx, &tokeninfo, buf, (size_t)err);
 1184|     42|	if (err != SC_SUCCESS)   {
  ------------------
  |  |   28|     42|#define SC_SUCCESS				0
  ------------------
  |  Branch (1184:6): [True: 26, False: 16]
  ------------------
 1185|     26|		sc_log(ctx, "cannot parse TokenInfo content: %s", sc_strerror(err));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1186|     26|		goto end;
 1187|     26|	}
 1188|       |
 1189|     16|	sc_pkcs15_clear_tokeninfo(p15card->tokeninfo);
 1190|     16|	*(p15card->tokeninfo) = tokeninfo;
 1191|       |
 1192|     16|	if (!p15card->tokeninfo->serial_number && 0 == card->serialnr.len) {
  ------------------
  |  Branch (1192:6): [True: 15, False: 1]
  |  Branch (1192:44): [True: 15, False: 0]
  ------------------
 1193|     15|		sc_card_ctl(p15card->card, SC_CARDCTL_GET_SERIALNR, &card->serialnr);
 1194|     15|	}
 1195|       |
 1196|     16|	if (!p15card->tokeninfo->serial_number && card->serialnr.len)   {
  ------------------
  |  Branch (1196:6): [True: 15, False: 1]
  |  Branch (1196:44): [True: 11, False: 4]
  ------------------
 1197|     11|		char *serial = calloc(1, card->serialnr.len*2 + 1);
 1198|     11|		size_t ii;
 1199|     11|		if (!serial) {
  ------------------
  |  Branch (1199:7): [True: 0, False: 11]
  ------------------
 1200|      0|			err = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 1201|      0|			goto end;
 1202|      0|		}
 1203|       |
 1204|    205|		for(ii=0;ii<card->serialnr.len;ii++)
  ------------------
  |  Branch (1204:12): [True: 194, False: 11]
  ------------------
 1205|    194|			sprintf(serial + ii*2, "%02X", *(card->serialnr.value + ii));
 1206|       |
 1207|     11|		p15card->tokeninfo->serial_number = serial;
 1208|     11|		sc_log(ctx, "p15card->tokeninfo->serial_number %s", p15card->tokeninfo->serial_number);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 1209|     11|	}
 1210|       |
 1211|     16|	ok = 1;
 1212|  12.1k|end:
 1213|  12.1k|	if(buf != NULL)
  ------------------
  |  Branch (1213:5): [True: 647, False: 11.4k]
  ------------------
 1214|    647|		free(buf);
 1215|  12.1k|	if (!ok) {
  ------------------
  |  Branch (1215:6): [True: 12.0k, False: 16]
  ------------------
 1216|  12.0k|		sc_pkcs15_card_clear(p15card);
 1217|  12.0k|		if (err == SC_ERROR_FILE_NOT_FOUND)
  ------------------
  |  |   51|  12.0k|#define SC_ERROR_FILE_NOT_FOUND			-1201
  ------------------
  |  Branch (1217:7): [True: 1.10k, False: 10.9k]
  ------------------
 1218|  1.10k|			err = SC_ERROR_WRONG_CARD;
  ------------------
  |  |   94|  1.10k|#define SC_ERROR_WRONG_CARD			-1413
  ------------------
 1219|  12.0k|		LOG_FUNC_RETURN(ctx, err);
  ------------------
  |  |  164|  12.0k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  12.0k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  12.0k|	int _ret = r; \
  |  |  |  |  155|  12.0k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 12.0k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  12.0k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|  11.8k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 11.8k, False: 225]
  |  |  |  |  ------------------
  |  |  |  |  157|  12.0k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  12.0k|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|  12.0k|	return _ret; \
  |  |  |  |  163|  12.0k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1220|  12.0k|	}
 1221|       |
 1222|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1223|     16|}
pkcs15_get_default_use_file_cache:
 1227|  12.5k|{
 1228|       |	/* enable file caching by default for cards with static content to avoid
 1229|       |	 * synchronization problems.
 1230|       |	 *
 1231|       |	 * The following list was initialized with the cards that can't be modified
 1232|       |	 * with OpenSC i.e. which don't have a profile/driver for pkcs15-init. */
 1233|  12.5k|	const char *card_drivers_with_file_cache[] = {
 1234|  12.5k|			"atrust-acos",
 1235|  12.5k|			"belpic",
 1236|  12.5k|			"cac1",
 1237|  12.5k|			"cac",
 1238|  12.5k|			"coolkey",
 1239|  12.5k|			"edo",
 1240|  12.5k|			"esteid2018",
 1241|  12.5k|			"esteid2025",
 1242|  12.5k|			"flex",
 1243|  12.5k|			"cyberflex",
 1244|  12.5k|			"gemsafeV1",
 1245|  12.5k|			"idprime",
 1246|  12.5k|			"itacns",
 1247|  12.5k|			"jpki",
 1248|  12.5k|			"MaskTech",
 1249|  12.5k|			"mcrd",
 1250|  12.5k|			"myeid",
 1251|  12.5k|			"npa",
 1252|  12.5k|			"nqapplet",
 1253|  12.5k|			"tcos",
 1254|  12.5k|			"dtrust",
 1255|  12.5k|			"lteid",
 1256|  12.5k|	};
 1257|       |
 1258|  12.5k|	if (NULL == card || NULL == card->driver || NULL == card->driver->short_name)
  ------------------
  |  Branch (1258:6): [True: 0, False: 12.5k]
  |  Branch (1258:22): [True: 0, False: 12.5k]
  |  Branch (1258:46): [True: 0, False: 12.5k]
  ------------------
 1259|      0|		return "no";
 1260|   227k|	for (size_t i = 0; i < (sizeof card_drivers_with_file_cache / sizeof *card_drivers_with_file_cache); i++) {
  ------------------
  |  Branch (1260:21): [True: 220k, False: 7.18k]
  ------------------
 1261|   220k|		if (0 == strcmp(card->driver->short_name, card_drivers_with_file_cache[i]))
  ------------------
  |  Branch (1261:7): [True: 5.36k, False: 214k]
  ------------------
 1262|  5.36k|			return "public";
 1263|   220k|	}
 1264|       |
 1265|  7.18k|	return "no";
 1266|  12.5k|}
sc_pkcs15_bind:
 1271|  12.5k|{
 1272|  12.5k|	struct sc_pkcs15_card *p15card = NULL;
 1273|  12.5k|	struct sc_context *ctx;
 1274|  12.5k|	scconf_block *conf_block = NULL;
 1275|  12.5k|	int r, emu_first, enable_emu;
 1276|  12.5k|	const char *use_file_cache;
 1277|  12.5k|	const char *pin_protected_certificate, *private_certificate;
 1278|       |
 1279|  12.5k|	if (card == NULL || p15card_out == NULL) {
  ------------------
  |  Branch (1279:6): [True: 0, False: 12.5k]
  |  Branch (1279:22): [True: 0, False: 12.5k]
  ------------------
 1280|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1281|      0|	}
 1282|  12.5k|	ctx = card->ctx;
 1283|       |
 1284|  12.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1285|  12.5k|	sc_log(ctx, "application(aid:'%s')", aid ? sc_dump_hex(aid->value, aid->len) : "empty");
  ------------------
  |  |   71|  25.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: 12.5k]
  |  |  ------------------
  ------------------
 1286|       |
 1287|  12.5k|	p15card = sc_pkcs15_card_new();
 1288|  12.5k|	if (p15card == NULL)
  ------------------
  |  Branch (1288:6): [True: 0, False: 12.5k]
  ------------------
 1289|  12.5k|		LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
  ------------------
  |  |  164|      0|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|      0|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|      0|	int _ret = r; \
  |  |  |  |  155|      0|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|      0|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|      0|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|      0|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|      0|	return _ret; \
  |  |  |  |  163|      0|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1290|       |
 1291|  12.5k|	p15card->card = card;
 1292|  12.5k|	p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  12.5k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1293|  12.5k|	use_file_cache = pkcs15_get_default_use_file_cache(card);
 1294|  12.5k|	p15card->opts.use_pin_cache = 1;
 1295|  12.5k|	p15card->opts.pin_cache_counter = 10;
 1296|  12.5k|	p15card->opts.pin_cache_ignore_user_consent = 0;
 1297|  12.5k|	pin_protected_certificate = "protect";
 1298|  12.5k|	private_certificate = "";
 1299|       |
 1300|  12.5k|	conf_block = sc_get_conf_block(ctx, "framework", "pkcs15", 1);
 1301|  12.5k|	if (conf_block) {
  ------------------
  |  Branch (1301:6): [True: 0, False: 12.5k]
  ------------------
 1302|      0|		use_file_cache = scconf_get_str(conf_block, "use_file_caching", use_file_cache);
 1303|      0|		p15card->opts.use_pin_cache = scconf_get_bool(conf_block, "use_pin_caching", p15card->opts.use_pin_cache);
 1304|      0|		p15card->opts.pin_cache_counter = scconf_get_int(conf_block, "pin_cache_counter", p15card->opts.pin_cache_counter);
 1305|      0|		p15card->opts.pin_cache_ignore_user_consent = scconf_get_bool(conf_block, "pin_cache_ignore_user_consent",
 1306|      0|				p15card->opts.pin_cache_ignore_user_consent);
 1307|      0|		pin_protected_certificate = scconf_get_str(conf_block, "pin_protected_certificate", pin_protected_certificate);
 1308|       |		/* read also the old value to keep backward compatibility */
 1309|      0|		private_certificate = scconf_get_str(conf_block, "private_certificate", private_certificate);
 1310|      0|	}
 1311|       |
 1312|  12.5k|	if (0 == strcmp(use_file_cache, "yes")) {
  ------------------
  |  Branch (1312:6): [True: 0, False: 12.5k]
  ------------------
 1313|      0|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_ALL_FILES;
  ------------------
  |  |  606|      0|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
 1314|  12.5k|	} else if (0 == strcmp(use_file_cache, "public")) {
  ------------------
  |  Branch (1314:13): [True: 5.36k, False: 7.18k]
  ------------------
 1315|  5.36k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_PUBLIC_FILES;
  ------------------
  |  |  605|  5.36k|#define SC_PKCS15_OPTS_CACHE_PUBLIC_FILES		1
  ------------------
 1316|  7.18k|	} else if (0 == strcmp(use_file_cache, "no")) {
  ------------------
  |  Branch (1316:13): [True: 7.18k, False: 0]
  ------------------
 1317|  7.18k|		p15card->opts.use_file_cache = SC_PKCS15_OPTS_CACHE_NO_FILES;
  ------------------
  |  |  604|  7.18k|#define SC_PKCS15_OPTS_CACHE_NO_FILES			0
  ------------------
 1318|  7.18k|	}
 1319|       |
 1320|  12.5k|	if (0 == strcmp(pin_protected_certificate, "protect")) {
  ------------------
  |  Branch (1320:6): [True: 12.5k, False: 0]
  ------------------
 1321|  12.5k|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|  12.5k|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1322|  12.5k|	} else if (0 == strcmp(pin_protected_certificate, "ignore")) {
  ------------------
  |  Branch (1322:13): [True: 0, False: 0]
  ------------------
 1323|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1324|      0|	} else if (0 == strcmp(pin_protected_certificate, "declassify")) {
  ------------------
  |  Branch (1324:13): [True: 0, False: 0]
  ------------------
 1325|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1326|      0|	}
 1327|       |	/* overwrite pin_protected_certificate when private_certificate set */
 1328|  12.5k|	if (0 == strcmp(private_certificate, "protect")) {
  ------------------
  |  Branch (1328:6): [True: 0, False: 12.5k]
  ------------------
 1329|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT;
  ------------------
  |  |  609|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_PROTECT		0
  ------------------
 1330|  12.5k|	} else if (0 == strcmp(private_certificate, "ignore")) {
  ------------------
  |  Branch (1330:13): [True: 0, False: 12.5k]
  ------------------
 1331|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE;
  ------------------
  |  |  610|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_IGNORE		1
  ------------------
 1332|  12.5k|	} else if (0 == strcmp(private_certificate, "declassify")) {
  ------------------
  |  Branch (1332:13): [True: 0, False: 12.5k]
  ------------------
 1333|      0|		p15card->opts.pin_protected_certificate = SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY;
  ------------------
  |  |  611|      0|#define SC_PKCS15_CARD_OPTS_PRIV_CERT_DECLASSIFY	2
  ------------------
 1334|      0|	}
 1335|  12.5k|	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|  12.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__
  |  |  ------------------
  ------------------
 1336|  12.5k|			p15card->opts.use_file_cache, p15card->opts.use_pin_cache, p15card->opts.pin_cache_counter,
 1337|  12.5k|			p15card->opts.pin_cache_ignore_user_consent, p15card->opts.pin_protected_certificate);
 1338|       |
 1339|  12.5k|	r = sc_lock(card);
 1340|  12.5k|	if (r) {
  ------------------
  |  Branch (1340:6): [True: 0, False: 12.5k]
  ------------------
 1341|      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__
  |  |  ------------------
  ------------------
 1342|      0|		sc_pkcs15_card_free(p15card);
 1343|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1344|      0|	}
 1345|       |
 1346|  12.5k|	enable_emu = scconf_get_bool(conf_block, "enable_pkcs15_emulation", 1);
 1347|  12.5k|	if (enable_emu) {
  ------------------
  |  Branch (1347:6): [True: 12.5k, False: 0]
  ------------------
 1348|  12.5k|		sc_log(ctx, "PKCS#15 emulation enabled");
  ------------------
  |  |   71|  12.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__
  |  |  ------------------
  ------------------
 1349|  12.5k|		emu_first = scconf_get_bool(conf_block, "try_emulation_first", 0);
 1350|  12.5k|		if (emu_first || sc_pkcs15_is_emulation_only(card)) {
  ------------------
  |  Branch (1350:7): [True: 0, False: 12.5k]
  |  Branch (1350:20): [True: 2.82k, False: 9.72k]
  ------------------
 1351|  2.82k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1352|  2.82k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  2.82k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1352:8): [True: 1.36k, False: 1.45k]
  ------------------
 1353|  1.36k|				goto done;
 1354|  1.45k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1355|  1.45k|			if (r < 0)
  ------------------
  |  Branch (1355:8): [True: 1.44k, False: 8]
  ------------------
 1356|  1.44k|				goto error;
 1357|  9.72k|		} else {
 1358|  9.72k|			r = sc_pkcs15_bind_internal(p15card, aid);
 1359|  9.72k|			if (r == SC_SUCCESS)
  ------------------
  |  |   28|  9.72k|#define SC_SUCCESS				0
  ------------------
  |  Branch (1359:8): [True: 217, False: 9.51k]
  ------------------
 1360|    217|				goto done;
 1361|  9.51k|			r = sc_pkcs15_bind_synthetic(p15card, aid);
 1362|  9.51k|			if (r < 0)
  ------------------
  |  Branch (1362:8): [True: 5.66k, False: 3.84k]
  ------------------
 1363|  5.66k|				goto error;
 1364|  9.51k|		}
 1365|  12.5k|	}
 1366|      0|	else {
 1367|      0|		r = sc_pkcs15_bind_internal(p15card, aid);
 1368|      0|		if (r < 0)
  ------------------
  |  Branch (1368:7): [True: 0, False: 0]
  ------------------
 1369|      0|			goto error;
 1370|      0|	}
 1371|  5.43k|done:
 1372|  5.43k|	*p15card_out = p15card;
 1373|  5.43k|	sc_unlock(card);
 1374|  5.43k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  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|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 5.43k]
  |  |  |  |  ------------------
  |  |  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1375|  7.11k|error:
 1376|  7.11k|	sc_unlock(card);
 1377|  7.11k|	sc_pkcs15_card_free(p15card);
 1378|  7.11k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  7.11k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  7.11k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  7.11k|	int _ret = r; \
  |  |  |  |  155|  7.11k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 7.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  7.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|  7.11k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 7.11k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  7.11k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  7.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|  7.11k|	return _ret; \
  |  |  |  |  163|  7.11k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1379|  7.11k|}
sc_pkcs15_get_objects:
 1483|    161|{
 1484|    161|	return sc_pkcs15_get_objects_cond(p15card, type, NULL, NULL, ret, ret_size);
 1485|    161|}
sc_pkcs15_search_objects:
 1666|      2|{
 1667|      2|	return __sc_pkcs15_search_objects(p15card,
 1668|      2|			sk->class_mask, sk->type,
 1669|      2|			compare_obj_key, sk,
 1670|      2|			ret, ret_size);
 1671|      2|}
sc_pkcs15_get_objects_cond:
 1678|    161|{
 1679|    161|	return __sc_pkcs15_search_objects(p15card, 0, type,
 1680|    161|			func, func_arg, ret, ret_size);
 1681|    161|}
sc_pkcs15_find_object_by_id:
 1687|  1.88k|{
 1688|  1.88k|	struct sc_pkcs15_search_key sk;
 1689|  1.88k|	int	r;
 1690|       |
 1691|  1.88k|	memset(&sk, 0, sizeof(sk));
 1692|  1.88k|	sk.id = id;
 1693|       |
 1694|  1.88k|	r = __sc_pkcs15_search_objects(p15card, 0, type, compare_obj_key, &sk, out, 1);
 1695|  1.88k|	if (r < 0)
  ------------------
  |  Branch (1695:6): [True: 0, False: 1.88k]
  ------------------
 1696|      0|		return r;
 1697|  1.88k|	if (r == 0)
  ------------------
  |  Branch (1697:6): [True: 784, False: 1.09k]
  ------------------
 1698|    784|		return SC_ERROR_OBJECT_NOT_FOUND;
  ------------------
  |  |   88|    784|#define SC_ERROR_OBJECT_NOT_FOUND		-1407
  ------------------
 1699|  1.09k|	return 0;
 1700|  1.88k|}
sc_pkcs15_find_cert_by_id:
 1706|  1.10k|{
 1707|  1.10k|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_CERT, id, out);
  ------------------
  |  |  438|  1.10k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
 1708|  1.10k|}
sc_pkcs15_find_pin_by_auth_id:
 1738|    778|{
 1739|    778|	return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_AUTH, id, out);
  ------------------
  |  |  444|    778|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
 1740|    778|}
sc_pkcs15_add_object:
 1930|  34.9k|{
 1931|  34.9k|	struct sc_pkcs15_object *p = p15card->obj_list;
 1932|       |
 1933|  34.9k|	if (!obj)
  ------------------
  |  Branch (1933:6): [True: 0, False: 34.9k]
  ------------------
 1934|      0|		return 0;
 1935|  34.9k|	obj->next = obj->prev = NULL;
 1936|  34.9k|	if (p15card->obj_list == NULL) {
  ------------------
  |  Branch (1936:6): [True: 5.08k, False: 29.8k]
  ------------------
 1937|  5.08k|		p15card->obj_list = obj;
 1938|  5.08k|		return 0;
 1939|  5.08k|	}
 1940|   409k|	while (p->next != NULL)
  ------------------
  |  Branch (1940:9): [True: 379k, False: 29.8k]
  ------------------
 1941|   379k|		p = p->next;
 1942|  29.8k|	p->next = obj;
 1943|  29.8k|	obj->prev = p;
 1944|       |
 1945|  29.8k|	return 0;
 1946|  34.9k|}
sc_pkcs15_free_object:
 1981|  34.9k|{
 1982|  34.9k|	if (!obj)
  ------------------
  |  Branch (1982:6): [True: 0, False: 34.9k]
  ------------------
 1983|      0|		return;
 1984|  34.9k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  34.9k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
 1985|  4.12k|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|  4.12k|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1985:2): [True: 4.12k, False: 30.8k]
  ------------------
 1986|  4.12k|		sc_pkcs15_free_prkey_info((sc_pkcs15_prkey_info_t *)obj->data);
 1987|  4.12k|		break;
 1988|  1.58k|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|  1.58k|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1988:2): [True: 1.58k, False: 33.3k]
  ------------------
 1989|       |		/* This is normally passed to framework-pkcs15,
 1990|       |		 * but if something fails on the way, it would not get freed */
 1991|  1.58k|		if (obj->emulated) {
  ------------------
  |  Branch (1991:7): [True: 1.29k, False: 286]
  ------------------
 1992|  1.29k|			sc_pkcs15_free_pubkey(obj->emulated);
 1993|  1.29k|		}
 1994|  1.58k|		sc_pkcs15_free_pubkey_info((sc_pkcs15_pubkey_info_t *)obj->data);
 1995|  1.58k|		break;
 1996|  3.00k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  3.00k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1996:2): [True: 3.00k, False: 31.9k]
  ------------------
 1997|  3.00k|		sc_pkcs15_free_cert_info((sc_pkcs15_cert_info_t *)obj->data);
 1998|  3.00k|		break;
 1999|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (1999:2): [True: 0, False: 34.9k]
  ------------------
 2000|      0|		sc_pkcs15_free_skey_info((sc_pkcs15_skey_info_t *)obj->data);
 2001|      0|		break;
 2002|  19.5k|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|  19.5k|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (2002:2): [True: 19.5k, False: 15.4k]
  ------------------
 2003|  19.5k|		sc_pkcs15_free_data_info((sc_pkcs15_data_info_t *)obj->data);
 2004|  19.5k|		break;
 2005|  6.71k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  6.71k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2005:2): [True: 6.71k, False: 28.2k]
  ------------------
 2006|  6.71k|		sc_pkcs15_free_auth_info((sc_pkcs15_auth_info_t *)obj->data);
 2007|  6.71k|		break;
 2008|      0|	default:
  ------------------
  |  Branch (2008:2): [True: 0, False: 34.9k]
  ------------------
 2009|      0|		free(obj->data);
 2010|  34.9k|	}
 2011|       |
 2012|  34.9k|	sc_pkcs15_free_object_content(obj);
 2013|       |
 2014|  34.9k|	free(obj);
 2015|  34.9k|}
sc_pkcs15_add_df:
 2020|  15.0k|{
 2021|  15.0k|	struct sc_pkcs15_df *p, *newdf;
 2022|       |
 2023|  15.0k|	newdf = calloc(1, sizeof(struct sc_pkcs15_df));
 2024|  15.0k|	if (newdf == NULL)
  ------------------
  |  Branch (2024:6): [True: 0, False: 15.0k]
  ------------------
 2025|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2026|  15.0k|	newdf->path = *path;
 2027|  15.0k|	newdf->type = type;
 2028|       |
 2029|  15.0k|	if (p15card->df_list == NULL) {
  ------------------
  |  Branch (2029:6): [True: 5.20k, False: 9.85k]
  ------------------
 2030|  5.20k|		p15card->df_list = newdf;
 2031|  5.20k|		return 0;
 2032|  5.20k|	}
 2033|       |
 2034|  9.85k|	p = p15card->df_list;
 2035|   316k|	while (p->next != NULL)
  ------------------
  |  Branch (2035:9): [True: 306k, False: 9.85k]
  ------------------
 2036|   306k|		p = p->next;
 2037|  9.85k|	p->next = newdf;
 2038|  9.85k|	newdf->prev = p;
 2039|       |
 2040|  9.85k|	return 0;
 2041|  15.0k|}
sc_pkcs15_parse_df:
 2136|  1.53k|{
 2137|  1.53k|	struct sc_context *ctx = p15card->card->ctx;
 2138|  1.53k|	unsigned char *buf;
 2139|  1.53k|	const unsigned char *p;
 2140|  1.53k|	size_t bufsize;
 2141|  1.53k|	int r;
 2142|  1.53k|	struct sc_pkcs15_object *obj = NULL;
 2143|  1.53k|	int (* func)(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
 2144|  1.53k|		     const u8 **nbuf, size_t *nbufsize) = NULL;
 2145|       |
 2146|  1.53k|	sc_log(ctx, "called; path=%s, type=%d, enum=%d", sc_print_path(&df->path), df->type, df->enumerated);
  ------------------
  |  |   71|  1.53k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
 2147|       |
 2148|  1.53k|	if (df->enumerated)
  ------------------
  |  Branch (2148:6): [True: 0, False: 1.53k]
  ------------------
 2149|  1.53k|		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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2150|       |
 2151|  1.53k|	switch (df->type) {
  ------------------
  |  Branch (2151:10): [True: 1.53k, False: 0]
  ------------------
 2152|     84|	case SC_PKCS15_PRKDF:
  ------------------
  |  |  488|     84|#define SC_PKCS15_PRKDF			0
  ------------------
  |  Branch (2152:2): [True: 84, False: 1.45k]
  ------------------
 2153|     84|		func = sc_pkcs15_decode_prkdf_entry;
 2154|     84|		break;
 2155|  1.09k|	case SC_PKCS15_PUKDF:
  ------------------
  |  |  489|  1.09k|#define SC_PKCS15_PUKDF			1
  ------------------
  |  Branch (2155:2): [True: 1.09k, False: 443]
  ------------------
 2156|  1.09k|		func = sc_pkcs15_decode_pukdf_entry;
 2157|  1.09k|		break;
 2158|      0|	case SC_PKCS15_SKDF:
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
  |  Branch (2158:2): [True: 0, False: 1.53k]
  ------------------
 2159|      0|		func = sc_pkcs15_decode_skdf_entry;
 2160|      0|		break;
 2161|    324|	case SC_PKCS15_CDF:
  ------------------
  |  |  492|    324|#define SC_PKCS15_CDF			4
  ------------------
  |  Branch (2161:2): [True: 324, False: 1.21k]
  ------------------
 2162|    324|	case SC_PKCS15_CDF_TRUSTED:
  ------------------
  |  |  493|    324|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
  |  Branch (2162:2): [True: 0, False: 1.53k]
  ------------------
 2163|    324|	case SC_PKCS15_CDF_USEFUL:
  ------------------
  |  |  494|    324|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
  |  Branch (2163:2): [True: 0, False: 1.53k]
  ------------------
 2164|    324|		func = sc_pkcs15_decode_cdf_entry;
 2165|    324|		break;
 2166|      0|	case SC_PKCS15_DODF:
  ------------------
  |  |  495|      0|#define SC_PKCS15_DODF			7
  ------------------
  |  Branch (2166:2): [True: 0, False: 1.53k]
  ------------------
 2167|      0|		func = sc_pkcs15_decode_dodf_entry;
 2168|      0|		break;
 2169|     35|	case SC_PKCS15_AODF:
  ------------------
  |  |  496|     35|#define SC_PKCS15_AODF			8
  ------------------
  |  Branch (2169:2): [True: 35, False: 1.50k]
  ------------------
 2170|     35|		func = sc_pkcs15_decode_aodf_entry;
 2171|     35|		break;
 2172|  1.53k|	}
 2173|  1.53k|	if (func == NULL) {
  ------------------
  |  Branch (2173:6): [True: 0, False: 1.53k]
  ------------------
 2174|      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__
  |  |  ------------------
  ------------------
 2175|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2176|      0|	}
 2177|  1.53k|	r = sc_pkcs15_read_file(p15card, &df->path, &buf, &bufsize, 0);
 2178|  1.53k|	LOG_TEST_RET(ctx, r, "pkcs15 read file failed");
  ------------------
  |  |  174|  1.53k|#define LOG_TEST_RET(ctx, r, text) SC_TEST_RET((ctx), SC_LOG_DEBUG_NORMAL, (r), (text))
  |  |  ------------------
  |  |  |  |  166|  1.53k|#define SC_TEST_RET(ctx, level, r, text) do { \
  |  |  |  |  167|  1.53k|	int _ret = (r); \
  |  |  |  |  168|  1.53k|	if (_ret < 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (168:6): [True: 1.15k, False: 379]
  |  |  |  |  ------------------
  |  |  |  |  169|  1.15k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __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.15k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  170|  1.15k|			"%s: %d (%s)\n", (text), _ret, sc_strerror(_ret)); \
  |  |  |  |  171|  1.15k|		return _ret; \
  |  |  |  |  172|  1.15k|	} \
  |  |  |  |  173|  1.53k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 379]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2179|       |
 2180|    379|	p = buf;
 2181|    379|	while (bufsize && *p != 0x00) {
  ------------------
  |  Branch (2181:9): [True: 341, False: 38]
  |  Branch (2181:20): [True: 318, False: 23]
  ------------------
 2182|       |
 2183|    318|		obj = calloc(1, sizeof(struct sc_pkcs15_object));
 2184|    318|		if (obj == NULL) {
  ------------------
  |  Branch (2184:7): [True: 0, False: 318]
  ------------------
 2185|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2186|      0|			goto ret;
 2187|      0|		}
 2188|    318|		r = func(p15card, obj, &p, &bufsize);
 2189|    318|		if (r) {
  ------------------
  |  Branch (2189:7): [True: 318, False: 0]
  ------------------
 2190|    318|			free(obj);
 2191|    318|			if (r == SC_ERROR_ASN1_END_OF_CONTENTS) {
  ------------------
  |  |   84|    318|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (2191:8): [True: 103, False: 215]
  ------------------
 2192|    103|				r = 0;
 2193|    103|				break;
 2194|    103|			}
 2195|    215|			sc_log(ctx, "%s: Error decoding DF entry", sc_strerror(r));
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2196|    215|			goto ret;
 2197|    318|		}
 2198|       |
 2199|      0|		obj->df = df;
 2200|      0|		r = sc_pkcs15_add_object(p15card, obj);
 2201|      0|		if (r) {
  ------------------
  |  Branch (2201:7): [True: 0, False: 0]
  ------------------
 2202|      0|			if (obj->data)
  ------------------
  |  Branch (2202:8): [True: 0, False: 0]
  ------------------
 2203|      0|				free(obj->data);
 2204|      0|			free(obj);
 2205|      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__
  |  |  ------------------
  ------------------
 2206|      0|			goto ret;
 2207|      0|		}
 2208|      0|		while (bufsize > 0 && *p == 00) {
  ------------------
  |  Branch (2208:10): [True: 0, False: 0]
  |  Branch (2208:25): [True: 0, False: 0]
  ------------------
 2209|      0|			bufsize--;
 2210|      0|			p++;
 2211|      0|		}
 2212|    164|	};
 2213|       |
 2214|    164|	if (r > 0)
  ------------------
  |  Branch (2214:6): [True: 0, False: 164]
  ------------------
 2215|      0|		r = 0;
 2216|    379|ret:
 2217|    379|	df->enumerated = 1;
 2218|    379|	free(buf);
 2219|    379|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|    379|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    379|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    379|	int _ret = r; \
  |  |  |  |  155|    379|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 379, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    379|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_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: 164]
  |  |  |  |  ------------------
  |  |  |  |  157|    379|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    379|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    379|	return _ret; \
  |  |  |  |  163|    379|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2220|    379|}
sc_pkcs15_read_file:
 2472|  12.5k|{
 2473|  12.5k|	struct sc_context *ctx;
 2474|  12.5k|	struct sc_file *file = NULL;
 2475|  12.5k|	unsigned char *data = NULL;
 2476|  12.5k|	size_t	len = 0, offset = 0;
 2477|  12.5k|	int	r;
 2478|       |
 2479|  12.5k|	if (p15card == NULL || p15card->card == NULL || in_path == NULL || buf == NULL) {
  ------------------
  |  Branch (2479:6): [True: 0, False: 12.5k]
  |  Branch (2479:25): [True: 0, False: 12.5k]
  |  Branch (2479:50): [True: 0, False: 12.5k]
  |  Branch (2479:69): [True: 0, False: 12.5k]
  ------------------
 2480|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2481|      0|	}
 2482|  12.5k|	ctx = p15card->card->ctx;
 2483|       |
 2484|  12.5k|	LOG_FUNC_CALLED(ctx);
  ------------------
  |  |  151|  12.5k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  12.5k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  12.5k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  12.5k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 12.5k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2485|  12.5k|	sc_log(ctx, "path=%s, index=%u, count=%d", sc_print_path(in_path), in_path->index, in_path->count);
  ------------------
  |  |   71|  12.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__
  |  |  ------------------
  ------------------
 2486|       |
 2487|  12.5k|	r = -1; /* file state: not in cache */
 2488|  12.5k|	if (p15card->opts.use_file_cache
  ------------------
  |  Branch (2488:6): [True: 5.80k, False: 6.76k]
  ------------------
 2489|  5.80k|	    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|  5.80k|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2489:10): [True: 0, False: 5.80k]
  |  Branch (2489:77): [True: 5.80k, False: 0]
  ------------------
 2490|  5.80k|		r = sc_pkcs15_read_cached_file(p15card, in_path, &data, &len);
 2491|       |
 2492|  5.80k|		if (!r && in_path->aid.len > 0 && in_path->len >= 2)   {
  ------------------
  |  Branch (2492:7): [True: 500, False: 5.30k]
  |  Branch (2492:13): [True: 14, False: 486]
  |  Branch (2492:37): [True: 14, False: 0]
  ------------------
 2493|     14|			struct sc_path parent = *in_path;
 2494|       |
 2495|     14|			parent.len -= 2;
 2496|     14|			parent.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|     14|#define SC_PATH_TYPE_PATH		2
  ------------------
 2497|     14|			r = sc_select_file(p15card->card, &parent, NULL);
 2498|     14|		}
 2499|  5.80k|	}
 2500|       |
 2501|  12.5k|	if (r) {
  ------------------
  |  Branch (2501:6): [True: 12.0k, False: 492]
  ------------------
 2502|  12.0k|		r = sc_lock(p15card->card);
 2503|  12.0k|		if (r)
  ------------------
  |  Branch (2503:7): [True: 0, False: 12.0k]
  ------------------
 2504|      0|			goto fail;
 2505|  12.0k|		r = sc_select_file(p15card->card, in_path, &file);
 2506|  12.0k|		if (r)
  ------------------
  |  Branch (2506:7): [True: 8.78k, False: 3.28k]
  ------------------
 2507|  8.78k|			goto fail_unlock;
 2508|       |
 2509|       |		/* Handle the case where the ASN.1 Path object specified
 2510|       |		 * index and length values */
 2511|       |
 2512|  3.28k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  3.28k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2512:7): [True: 110, False: 3.17k]
  ------------------
 2513|       |
 2514|       |			// in_path->index: record_no
 2515|       |			// in_path->count: ignored!
 2516|       |
 2517|    110|			if(file->record_length > 0) {
  ------------------
  |  Branch (2517:7): [True: 89, False: 21]
  ------------------
 2518|     89|				if(file->record_length > MAX_FILE_SIZE) {
  ------------------
  |  |  229|     89|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2518:8): [True: 0, False: 89]
  ------------------
 2519|      0|					len = MAX_FILE_SIZE;
  ------------------
  |  |  229|      0|#define MAX_FILE_SIZE 65535
  ------------------
 2520|      0|					sc_log(ctx, "  record size truncated, encoded length: %"SC_FORMAT_LEN_SIZE_T"u", 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__
  |  |  ------------------
  ------------------
 2521|     89|				} else {
 2522|     89|					len = file->record_length;
 2523|     89|				}
 2524|     89|			} else {
 2525|     21|				len = MAX_FILE_SIZE;
  ------------------
  |  |  229|     21|#define MAX_FILE_SIZE 65535
  ------------------
 2526|     21|			}
 2527|       |
 2528|    110|			if ((in_path->index <= 0) || (in_path->index > (int)(file->record_count))) {
  ------------------
  |  Branch (2528:8): [True: 74, False: 36]
  |  Branch (2528:33): [True: 1, False: 35]
  ------------------
 2529|     75|				sc_log(ctx, "  record number out of bounds: %d", in_path->index);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2530|     75|				r = SC_ERROR_RECORD_NOT_FOUND;
  ------------------
  |  |   52|     75|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
 2531|     75|				goto fail_unlock;
 2532|     75|			}
 2533|       |
 2534|  3.17k|		} else {
 2535|       |
 2536|  3.17k|			if (in_path->count < 0) {
  ------------------
  |  Branch (2536:8): [True: 1.82k, False: 1.35k]
  ------------------
 2537|  1.82k|				if (file->size)
  ------------------
  |  Branch (2537:9): [True: 1.64k, False: 183]
  ------------------
 2538|  1.64k|					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  229|  1.64k|#define MAX_FILE_SIZE 65535
  ------------------
              					len = (file->size > MAX_FILE_SIZE)? MAX_FILE_SIZE:file->size;
  ------------------
  |  |  229|      0|#define MAX_FILE_SIZE 65535
  ------------------
  |  Branch (2538:12): [True: 0, False: 1.64k]
  ------------------
 2539|    183|				else
 2540|    183|					len = 1024;
 2541|  1.82k|				offset = 0;
 2542|  1.82k|			}
 2543|  1.35k|			else {
 2544|  1.35k|				offset = in_path->index;
 2545|  1.35k|				len = in_path->count;
 2546|       |				/* Make sure we're within proper bounds */
 2547|  1.35k|				if (offset >= file->size || offset + len > file->size) {
  ------------------
  |  Branch (2547:9): [True: 24, False: 1.32k]
  |  Branch (2547:33): [True: 8, False: 1.31k]
  ------------------
 2548|     32|					r = SC_ERROR_INVALID_ASN1_OBJECT;
  ------------------
  |  |   82|     32|#define SC_ERROR_INVALID_ASN1_OBJECT		-1401
  ------------------
 2549|     32|					goto fail_unlock;
 2550|     32|				}
 2551|  1.35k|			}
 2552|  3.17k|		}
 2553|       |
 2554|  3.18k|		free(data);
 2555|  3.18k|		data = malloc(len);
 2556|  3.18k|		if (data == NULL) {
  ------------------
  |  Branch (2556:7): [True: 0, False: 3.18k]
  ------------------
 2557|      0|			r = SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2558|      0|			goto fail_unlock;
 2559|      0|		}
 2560|       |
 2561|  3.18k|		if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE_TLV) {
  ------------------
  |  |  225|  3.18k|#define SC_FILE_EF_LINEAR_VARIABLE_TLV	0x05
  ------------------
  |  Branch (2561:7): [True: 52, False: 3.12k]
  ------------------
 2562|     52|			unsigned int i;
 2563|     52|			size_t l, record_len;
 2564|     52|			unsigned char *head = data;
 2565|       |
 2566|    998|			for (i=1; ; i++) {
 2567|    998|				l = len - (head - data);
 2568|    998|				if (l > 256) {
  ------------------
  |  Branch (2568:9): [True: 761, False: 237]
  ------------------
 2569|    761|					l = 256;
 2570|    761|				}
 2571|    998|				r = sc_read_record(p15card->card, i, 0, head, l, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1306|    998|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2572|    998|				if (r == SC_ERROR_RECORD_NOT_FOUND)
  ------------------
  |  |   52|    998|#define SC_ERROR_RECORD_NOT_FOUND		-1202
  ------------------
  |  Branch (2572:9): [True: 1, False: 997]
  ------------------
 2573|      1|					break;
 2574|    997|				if (r < 0) {
  ------------------
  |  Branch (2574:9): [True: 46, False: 951]
  ------------------
 2575|     46|					goto fail_unlock;
 2576|     46|				}
 2577|    951|				if (r < 2)
  ------------------
  |  Branch (2577:9): [True: 4, False: 947]
  ------------------
 2578|      4|					break;
 2579|    947|				record_len = head[1];
 2580|    947|				if (record_len != 0xff) {
  ------------------
  |  Branch (2580:9): [True: 854, False: 93]
  ------------------
 2581|    854|					memmove(head, head+2, r-2);
 2582|    854|					head += (r-2);
 2583|    854|				}
 2584|     93|				else {
 2585|     93|					if (r < 4)
  ------------------
  |  Branch (2585:10): [True: 1, False: 92]
  ------------------
 2586|      1|						break;
 2587|     92|					memmove(head, head+4, r-4);
 2588|     92|					head += (r-4);
 2589|     92|				}
 2590|    947|			}
 2591|      6|			len = head-data;
 2592|      6|		}
 2593|  3.12k|		else if (file->ef_structure == SC_FILE_EF_LINEAR_VARIABLE) {
  ------------------
  |  |  224|  3.12k|#define SC_FILE_EF_LINEAR_VARIABLE	0x04
  ------------------
  |  Branch (2593:12): [True: 35, False: 3.09k]
  ------------------
 2594|     35|			r = sc_read_record(p15card->card, in_path->index, (unsigned)offset, data, len, SC_RECORD_BY_REC_NR);
  ------------------
  |  | 1306|     35|#define SC_RECORD_BY_REC_NR		0x00100UL
  ------------------
 2595|     35|			if (r < 0) {
  ------------------
  |  Branch (2595:8): [True: 7, False: 28]
  ------------------
 2596|      7|				goto fail_unlock;
 2597|      7|			}
 2598|       |			/* sc_read_record may return less than requested */
 2599|     28|			len = r;
 2600|     28|		}
 2601|  3.09k|		else {
 2602|  3.09k|			unsigned long flags = 0;
 2603|  3.09k|			r = sc_read_binary(p15card->card, (unsigned)offset, data, len, &flags);
 2604|  3.09k|			if (r < 0) {
  ------------------
  |  Branch (2604:8): [True: 740, False: 2.35k]
  ------------------
 2605|    740|				goto fail_unlock;
 2606|    740|			}
 2607|       |			/* sc_read_binary may return less than requested */
 2608|  2.35k|			len = r;
 2609|       |
 2610|  2.35k|			if (flags & SC_FILE_FLAG_COMPRESSED_AUTO
  ------------------
  |  |  230|  4.70k|#define SC_FILE_FLAG_COMPRESSED_AUTO		0x01
  ------------------
  |  Branch (2610:8): [True: 339, False: 2.01k]
  ------------------
 2611|  2.01k|			    || flags & SC_FILE_FLAG_COMPRESSED_ZLIB
  ------------------
  |  |  231|  4.36k|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2611:11): [True: 0, False: 2.01k]
  ------------------
 2612|  2.01k|			    || flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|  2.01k|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2612:11): [True: 0, False: 2.01k]
  ------------------
 2613|    339|				unsigned char *decompressed_buf = NULL;
 2614|    339|				size_t decompressed_len = 0;
 2615|    339|				r = decompress_file(p15card->card, data, len, &decompressed_buf, &decompressed_len, flags);
 2616|    339|				if (r != SC_SUCCESS) {
  ------------------
  |  |   28|    339|#define SC_SUCCESS				0
  ------------------
  |  Branch (2616:9): [True: 204, False: 135]
  ------------------
 2617|    204|					goto fail_unlock;
 2618|    204|				}
 2619|    135|				free(data);
 2620|    135|				data = decompressed_buf;
 2621|    135|				len = decompressed_len;
 2622|    135|			}
 2623|  2.35k|		}
 2624|  2.18k|		sc_unlock(p15card->card);
 2625|       |
 2626|  2.18k|		sc_file_free(file);
 2627|       |
 2628|  2.18k|		if (len && p15card->opts.use_file_cache
  ------------------
  |  Branch (2628:7): [True: 1.90k, False: 281]
  |  Branch (2628:14): [True: 419, False: 1.48k]
  ------------------
 2629|    419|		    && ((p15card->opts.use_file_cache & SC_PKCS15_OPTS_CACHE_ALL_FILES) || !private_data)) {
  ------------------
  |  |  606|    419|#define SC_PKCS15_OPTS_CACHE_ALL_FILES			2
  ------------------
  |  Branch (2629:11): [True: 0, False: 419]
  |  Branch (2629:78): [True: 419, False: 0]
  ------------------
 2630|    419|			sc_pkcs15_cache_file(p15card, in_path, data, len);
 2631|    419|		}
 2632|  2.18k|		if (len == 0) {
  ------------------
  |  Branch (2632:7): [True: 281, False: 1.90k]
  ------------------
 2633|    281|			free(data);
 2634|    281|			data = NULL;
 2635|    281|		}
 2636|  2.18k|	}
 2637|  2.67k|	*buf = data;
 2638|  2.67k|	*buflen = len;
 2639|  2.67k|	LOG_FUNC_RETURN(ctx, SC_SUCCESS);
  ------------------
  |  |  164|  2.67k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  2.67k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  2.67k|	int _ret = r; \
  |  |  |  |  155|  2.67k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 2.67k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  2.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: 2.67k]
  |  |  |  |  ------------------
  |  |  |  |  157|  2.67k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  2.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|  2.67k|	return _ret; \
  |  |  |  |  163|  2.67k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2640|       |
 2641|  9.89k|fail_unlock:
 2642|  9.89k|	sc_unlock(p15card->card);
 2643|  9.89k|fail:
 2644|  9.89k|	free(data);
 2645|  9.89k|	sc_file_free(file);
 2646|  9.89k|	LOG_FUNC_RETURN(ctx, r);
  ------------------
  |  |  164|  9.89k|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|  9.89k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|  9.89k|	int _ret = r; \
  |  |  |  |  155|  9.89k|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 9.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|  9.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|  9.89k|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 9.89k, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|  9.89k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|  9.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|  9.89k|	return _ret; \
  |  |  |  |  163|  9.89k|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2647|  9.89k|}
sc_pkcs15_compare_id:
 2652|  7.87k|{
 2653|  7.87k|	if (id1 == NULL || id2 == NULL)
  ------------------
  |  Branch (2653:6): [True: 0, False: 7.87k]
  |  Branch (2653:21): [True: 0, False: 7.87k]
  ------------------
 2654|      0|		return 0;
 2655|  7.87k|	if (id1->len != id2->len)
  ------------------
  |  Branch (2655:6): [True: 3.65k, False: 4.22k]
  ------------------
 2656|  3.65k|		return 0;
 2657|  4.22k|	return memcmp(id1->value, id2->value, id1->len) == 0;
 2658|  7.87k|}
sc_pkcs15_format_id:
 2663|  82.1k|{
 2664|  82.1k|	size_t len;
 2665|       |
 2666|  82.1k|	if (!id)
  ------------------
  |  Branch (2666:6): [True: 0, False: 82.1k]
  ------------------
 2667|      0|		return;
 2668|  82.1k|	len = sizeof(id->value);
 2669|       |
 2670|  82.1k|	if (sc_hex_to_bin(str, id->value, &len) != SC_SUCCESS)
  ------------------
  |  |   28|  82.1k|#define SC_SUCCESS				0
  ------------------
  |  Branch (2670:6): [True: 0, False: 82.1k]
  ------------------
 2671|      0|		id->len = 0;
 2672|  82.1k|	else
 2673|  82.1k|		id->len = len;
 2674|  82.1k|}
sc_pkcs15_print_id:
 2679|    559|{
 2680|    559|	static char buffer[256];
 2681|       |
 2682|    559|	sc_bin_to_hex(id->value, id->len, buffer, sizeof(buffer), '\0');
 2683|    559|	return buffer;
 2684|    559|}
sc_pkcs15_make_absolute_path:
 2697|  16.8k|{
 2698|       |	/* nothing to do if child has valid 'aid' */
 2699|  16.8k|	if (child->aid.len)
  ------------------
  |  Branch (2699:6): [True: 0, False: 16.8k]
  ------------------
 2700|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2701|       |
 2702|  16.8k|	if (parent->aid.len)   {
  ------------------
  |  Branch (2702:6): [True: 0, False: 16.8k]
  ------------------
 2703|      0|		sc_path_t ppath;
 2704|       |
 2705|       |		/* child inherits parent's 'aid' */
 2706|      0|		child->aid = parent->aid;
 2707|      0|		if (!parent->len)
  ------------------
  |  Branch (2707:7): [True: 0, False: 0]
  ------------------
 2708|      0|			return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2709|       |
 2710|       |		/* parent has valid 'path' -- concatenate it with the child's one */
 2711|      0|		memcpy(&ppath, parent, sizeof(sc_path_t));
 2712|      0|		ppath.aid.len = 0;
 2713|      0|		ppath.type = SC_PATH_TYPE_FROM_CURRENT;
  ------------------
  |  |  122|      0|#define SC_PATH_TYPE_FROM_CURRENT	4
  ------------------
 2714|      0|		return sc_concatenate_path(child, &ppath, child);
 2715|       |
 2716|      0|	}
 2717|  16.8k|	else if (parent->type == SC_PATH_TYPE_DF_NAME)   {
  ------------------
  |  |  118|  16.8k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (2717:11): [True: 125, False: 16.6k]
  ------------------
 2718|       |		/* child inherits parent's 'DF NAME' as 'aid' */
 2719|    125|		if (parent->len > sizeof(child->aid.value))
  ------------------
  |  Branch (2719:7): [True: 0, False: 125]
  ------------------
 2720|      0|			return SC_ERROR_WRONG_LENGTH;
  ------------------
  |  |   56|      0|#define SC_ERROR_WRONG_LENGTH			-1206
  ------------------
 2721|       |
 2722|    125|		memcpy(child->aid.value, parent->value, parent->len);
 2723|    125|		child->aid.len = parent->len;
 2724|       |
 2725|    125|		return SC_SUCCESS;
  ------------------
  |  |   28|    125|#define SC_SUCCESS				0
  ------------------
 2726|    125|	}
 2727|       |
 2728|       |	/* a 0 length path stays a 0 length path */
 2729|  16.6k|	if (child->len == 0)
  ------------------
  |  Branch (2729:6): [True: 92, False: 16.5k]
  ------------------
 2730|     92|		return SC_SUCCESS;
  ------------------
  |  |   28|     92|#define SC_SUCCESS				0
  ------------------
 2731|       |
 2732|  16.5k|	if (sc_compare_path_prefix(sc_get_mf_path(), child))
  ------------------
  |  Branch (2732:6): [True: 63, False: 16.5k]
  ------------------
 2733|     63|		return SC_SUCCESS;
  ------------------
  |  |   28|     63|#define SC_SUCCESS				0
  ------------------
 2734|       |
 2735|  16.5k|	return sc_concatenate_path(child, parent, child);
 2736|  16.5k|}
sc_pkcs15_free_object_content:
 2740|  35.7k|{
 2741|  35.7k|	if (obj->content.value && obj->content.len) {
  ------------------
  |  Branch (2741:6): [True: 807, False: 34.9k]
  |  Branch (2741:28): [True: 807, False: 0]
  ------------------
 2742|    807|		if (obj->content_free) {
  ------------------
  |  Branch (2742:7): [True: 807, False: 0]
  ------------------
 2743|    807|			obj->content_free(obj->content.value, obj->content.len);
 2744|    807|		} else {
 2745|      0|			free(obj->content.value);
 2746|      0|		}
 2747|    807|	}
 2748|       |	obj->content.value = NULL;
 2749|  35.7k|	obj->content.len = 0;
 2750|  35.7k|}
sc_pkcs15_allocate_object_content:
 2756|    807|{
 2757|    807|	unsigned char *tmp_buf;
 2758|       |
 2759|    807|	if (!obj)
  ------------------
  |  Branch (2759:6): [True: 0, False: 807]
  ------------------
 2760|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 2761|       |
 2762|    807|	if (!value || !len)   {
  ------------------
  |  Branch (2762:6): [True: 0, False: 807]
  |  Branch (2762:16): [True: 0, False: 807]
  ------------------
 2763|      0|		sc_pkcs15_free_object_content(obj);
 2764|      0|		return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
 2765|      0|	}
 2766|       |
 2767|       |	/* Need to pass by temporary variable,
 2768|       |	 * because 'value' and 'content.value' pointers can be the sames.
 2769|       |	 */
 2770|    807|	if (SC_PKCS15_TYPE_AUTH & obj->type
  ------------------
  |  |  444|    807|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (2770:6): [True: 807, False: 0]
  ------------------
 2771|      0|			|| SC_PKCS15_TYPE_SKEY & obj->type
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (2771:7): [True: 0, False: 0]
  ------------------
 2772|    807|			|| SC_PKCS15_TYPE_PRKEY & obj->type) {
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (2772:7): [True: 0, False: 0]
  ------------------
 2773|    807|		tmp_buf = sc_mem_secure_alloc(len);
 2774|    807|		obj->content_free = sc_mem_secure_free;
 2775|    807|	} else {
 2776|      0|		tmp_buf = malloc(len);
 2777|      0|	}
 2778|    807|	if (!tmp_buf)
  ------------------
  |  Branch (2778:6): [True: 0, False: 807]
  ------------------
 2779|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
 2780|       |
 2781|    807|	memcpy(tmp_buf, value, len);
 2782|       |
 2783|    807|	sc_pkcs15_free_object_content(obj);
 2784|       |
 2785|    807|	obj->content.value = tmp_buf;
 2786|    807|	obj->content.len = len;
 2787|       |
 2788|    807|	return SC_SUCCESS;
  ------------------
  |  |   28|    807|#define SC_SUCCESS				0
  ------------------
 2789|    807|}
sc_pkcs15_free_key_params:
 3094|  5.94k|{
 3095|  5.94k|	if (!params)
  ------------------
  |  Branch (3095:6): [True: 0, False: 5.94k]
  ------------------
 3096|      0|		return;
 3097|  5.94k|	if (params->data && params->free_params)
  ------------------
  |  Branch (3097:6): [True: 0, False: 5.94k]
  |  Branch (3097:22): [True: 0, False: 0]
  ------------------
 3098|      0|		params->free_params(params->data);
 3099|  5.94k|	else if (params->data)
  ------------------
  |  Branch (3099:11): [True: 0, False: 5.94k]
  ------------------
 3100|      0|		free(params->data);
 3101|       |
 3102|       |	params->data = NULL;
 3103|  5.94k|}
pkcs15.c:sc_pkcs15_clear_tokeninfo:
  748|  22.0k|{
  749|  22.0k|	if (!tokeninfo)
  ------------------
  |  Branch (749:6): [True: 0, False: 22.0k]
  ------------------
  750|      0|		return;
  751|       |
  752|  22.0k|	free(tokeninfo->label);
  753|  22.0k|	tokeninfo->label = NULL;
  754|  22.0k|	free(tokeninfo->serial_number);
  755|  22.0k|	tokeninfo->serial_number = NULL;
  756|  22.0k|	free(tokeninfo->manufacturer_id);
  757|  22.0k|	tokeninfo->manufacturer_id = NULL;
  758|  22.0k|	free(tokeninfo->last_update.gtime);
  759|  22.0k|	tokeninfo->last_update.gtime = NULL;
  760|  22.0k|	free(tokeninfo->preferred_language);
  761|  22.0k|	tokeninfo->preferred_language = NULL;
  762|  22.0k|	free(tokeninfo->profile_indication.name);
  763|  22.0k|	tokeninfo->profile_indication.name = NULL;
  764|  22.0k|	if (tokeninfo->seInfo != NULL) {
  ------------------
  |  Branch (764:6): [True: 10, False: 22.0k]
  ------------------
  765|     10|		unsigned i;
  766|     13|		for (i = 0; i < tokeninfo->num_seInfo; i++)
  ------------------
  |  Branch (766:15): [True: 3, False: 10]
  ------------------
  767|      3|			free(tokeninfo->seInfo[i]);
  768|     10|		free(tokeninfo->seInfo);
  769|       |		tokeninfo->seInfo = NULL;
  770|     10|	}
  771|  22.0k|}
pkcs15.c:sc_dup_app_info:
  902|    462|{
  903|    462|	struct sc_app_info *out = calloc(1, sizeof(struct sc_app_info));
  904|       |
  905|    462|	if (!out)
  ------------------
  |  Branch (905:6): [True: 0, False: 462]
  ------------------
  906|      0|		return NULL;
  907|       |
  908|    462|	memcpy(out, info, sizeof(struct sc_app_info));
  909|       |
  910|    462|	if (info->label) {
  ------------------
  |  Branch (910:6): [True: 9, False: 453]
  ------------------
  911|      9|		out->label = strdup(info->label);
  912|      9|		if (!out->label) {
  ------------------
  |  Branch (912:7): [True: 0, False: 9]
  ------------------
  913|      0|			free(out);
  914|      0|			return NULL;
  915|      0|		}
  916|      9|	} else
  917|    453|		out->label = NULL;
  918|       |
  919|    462|	out->ddo.value = malloc(info->ddo.len);
  920|    462|	if (!out->ddo.value) {
  ------------------
  |  Branch (920:6): [True: 0, False: 462]
  ------------------
  921|      0|		free(out->label);
  922|      0|		free(out);
  923|      0|		return NULL;
  924|      0|	}
  925|    462|	memcpy(out->ddo.value, info->ddo.value, info->ddo.len);
  926|    462|	out->ddo.len = info->ddo.len;
  927|       |
  928|    462|	return out;
  929|    462|}
pkcs15.c:parse_ddo:
  467|     48|{
  468|     48|	struct sc_context *ctx = p15card->card->ctx;
  469|     48|	struct sc_asn1_entry asn1_ddo[7];
  470|     48|	sc_path_t odf_path, ti_path, us_path;
  471|     48|	struct sc_iid iid;
  472|     48|	struct sc_aid aid;
  473|     48|	int r;
  474|       |
  475|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  476|       |
  477|     48|	iid.len = sizeof(iid.value);
  478|     48|	aid.len = sizeof(aid.value);
  479|       |
  480|     48|	sc_copy_asn1_entry(c_asn1_ddo, asn1_ddo);
  481|     48|	sc_format_asn1_entry(asn1_ddo + 1, &odf_path, NULL, 0);
  482|     48|	sc_format_asn1_entry(asn1_ddo + 2, &ti_path, NULL, 0);
  483|     48|	sc_format_asn1_entry(asn1_ddo + 3, &us_path, NULL, 0);
  484|     48|	sc_format_asn1_entry(asn1_ddo + 4, iid.value, &iid.len, 0);
  485|     48|	sc_format_asn1_entry(asn1_ddo + 5, aid.value, &aid.len, 0);
  486|       |
  487|     48|	r = sc_asn1_decode(ctx, asn1_ddo, buf, buflen, NULL, NULL);
  488|     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: 14, False: 34]
  |  |  |  |  ------------------
  |  |  |  |  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|     48|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (173:9): [Folded, False: 34]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  489|       |
  490|     34|	if (asn1_ddo[1].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     34|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (490:6): [True: 13, False: 21]
  ------------------
  491|     13|		sc_file_free(p15card->file_odf);
  492|     13|		p15card->file_odf = sc_file_new();
  493|     13|		if (p15card->file_odf == NULL)
  ------------------
  |  Branch (493:7): [True: 0, False: 13]
  ------------------
  494|      0|			goto mem_err;
  495|     13|		p15card->file_odf->path = odf_path;
  496|     13|	}
  497|     34|	if (asn1_ddo[2].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     34|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (497:6): [True: 2, False: 32]
  ------------------
  498|      2|		sc_file_free(p15card->file_tokeninfo);
  499|      2|		p15card->file_tokeninfo = sc_file_new();
  500|      2|		if (p15card->file_tokeninfo == NULL)
  ------------------
  |  Branch (500:7): [True: 0, False: 2]
  ------------------
  501|      0|			goto mem_err;
  502|      2|		p15card->file_tokeninfo->path = ti_path;
  503|      2|	}
  504|     34|	if (asn1_ddo[3].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     34|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (504:6): [True: 2, False: 32]
  ------------------
  505|      2|		sc_file_free(p15card->file_unusedspace);
  506|      2|		p15card->file_unusedspace = sc_file_new();
  507|      2|		if (p15card->file_unusedspace == NULL)
  ------------------
  |  Branch (507:7): [True: 0, False: 2]
  ------------------
  508|      0|			goto mem_err;
  509|      2|		p15card->file_unusedspace->path = us_path;
  510|      2|	}
  511|     34|	if (asn1_ddo[4].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     34|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (511:6): [True: 1, False: 33]
  ------------------
  512|      1|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.IID '%s'", sc_dump_hex(iid.value, iid.len));
  ------------------
  |  |   70|      1|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  513|      1|		memcpy(&p15card->app->ddo.iid, &iid, sizeof(struct sc_iid));
  514|      1|	}
  515|     34|	if (asn1_ddo[5].flags & SC_ASN1_PRESENT) {
  ------------------
  |  |  147|     34|#define SC_ASN1_PRESENT			0x00000001
  ------------------
  |  Branch (515:6): [True: 3, False: 31]
  ------------------
  516|      3|		sc_debug(ctx, SC_LOG_DEBUG_ASN1, "DDO.AID '%s'", sc_dump_hex(aid.value, aid.len));
  ------------------
  |  |   70|      3|#define sc_debug(ctx, level, format, args...)	sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  517|      3|		memcpy(&p15card->app->ddo.aid, &aid, sizeof(struct sc_aid));
  518|      3|	}
  519|       |
  520|     34|	fix_authentic_ddo(p15card);
  521|     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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  522|      0|mem_err:
  523|      0|	sc_file_free(p15card->file_odf);
  524|      0|	p15card->file_odf = NULL;
  525|      0|	sc_file_free(p15card->file_tokeninfo);
  526|      0|	p15card->file_tokeninfo = NULL;
  527|      0|	sc_file_free(p15card->file_unusedspace);
  528|      0|	p15card->file_unusedspace = NULL;
  529|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  530|      0|}
pkcs15.c:fix_authentic_ddo:
  453|     34|{
  454|       |	/* AuthentIC v3.2 card has invalid ODF and tokenInfo paths encoded into DDO.
  455|       |	 * Cleanup this attributes -- default values must be OK.
  456|       |	 */
  457|     34|	if (p15card->card->type == SC_CARD_TYPE_OBERTHUR_AUTHENTIC_3_2)   {
  ------------------
  |  Branch (457:6): [True: 0, False: 34]
  ------------------
  458|      0|		sc_file_free(p15card->file_odf);
  459|      0|		p15card->file_odf = NULL;
  460|      0|		sc_file_free(p15card->file_tokeninfo);
  461|       |		p15card->file_tokeninfo = NULL;
  462|      0|	}
  463|     34|}
pkcs15.c:parse_odf:
  615|    429|{
  616|    429|	const unsigned char *p = buf;
  617|    429|	size_t left = buflen;
  618|    429|	int r, i, type;
  619|    429|	struct sc_path path;
  620|    429|	struct sc_asn1_entry asn1_obj_or_path[] = {
  621|    429|		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  174|    429|#define SC_ASN1_PATH			256
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  141|    429|#define SC_ASN1_CONS			0x20000000
  ------------------
              		{ "path", SC_ASN1_PATH, SC_ASN1_CONS | SC_ASN1_SEQUENCE, 0, &path, NULL },
  ------------------
  |  |  162|    429|#define SC_ASN1_SEQUENCE                16
  ------------------
  622|    429|		{ NULL, 0, 0, 0, NULL, NULL }
  623|    429|	};
  624|    429|	struct sc_asn1_entry asn1_odf[10];
  625|       |
  626|    429|	sc_copy_asn1_entry(c_asn1_odf, asn1_odf);
  627|  4.29k|	for (i = 0; asn1_odf[i].name != NULL; i++)
  ------------------
  |  Branch (627:14): [True: 3.86k, False: 429]
  ------------------
  628|  3.86k|		sc_format_asn1_entry(asn1_odf + i, asn1_obj_or_path, NULL, 0);
  629|  3.65k|	while (left > 0) {
  ------------------
  |  Branch (629:9): [True: 3.61k, False: 40]
  ------------------
  630|  3.61k|		r = sc_asn1_decode_choice(p15card->card->ctx, asn1_odf, p, left, &p, &left);
  631|  3.61k|		if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
  ------------------
  |  |   84|  3.61k|#define SC_ERROR_ASN1_END_OF_CONTENTS		-1403
  ------------------
  |  Branch (631:7): [True: 205, False: 3.40k]
  ------------------
  632|    205|			break;
  633|  3.40k|		if (r < 0)
  ------------------
  |  Branch (633:7): [True: 184, False: 3.22k]
  ------------------
  634|    184|			return r;
  635|  3.22k|		type = r;
  636|  3.22k|		if (p15card->file_app) {
  ------------------
  |  Branch (636:7): [True: 3.22k, False: 0]
  ------------------
  637|  3.22k|			r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &path);
  638|  3.22k|			if (r < 0)
  ------------------
  |  Branch (638:8): [True: 0, False: 3.22k]
  ------------------
  639|      0|				return r;
  640|  3.22k|			r = sc_pkcs15_add_df(p15card, odf_indexes[type], &path);
  641|  3.22k|			if (r)
  ------------------
  |  Branch (641:8): [True: 0, False: 3.22k]
  ------------------
  642|      0|				return r;
  643|  3.22k|		}
  644|  3.22k|	}
  645|    245|	return 0;
  646|    429|}
pkcs15.c:__sc_pkcs15_search_objects:
 1402|  2.04k|{
 1403|  2.04k|	struct sc_pkcs15_object *obj = NULL;
 1404|  2.04k|	struct sc_pkcs15_df	*df = NULL;
 1405|  2.04k|	unsigned int	df_mask = 0;
 1406|  2.04k|	size_t		match_count = 0;
 1407|  2.04k|	int r;
 1408|       |
 1409|  2.04k|	if (type)
  ------------------
  |  Branch (1409:6): [True: 2.04k, False: 2]
  ------------------
 1410|  2.04k|		class_mask |= SC_PKCS15_TYPE_TO_CLASS(type);
  ------------------
  |  |  449|  2.04k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
 1411|       |
 1412|       |	/* Make sure the class mask we have makes sense */
 1413|  2.04k|	if (class_mask == 0
  ------------------
  |  Branch (1413:6): [True: 0, False: 2.04k]
  ------------------
 1414|  2.04k|			|| (class_mask & ~(
  ------------------
  |  Branch (1414:7): [True: 0, False: 2.04k]
  ------------------
 1415|  2.04k|					SC_PKCS15_SEARCH_CLASS_PRKEY |
  ------------------
  |  |  450|  2.04k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
 1416|  2.04k|					SC_PKCS15_SEARCH_CLASS_PUBKEY |
  ------------------
  |  |  451|  2.04k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
 1417|  2.04k|					SC_PKCS15_SEARCH_CLASS_SKEY |
  ------------------
  |  |  452|  2.04k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
 1418|  2.04k|					SC_PKCS15_SEARCH_CLASS_CERT |
  ------------------
  |  |  453|  2.04k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
 1419|  2.04k|					SC_PKCS15_SEARCH_CLASS_DATA |
  ------------------
  |  |  454|  2.04k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
 1420|  2.04k|					SC_PKCS15_SEARCH_CLASS_AUTH))) {
  ------------------
  |  |  455|  2.04k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
 1421|      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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1422|      0|	}
 1423|       |
 1424|  2.04k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PRKEY)
  ------------------
  |  |  450|  2.04k|#define SC_PKCS15_SEARCH_CLASS_PRKEY		0x0002U
  ------------------
  |  Branch (1424:6): [True: 1, False: 2.04k]
  ------------------
 1425|      1|		df_mask |= (1 << SC_PKCS15_PRKDF);
  ------------------
  |  |  488|      1|#define SC_PKCS15_PRKDF			0
  ------------------
 1426|  2.04k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_PUBKEY)
  ------------------
  |  |  451|  2.04k|#define SC_PKCS15_SEARCH_CLASS_PUBKEY		0x0004U
  ------------------
  |  Branch (1426:6): [True: 0, False: 2.04k]
  ------------------
 1427|      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
  ------------------
 1428|  2.04k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_CERT)
  ------------------
  |  |  453|  2.04k|#define SC_PKCS15_SEARCH_CLASS_CERT		0x0010U
  ------------------
  |  Branch (1428:6): [True: 1.10k, False: 938]
  ------------------
 1429|  1.10k|		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  492|  1.10k|#define SC_PKCS15_CDF			4
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  493|  1.10k|#define SC_PKCS15_CDF_TRUSTED		5
  ------------------
              		df_mask |= (1 << SC_PKCS15_CDF) | (1 << SC_PKCS15_CDF_TRUSTED) | (1 << SC_PKCS15_CDF_USEFUL);
  ------------------
  |  |  494|  1.10k|#define SC_PKCS15_CDF_USEFUL		6
  ------------------
 1430|  2.04k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_DATA)
  ------------------
  |  |  454|  2.04k|#define SC_PKCS15_SEARCH_CLASS_DATA		0x0020U
  ------------------
  |  Branch (1430:6): [True: 156, False: 1.88k]
  ------------------
 1431|    156|		df_mask |= (1 << SC_PKCS15_DODF);
  ------------------
  |  |  495|    156|#define SC_PKCS15_DODF			7
  ------------------
 1432|  2.04k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_AUTH)
  ------------------
  |  |  455|  2.04k|#define SC_PKCS15_SEARCH_CLASS_AUTH		0x0040U
  ------------------
  |  Branch (1432:6): [True: 781, False: 1.26k]
  ------------------
 1433|    781|		df_mask |= (1 << SC_PKCS15_AODF);
  ------------------
  |  |  496|    781|#define SC_PKCS15_AODF			8
  ------------------
 1434|  2.04k|	if (class_mask & SC_PKCS15_SEARCH_CLASS_SKEY)
  ------------------
  |  |  452|  2.04k|#define SC_PKCS15_SEARCH_CLASS_SKEY		0x0008U
  ------------------
  |  Branch (1434:6): [True: 0, False: 2.04k]
  ------------------
 1435|      0|		df_mask |= (1 << SC_PKCS15_SKDF);
  ------------------
  |  |  491|      0|#define SC_PKCS15_SKDF			3
  ------------------
 1436|       |
 1437|       |	/* Make sure all the DFs we want to search have been
 1438|       |	 * enumerated. */
 1439|  7.62k|	for (df = p15card->df_list; df != NULL; df = df->next) {
  ------------------
  |  Branch (1439:30): [True: 5.57k, False: 2.04k]
  ------------------
 1440|  5.57k|		if (!(df_mask & (1 << df->type)))   {
  ------------------
  |  Branch (1440:7): [True: 3.95k, False: 1.62k]
  ------------------
 1441|  3.95k|			continue;
 1442|  3.95k|		}
 1443|  1.62k|		if (df->enumerated)
  ------------------
  |  Branch (1443:7): [True: 1.62k, False: 0]
  ------------------
 1444|  1.62k|			continue;
 1445|       |		/* Enumerate the DF's, so p15card->obj_list is populated. */
 1446|      0|		if (p15card->ops.parse_df)
  ------------------
  |  Branch (1446:7): [True: 0, False: 0]
  ------------------
 1447|      0|			r = p15card->ops.parse_df(p15card, df);
 1448|      0|		else
 1449|      0|			r = sc_pkcs15_parse_df(p15card, df);
 1450|      0|		if (r != SC_SUCCESS)
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  |  Branch (1450:7): [True: 0, False: 0]
  ------------------
 1451|      0|			continue;
 1452|      0|	}
 1453|       |
 1454|       |	/* And now loop over all objects */
 1455|  13.5k|	for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (1455:32): [True: 12.5k, False: 947]
  ------------------
 1456|       |		/* Check object type */
 1457|  12.5k|		if (!(class_mask & SC_PKCS15_TYPE_TO_CLASS(obj->type)))
  ------------------
  |  |  449|  12.5k|#define SC_PKCS15_TYPE_TO_CLASS(t)		(1 << ((t) >> 8))
  ------------------
  |  Branch (1457:7): [True: 8.21k, False: 4.37k]
  ------------------
 1458|  8.21k|			continue;
 1459|  4.37k|		if (type != 0
  ------------------
  |  Branch (1459:7): [True: 4.37k, False: 0]
  ------------------
 1460|  4.37k|		 && obj->type != type
  ------------------
  |  Branch (1460:7): [True: 2.55k, False: 1.81k]
  ------------------
 1461|  2.55k|		 && (obj->type & SC_PKCS15_TYPE_CLASS_MASK) != type)
  ------------------
  |  |  416|  2.55k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1461:7): [True: 0, False: 2.55k]
  ------------------
 1462|      0|			continue;
 1463|       |
 1464|       |		/* Potential candidate, apply search function */
 1465|  4.37k|		if (func != NULL && func(obj, func_arg) <= 0)
  ------------------
  |  Branch (1465:7): [True: 2.55k, False: 1.81k]
  |  Branch (1465:23): [True: 1.45k, False: 1.09k]
  ------------------
 1466|  1.45k|			continue;
 1467|       |		/* Okay, we have a match. */
 1468|  2.91k|		match_count++;
 1469|  2.91k|		if (!ret || ret_size <= 0)
  ------------------
  |  Branch (1469:7): [True: 0, False: 2.91k]
  |  Branch (1469:15): [True: 0, False: 2.91k]
  ------------------
 1470|      0|			continue;
 1471|  2.91k|		ret[match_count-1] = obj;
 1472|  2.91k|		if (ret_size <= match_count)
  ------------------
  |  Branch (1472:7): [True: 1.09k, False: 1.81k]
  ------------------
 1473|  1.09k|			break;
 1474|  2.91k|	}
 1475|       |
 1476|  2.04k|	return (int)match_count;
 1477|  2.04k|}
pkcs15.c:compare_obj_key:
 1622|  2.55k|{
 1623|  2.55k|	struct sc_pkcs15_search_key *sk = (struct sc_pkcs15_search_key *) arg;
 1624|       |
 1625|  2.55k|	if (sk->id && !compare_obj_id(obj, sk->id))
  ------------------
  |  Branch (1625:6): [True: 2.55k, False: 0]
  |  Branch (1625:16): [True: 1.45k, False: 1.09k]
  ------------------
 1626|  1.45k|		return 0;
 1627|  1.09k|	if (sk->app_oid && !sc_obj_app_oid(obj, sk->app_oid))
  ------------------
  |  Branch (1627:6): [True: 0, False: 1.09k]
  |  Branch (1627:21): [True: 0, False: 0]
  ------------------
 1628|      0|		return 0;
 1629|  1.09k|	if (sk->usage_mask && !compare_obj_usage(obj, sk->usage_mask, sk->usage_value))
  ------------------
  |  Branch (1629:6): [True: 0, False: 1.09k]
  |  Branch (1629:24): [True: 0, False: 0]
  ------------------
 1630|      0|		return 0;
 1631|  1.09k|	if (sk->flags_mask && !compare_obj_flags(obj, sk->flags_mask, sk->flags_value))
  ------------------
  |  Branch (1631:6): [True: 0, False: 1.09k]
  |  Branch (1631:24): [True: 0, False: 0]
  ------------------
 1632|      0|		return 0;
 1633|  1.09k|	if (sk->match_reference && !compare_obj_reference(obj, sk->reference))
  ------------------
  |  Branch (1633:6): [True: 0, False: 1.09k]
  |  Branch (1633:29): [True: 0, False: 0]
  ------------------
 1634|      0|		return 0;
 1635|  1.09k|	if (sk->path && !compare_obj_path(obj, sk->path))
  ------------------
  |  Branch (1635:6): [True: 0, False: 1.09k]
  |  Branch (1635:18): [True: 0, False: 0]
  ------------------
 1636|      0|		return 0;
 1637|  1.09k|	if (
 1638|  1.09k|		sk->app_label && sk->label &&
  ------------------
  |  Branch (1638:3): [True: 0, False: 1.09k]
  |  Branch (1638:20): [True: 0, False: 0]
  ------------------
 1639|      0|		!compare_obj_data_name(obj, sk->app_label, sk->label)
  ------------------
  |  Branch (1639:3): [True: 0, False: 0]
  ------------------
 1640|  1.09k|	) {
 1641|      0|		return 0;
 1642|      0|	}
 1643|       |
 1644|  1.09k|	return 1;
 1645|  1.09k|}
pkcs15.c:compare_obj_id:
 1490|  2.55k|{
 1491|  2.55k|	void *data = obj->data;
 1492|       |
 1493|  2.55k|	switch (obj->type & SC_PKCS15_TYPE_CLASS_MASK) {
  ------------------
  |  |  416|  2.55k|#define SC_PKCS15_TYPE_CLASS_MASK		0xF00
  ------------------
  |  Branch (1493:10): [True: 2.55k, False: 0]
  ------------------
 1494|  1.23k|	case SC_PKCS15_TYPE_CERT:
  ------------------
  |  |  438|  1.23k|#define SC_PKCS15_TYPE_CERT			0x400
  ------------------
  |  Branch (1494:2): [True: 1.23k, False: 1.31k]
  ------------------
 1495|  1.23k|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_cert_info *) data)->id, id);
 1496|      0|	case SC_PKCS15_TYPE_PRKEY:
  ------------------
  |  |  418|      0|#define SC_PKCS15_TYPE_PRKEY			0x100
  ------------------
  |  Branch (1496:2): [True: 0, False: 2.55k]
  ------------------
 1497|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_prkey_info *) data)->id, id);
 1498|      0|	case SC_PKCS15_TYPE_PUBKEY:
  ------------------
  |  |  425|      0|#define SC_PKCS15_TYPE_PUBKEY			0x200
  ------------------
  |  Branch (1498:2): [True: 0, False: 2.55k]
  ------------------
 1499|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_pubkey_info *) data)->id, id);
 1500|      0|	case SC_PKCS15_TYPE_SKEY:
  ------------------
  |  |  432|      0|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
  |  Branch (1500:2): [True: 0, False: 2.55k]
  ------------------
 1501|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_skey_info *) data)->id, id);
 1502|  1.31k|	case SC_PKCS15_TYPE_AUTH:
  ------------------
  |  |  444|  1.31k|#define SC_PKCS15_TYPE_AUTH			0x600
  ------------------
  |  Branch (1502:2): [True: 1.31k, False: 1.23k]
  ------------------
 1503|  1.31k|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_auth_info *) data)->auth_id, id);
 1504|      0|	case SC_PKCS15_TYPE_DATA_OBJECT:
  ------------------
  |  |  442|      0|#define SC_PKCS15_TYPE_DATA_OBJECT		0x500
  ------------------
  |  Branch (1504:2): [True: 0, False: 2.55k]
  ------------------
 1505|      0|		return sc_pkcs15_compare_id(&((struct sc_pkcs15_data_info *) data)->id, id);
 1506|  2.55k|	}
 1507|      0|	return 0;
 1508|  2.55k|}
pkcs15.c:sc_pkcs15_remove_objects:
 1965|  27.4k|{
 1966|  27.4k|	struct sc_pkcs15_object *cur = NULL, *next = NULL;
 1967|       |
 1968|  27.4k|	if (!p15card || !p15card->obj_list)
  ------------------
  |  Branch (1968:6): [True: 0, False: 27.4k]
  |  Branch (1968:18): [True: 22.3k, False: 5.08k]
  ------------------
 1969|  22.3k|		return;
 1970|  40.0k|	for (cur = p15card->obj_list; cur; cur = next)   {
  ------------------
  |  Branch (1970:32): [True: 34.9k, False: 5.08k]
  ------------------
 1971|  34.9k|		next = cur->next;
 1972|  34.9k|		sc_pkcs15_free_object(cur);
 1973|  34.9k|	}
 1974|       |
 1975|       |	p15card->obj_list = NULL;
 1976|  5.08k|}
pkcs15.c:sc_pkcs15_remove_dfs:
 2046|  27.4k|{
 2047|  27.4k|	struct sc_pkcs15_df *cur = NULL, *next = NULL;
 2048|       |
 2049|  27.4k|	if (!p15card || !p15card->df_list)
  ------------------
  |  Branch (2049:6): [True: 0, False: 27.4k]
  |  Branch (2049:18): [True: 22.2k, False: 5.20k]
  ------------------
 2050|  22.2k|		return;
 2051|       |
 2052|  20.2k|	for (cur = p15card->df_list; cur; cur = next)   {
  ------------------
  |  Branch (2052:31): [True: 15.0k, False: 5.20k]
  ------------------
 2053|  15.0k|		next = cur->next;
 2054|  15.0k|		free(cur);
 2055|  15.0k|	}
 2056|       |
 2057|       |	p15card->df_list = NULL;
 2058|  5.20k|}
pkcs15.c:sc_pkcs15_free_unusedspace:
 2281|  12.5k|{
 2282|  12.5k|	struct sc_pkcs15_unusedspace *cur = NULL, *next = NULL;
 2283|       |
 2284|  12.5k|	if (!p15card || !p15card->unusedspace_list)
  ------------------
  |  Branch (2284:6): [True: 0, False: 12.5k]
  |  Branch (2284:18): [True: 12.5k, False: 0]
  ------------------
 2285|  12.5k|		return;
 2286|      0|	for (cur = p15card->unusedspace_list; cur; cur = next)   {
  ------------------
  |  Branch (2286:40): [True: 0, False: 0]
  ------------------
 2287|      0|		next = cur->next;
 2288|      0|		free(cur);
 2289|      0|	}
 2290|       |
 2291|       |	p15card->unusedspace_list = NULL;
 2292|      0|}
pkcs15.c:decompress_file:
 2421|    339|{
 2422|    339|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|    339|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|    339|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|    339|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|    339|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 339]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2423|    339|#ifdef ENABLE_ZLIB
 2424|    339|	int rv = SC_SUCCESS;
  ------------------
  |  |   28|    339|#define SC_SUCCESS				0
  ------------------
 2425|    339|	int method = 0;
 2426|       |
 2427|    339|	if (flags & SC_FILE_FLAG_COMPRESSED_GZIP) {
  ------------------
  |  |  232|    339|#define SC_FILE_FLAG_COMPRESSED_GZIP		0x04
  ------------------
  |  Branch (2427:6): [True: 0, False: 339]
  ------------------
 2428|      0|		method = COMPRESSION_GZIP;
  ------------------
  |  |   28|      0|#define COMPRESSION_GZIP	2
  ------------------
 2429|    339|	} else if (flags & SC_FILE_FLAG_COMPRESSED_ZLIB) {
  ------------------
  |  |  231|    339|#define SC_FILE_FLAG_COMPRESSED_ZLIB		0x02
  ------------------
  |  Branch (2429:13): [True: 0, False: 339]
  ------------------
 2430|      0|		method = COMPRESSION_ZLIB;
  ------------------
  |  |   27|      0|#define COMPRESSION_ZLIB	1
  ------------------
 2431|    339|	} else {
 2432|    339|		method = COMPRESSION_AUTO;
  ------------------
  |  |   26|    339|#define COMPRESSION_AUTO	0
  ------------------
 2433|    339|	}
 2434|       |
 2435|    339|	rv = sc_decompress_alloc(out, outlen, buf, buflen, method);
 2436|    339|	if (rv != SC_SUCCESS) {
  ------------------
  |  |   28|    339|#define SC_SUCCESS				0
  ------------------
  |  Branch (2436:6): [True: 204, False: 135]
  ------------------
 2437|    204|		sc_log(card->ctx,  "Decompression failed: %d", rv);
  ------------------
  |  |   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__
  |  |  ------------------
  ------------------
 2438|    204|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_DATA);
  ------------------
  |  |  164|    204|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    204|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    204|	int _ret = r; \
  |  |  |  |  155|    204|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 204, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    204|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|    204|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 204, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  157|    204|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    204|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    204|	return _ret; \
  |  |  |  |  163|    204|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2439|    204|	}
 2440|    135|	LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
  ------------------
  |  |  164|    135|#define LOG_FUNC_RETURN(ctx, r) SC_FUNC_RETURN((ctx), SC_LOG_DEBUG_NORMAL, (r))
  |  |  ------------------
  |  |  |  |  153|    135|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  |  |  154|    135|	int _ret = r; \
  |  |  |  |  155|    135|	if (_ret <= 0) { \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (155:6): [True: 135, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  156|    135|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   44|      0|#define SC_COLOR_FG_RED			0x0001
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (156:65): [True: 0, False: 135]
  |  |  |  |  ------------------
  |  |  |  |  157|    135|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  |  |  158|    135|	} else { \
  |  |  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  |  |  161|      0|	} \
  |  |  |  |  162|    135|	return _ret; \
  |  |  |  |  163|    135|} while(0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 2441|       |#else
 2442|       |	sc_log(card->ctx, "Compression not supported, no zlib");
 2443|       |	LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
 2444|       |#endif
 2445|    135|}

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

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

sc_get_version:
   59|  15.3k|{
   60|  15.3k|    return sc_version;
   61|  15.3k|}
sc_hex_to_bin:
   64|   339k|{
   65|   339k|	const char *sc_hex_to_bin_separators = " :";
   66|   339k|	if (in == NULL || out == NULL || outlen == NULL) {
  ------------------
  |  Branch (66:6): [True: 0, False: 339k]
  |  Branch (66:20): [True: 0, False: 339k]
  |  Branch (66:35): [True: 0, False: 339k]
  ------------------
   67|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   68|      0|	}
   69|       |
   70|   339k|	int byte_needs_nibble = 0;
   71|   339k|	int r = SC_SUCCESS;
  ------------------
  |  |   28|   339k|#define SC_SUCCESS				0
  ------------------
   72|   339k|	size_t left = *outlen;
   73|   339k|	u8 byte = 0;
   74|  5.76M|	while (*in != '\0' && 0 != left) {
  ------------------
  |  Branch (74:9): [True: 5.42M, False: 339k]
  |  Branch (74:24): [True: 5.42M, False: 0]
  ------------------
   75|  5.42M|		char c = *in++;
   76|  5.42M|		u8 nibble;
   77|  5.42M|		if      ('0' <= c && c <= '9')
  ------------------
  |  Branch (77:12): [True: 5.42M, False: 0]
  |  Branch (77:24): [True: 2.89M, False: 2.52M]
  ------------------
   78|  2.89M|			nibble = c - '0';
   79|  2.52M|		else if ('a' <= c && c <= 'f')
  ------------------
  |  Branch (79:12): [True: 476k, False: 2.04M]
  |  Branch (79:24): [True: 476k, False: 0]
  ------------------
   80|   476k|			nibble = c - 'a' + 10;
   81|  2.04M|		else if ('A' <= c && c <= 'F')
  ------------------
  |  Branch (81:12): [True: 696k, False: 1.35M]
  |  Branch (81:24): [True: 696k, False: 0]
  ------------------
   82|   696k|			nibble = c - 'A' + 10;
   83|  1.35M|		else {
   84|  1.35M|			if (strchr(sc_hex_to_bin_separators, (int) c)) {
  ------------------
  |  Branch (84:8): [True: 1.35M, False: 0]
  ------------------
   85|  1.35M|				if (byte_needs_nibble) {
  ------------------
  |  Branch (85:9): [True: 0, False: 1.35M]
  ------------------
   86|      0|					r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   87|      0|					goto err;
   88|      0|				}
   89|  1.35M|				continue;
   90|  1.35M|			}
   91|      0|			r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   92|      0|			goto err;
   93|  1.35M|		}
   94|       |
   95|  4.07M|		if (byte_needs_nibble) {
  ------------------
  |  Branch (95:7): [True: 2.03M, False: 2.03M]
  ------------------
   96|  2.03M|			byte |= nibble;
   97|  2.03M|			*out++ = (u8) byte;
   98|  2.03M|			left--;
   99|  2.03M|			byte_needs_nibble = 0;
  100|  2.03M|		} else {
  101|  2.03M|			byte  = nibble << 4;
  102|  2.03M|			byte_needs_nibble = 1;
  103|  2.03M|		}
  104|  4.07M|	}
  105|       |
  106|   339k|	if (left == *outlen && 1 == byte_needs_nibble && 0 != left) {
  ------------------
  |  Branch (106:6): [True: 11.4k, False: 328k]
  |  Branch (106:25): [True: 6.92k, False: 4.51k]
  |  Branch (106:51): [True: 6.92k, False: 0]
  ------------------
  107|       |		/* no output written so far, but we have a valid nibble in the upper
  108|       |		 * bits. Allow this special case. */
  109|  6.92k|		*out = (u8) byte>>4;
  110|  6.92k|		left--;
  111|  6.92k|		byte_needs_nibble = 0;
  112|  6.92k|	}
  113|       |
  114|       |	/* for ease of implementation we only accept completely hexed bytes. */
  115|   339k|	if (byte_needs_nibble) {
  ------------------
  |  Branch (115:6): [True: 0, False: 339k]
  ------------------
  116|      0|		r = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  117|      0|		goto err;
  118|      0|	}
  119|       |
  120|       |	/* skip all trailing separators to see if we missed something */
  121|   339k|	while (*in != '\0') {
  ------------------
  |  Branch (121:9): [True: 0, False: 339k]
  ------------------
  122|      0|		if (NULL == strchr(sc_hex_to_bin_separators, (int) *in))
  ------------------
  |  Branch (122:7): [True: 0, False: 0]
  ------------------
  123|      0|			break;
  124|      0|		in++;
  125|      0|	}
  126|   339k|	if (*in != '\0') {
  ------------------
  |  Branch (126:6): [True: 0, False: 339k]
  ------------------
  127|      0|		r = SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  128|      0|		goto err;
  129|      0|	}
  130|       |
  131|   339k|err:
  132|   339k|	*outlen -= left;
  133|   339k|	return r;
  134|   339k|}
sc_bin_to_hex:
  138|   310k|{
  139|   310k|	if (in == NULL || out == NULL) {
  ------------------
  |  Branch (139:6): [True: 0, False: 310k]
  |  Branch (139:20): [True: 0, False: 310k]
  ------------------
  140|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  141|      0|	}
  142|       |
  143|   310k|	if (in_sep > 0) {
  ------------------
  |  Branch (143:6): [True: 306k, False: 3.98k]
  ------------------
  144|   306k|		if (out_len < in_len*3 || out_len < 1)
  ------------------
  |  Branch (144:7): [True: 0, False: 306k]
  |  Branch (144:29): [True: 0, False: 306k]
  ------------------
  145|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  146|   306k|	} else {
  147|  3.98k|		if (out_len < in_len*2 + 1)
  ------------------
  |  Branch (147:7): [True: 9, False: 3.98k]
  ------------------
  148|      9|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      9|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  149|  3.98k|	}
  150|       |
  151|   310k|	const char hex[] = "0123456789abcdef";
  152|  3.99M|	while (in_len) {
  ------------------
  |  Branch (152:9): [True: 3.68M, False: 310k]
  ------------------
  153|  3.68M|		unsigned char value = *in++;
  154|  3.68M|		*out++ = hex[(value >> 4) & 0xF];
  155|  3.68M|		*out++ = hex[ value       & 0xF];
  156|  3.68M|		in_len--;
  157|  3.68M|		if (in_len && in_sep > 0)
  ------------------
  |  Branch (157:7): [True: 3.44M, False: 231k]
  |  Branch (157:17): [True: 3.43M, False: 16.8k]
  ------------------
  158|  3.43M|			*out++ = (char)in_sep;
  159|  3.68M|	}
  160|   310k|	*out = '\0';
  161|       |
  162|   310k|	return SC_SUCCESS;
  ------------------
  |  |   28|   310k|#define SC_SUCCESS				0
  ------------------
  163|   310k|}
ulong2bebytes:
  189|  94.3k|{
  190|  94.3k|	if (buf != NULL) {
  ------------------
  |  Branch (190:6): [True: 94.3k, False: 0]
  ------------------
  191|  94.3k|		buf[3] = (u8) (x & 0xff);
  192|  94.3k|		buf[2] = (u8) ((x >> 8) & 0xff);
  193|  94.3k|		buf[1] = (u8) ((x >> 16) & 0xff);
  194|  94.3k|		buf[0] = (u8) ((x >> 24) & 0xff);
  195|  94.3k|	}
  196|  94.3k|	return buf;
  197|  94.3k|}
ushort2bebytes:
  200|    351|{
  201|    351|	if (buf != NULL) {
  ------------------
  |  Branch (201:6): [True: 351, False: 0]
  ------------------
  202|    351|		buf[1] = (u8) (x & 0xff);
  203|    351|		buf[0] = (u8) ((x >> 8) & 0xff);
  204|    351|	}
  205|    351|	return buf;
  206|    351|}
bebytes2ulong:
  209|   103k|{
  210|   103k|	if (buf == NULL)
  ------------------
  |  Branch (210:6): [True: 0, False: 103k]
  ------------------
  211|      0|		return 0UL;
  212|   103k|	return (unsigned long)buf[0] << 24
  213|   103k|		| (unsigned long)buf[1] << 16
  214|   103k|		| (unsigned long)buf[2] << 8
  215|   103k|		| (unsigned long)buf[3];
  216|   103k|}
bebytes2ushort:
  219|   104k|{
  220|   104k|	if (buf == NULL)
  ------------------
  |  Branch (220:6): [True: 0, False: 104k]
  ------------------
  221|      0|		return 0U;
  222|   104k|	return (unsigned short)buf[0] << 8
  223|   104k|		| (unsigned short)buf[1];
  224|   104k|}
lebytes2ushort:
  227|  5.40k|{
  228|  5.40k|	if (buf == NULL)
  ------------------
  |  Branch (228:6): [True: 0, False: 5.40k]
  ------------------
  229|      0|		return 0U;
  230|  5.40k|	return (unsigned short)buf[1] << 8
  231|  5.40k|		| (unsigned short)buf[0];
  232|  5.40k|}
lebytes2ulong:
  235|    810|{
  236|    810|	if (buf == NULL)
  ------------------
  |  Branch (236:6): [True: 0, False: 810]
  ------------------
  237|      0|		return 0UL;
  238|    810|	return (unsigned long)buf[3] << 24
  239|    810|		| (unsigned long)buf[2] << 16
  240|    810|		| (unsigned long)buf[1] << 8
  241|    810|		| (unsigned long)buf[0];
  242|    810|}
set_string:
  245|  14.3k|{
  246|  14.3k|	if (strp == NULL) {
  ------------------
  |  Branch (246:6): [True: 0, False: 14.3k]
  ------------------
  247|      0|		return;
  248|      0|	}
  249|       |
  250|  14.3k|	free(*strp);
  251|  14.3k|	*strp = value ? strdup(value) : NULL;
  ------------------
  |  Branch (251:10): [True: 14.3k, False: 0]
  ------------------
  252|  14.3k|}
sc_init_oid:
  255|  48.0k|{
  256|  48.0k|	int ii;
  257|       |
  258|  48.0k|	if (!oid)
  ------------------
  |  Branch (258:6): [True: 0, False: 48.0k]
  ------------------
  259|      0|		return;
  260|   817k|	for (ii=0; ii<SC_MAX_OBJECT_ID_OCTETS; ii++)
  ------------------
  |  |   46|   817k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (260:13): [True: 769k, False: 48.0k]
  ------------------
  261|   769k|		oid->value[ii] = -1;
  262|  48.0k|}
sc_format_oid:
  265|  18.7k|{
  266|  18.7k|	int        ii, ret = SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|  18.7k|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  267|  18.7k|	const char *p;
  268|  18.7k|	char       *q;
  269|       |
  270|  18.7k|	if (oid == NULL || in == NULL)
  ------------------
  |  Branch (270:6): [True: 0, False: 18.7k]
  |  Branch (270:21): [True: 0, False: 18.7k]
  ------------------
  271|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  272|       |
  273|  18.7k|	sc_init_oid(oid);
  274|       |
  275|  18.7k|	p = in;
  276|   174k|	for (ii=0; ii < SC_MAX_OBJECT_ID_OCTETS; ii++)   {
  ------------------
  |  |   46|   174k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (276:13): [True: 174k, False: 0]
  ------------------
  277|   174k|		oid->value[ii] = (int)strtol(p, &q, 10);
  278|   174k|		if (!*q)
  ------------------
  |  Branch (278:7): [True: 18.7k, False: 155k]
  ------------------
  279|  18.7k|			break;
  280|       |
  281|   155k|		if (!(q[0] == '.' && isdigit((unsigned char)q[1])))
  ------------------
  |  Branch (281:9): [True: 155k, False: 0]
  |  Branch (281:24): [True: 155k, False: 0]
  ------------------
  282|      0|			goto out;
  283|       |
  284|   155k|		p = q + 1;
  285|   155k|	}
  286|       |
  287|  18.7k|	if (!sc_valid_oid(oid))
  ------------------
  |  Branch (287:6): [True: 0, False: 18.7k]
  ------------------
  288|      0|		goto out;
  289|       |
  290|  18.7k|	ret = SC_SUCCESS;
  ------------------
  |  |   28|  18.7k|#define SC_SUCCESS				0
  ------------------
  291|  18.7k|out:
  292|  18.7k|	if (ret)
  ------------------
  |  Branch (292:6): [True: 0, False: 18.7k]
  ------------------
  293|      0|		sc_init_oid(oid);
  294|       |
  295|  18.7k|	return ret;
  296|  18.7k|}
sc_compare_oid:
  299|  63.9k|{
  300|  63.9k|	int i;
  301|       |
  302|  63.9k|	if (oid1 == NULL || oid2 == NULL) {
  ------------------
  |  Branch (302:6): [True: 0, False: 63.9k]
  |  Branch (302:22): [True: 0, False: 63.9k]
  ------------------
  303|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  304|      0|	}
  305|       |
  306|   161k|	for (i = 0; i < SC_MAX_OBJECT_ID_OCTETS; i++)   {
  ------------------
  |  |   46|   161k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (306:14): [True: 161k, False: 0]
  ------------------
  307|   161k|		if (oid1->value[i] != oid2->value[i])
  ------------------
  |  Branch (307:7): [True: 61.9k, False: 99.3k]
  ------------------
  308|  61.9k|			return 0;
  309|  99.3k|		if (oid1->value[i] == -1)
  ------------------
  |  Branch (309:7): [True: 2.01k, False: 97.3k]
  ------------------
  310|  2.01k|			break;
  311|  99.3k|	}
  312|       |
  313|  2.01k|	return 1;
  314|  63.9k|}
sc_valid_oid:
  318|  20.0k|{
  319|  20.0k|	int ii;
  320|       |
  321|  20.0k|	if (!oid)
  ------------------
  |  Branch (321:6): [True: 0, False: 20.0k]
  ------------------
  322|      0|		return 0;
  323|  20.0k|	if (oid->value[0] == -1 || oid->value[1] == -1)
  ------------------
  |  Branch (323:6): [True: 0, False: 20.0k]
  |  Branch (323:29): [True: 0, False: 20.0k]
  ------------------
  324|      0|		return 0;
  325|  20.0k|	if (oid->value[0] > 2 || oid->value[1] > 39)
  ------------------
  |  Branch (325:6): [True: 0, False: 20.0k]
  |  Branch (325:27): [True: 0, False: 20.0k]
  ------------------
  326|      0|		return 0;
  327|  20.0k|	for (ii=0;ii<SC_MAX_OBJECT_ID_OCTETS;ii++)
  ------------------
  |  |   46|  20.0k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (327:12): [True: 20.0k, False: 0]
  ------------------
  328|  20.0k|		if (oid->value[ii])
  ------------------
  |  Branch (328:7): [True: 20.0k, False: 0]
  ------------------
  329|  20.0k|			break;
  330|  20.0k|	if (ii==SC_MAX_OBJECT_ID_OCTETS)
  ------------------
  |  |   46|  20.0k|#define SC_MAX_OBJECT_ID_OCTETS		16
  ------------------
  |  Branch (330:6): [True: 0, False: 20.0k]
  ------------------
  331|      0|		return 0;
  332|  20.0k|	return 1;
  333|  20.0k|}
sc_path_set:
  355|  24.1k|{
  356|  24.1k|	if (path == NULL || id == NULL || id_len == 0 || id_len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  24.1k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (356:6): [True: 0, False: 24.1k]
  |  Branch (356:22): [True: 0, False: 24.1k]
  |  Branch (356:36): [True: 0, False: 24.1k]
  |  Branch (356:51): [True: 0, False: 24.1k]
  ------------------
  357|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  358|       |
  359|  24.1k|	memset(path, 0, sizeof(*path));
  360|  24.1k|	memcpy(path->value, id, id_len);
  361|  24.1k|	path->len   = id_len;
  362|  24.1k|	path->type  = type;
  363|  24.1k|	path->index = idx;
  364|  24.1k|	path->count = count;
  365|       |
  366|  24.1k|	return SC_SUCCESS;
  ------------------
  |  |   28|  24.1k|#define SC_SUCCESS				0
  ------------------
  367|  24.1k|}
sc_format_path:
  370|   154k|{
  371|   154k|	int type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|   154k|#define SC_PATH_TYPE_PATH		2
  ------------------
  372|       |
  373|   154k|	if (path) {
  ------------------
  |  Branch (373:6): [True: 154k, False: 0]
  ------------------
  374|   154k|		memset(path, 0, sizeof(*path));
  375|   154k|		if (*str == 'i' || *str == 'I') {
  ------------------
  |  Branch (375:7): [True: 0, False: 154k]
  |  Branch (375:22): [True: 0, False: 154k]
  ------------------
  376|      0|			type = SC_PATH_TYPE_FILE_ID;
  ------------------
  |  |  117|      0|#define SC_PATH_TYPE_FILE_ID		0
  ------------------
  377|      0|			str++;
  378|      0|		}
  379|   154k|		path->len = sizeof(path->value);
  380|   154k|		if (sc_hex_to_bin(str, path->value, &path->len) >= 0) {
  ------------------
  |  Branch (380:7): [True: 154k, False: 0]
  ------------------
  381|   154k|			path->type = type;
  382|   154k|		}
  383|   154k|		path->count = -1;
  384|   154k|	}
  385|   154k|}
sc_append_path_id:
  393|  45.6k|{
  394|  45.6k|	if (dest->len + idlen > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  45.6k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (394:6): [True: 1, False: 45.6k]
  ------------------
  395|      1|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      1|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  396|  45.6k|	memcpy(dest->value + dest->len, id, idlen);
  397|  45.6k|	dest->len += idlen;
  398|  45.6k|	return SC_SUCCESS;
  ------------------
  |  |   28|  45.6k|#define SC_SUCCESS				0
  ------------------
  399|  45.6k|}
sc_append_file_id:
  402|  45.5k|{
  403|  45.5k|	u8 id[2] = { fid >> 8, fid & 0xff };
  404|       |
  405|  45.5k|	return sc_append_path_id(dest, id, 2);
  406|  45.5k|}
sc_concatenate_path:
  409|  22.7k|{
  410|  22.7k|	sc_path_t tpath;
  411|       |
  412|  22.7k|	if (d == NULL || p1 == NULL || p2 == NULL)
  ------------------
  |  Branch (412:6): [True: 0, False: 22.7k]
  |  Branch (412:19): [True: 0, False: 22.7k]
  |  Branch (412:33): [True: 0, False: 22.7k]
  ------------------
  413|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  414|       |
  415|  22.7k|	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  45.5k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
              	if (p1->type == SC_PATH_TYPE_DF_NAME || p2->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|  22.7k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (415:6): [True: 0, False: 22.7k]
  |  Branch (415:42): [True: 0, False: 22.7k]
  ------------------
  416|       |		/* we do not support concatenation of AIDs at the moment */
  417|      0|		return SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  418|       |
  419|  22.7k|	if (p1->len + p2->len > SC_MAX_PATH_SIZE)
  ------------------
  |  |   47|  22.7k|#define SC_MAX_PATH_SIZE		16
  ------------------
  |  Branch (419:6): [True: 3, False: 22.7k]
  ------------------
  420|      3|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      3|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  421|       |
  422|  22.7k|	memset(&tpath, 0, sizeof(sc_path_t));
  423|  22.7k|	memcpy(tpath.value, p1->value, p1->len);
  424|  22.7k|	memcpy(tpath.value + p1->len, p2->value, p2->len);
  425|  22.7k|	tpath.len  = p1->len + p2->len;
  426|  22.7k|	tpath.type = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  22.7k|#define SC_PATH_TYPE_PATH		2
  ------------------
  427|       |	/* use 'index' and 'count' entry of the second path object */
  428|  22.7k|	tpath.index = p2->index;
  429|  22.7k|	tpath.count = p2->count;
  430|       |	/* the result is currently always as path */
  431|  22.7k|	tpath.type  = SC_PATH_TYPE_PATH;
  ------------------
  |  |  119|  22.7k|#define SC_PATH_TYPE_PATH		2
  ------------------
  432|       |
  433|  22.7k|	*d = tpath;
  434|       |
  435|  22.7k|	return SC_SUCCESS;
  ------------------
  |  |   28|  22.7k|#define SC_SUCCESS				0
  ------------------
  436|  22.7k|}
sc_print_path:
  439|   235k|{
  440|   235k|	static char buffer[SC_MAX_PATH_STRING_SIZE + SC_MAX_AID_STRING_SIZE];
  441|       |
  442|   235k|	if (sc_path_print(buffer, sizeof(buffer), path) != SC_SUCCESS)
  ------------------
  |  |   28|   235k|#define SC_SUCCESS				0
  ------------------
  |  Branch (442:6): [True: 0, False: 235k]
  ------------------
  443|      0|		buffer[0] = '\0';
  444|       |
  445|   235k|	return buffer;
  446|   235k|}
sc_path_print:
  449|   339k|{
  450|   339k|	size_t i;
  451|       |
  452|   339k|	if (buf == NULL || path == NULL)
  ------------------
  |  Branch (452:6): [True: 0, False: 339k]
  |  Branch (452:21): [True: 0, False: 339k]
  ------------------
  453|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  454|       |
  455|   339k|	if (buflen < path->len * 2 + path->aid.len * 2 + 3)
  ------------------
  |  Branch (455:6): [True: 626, False: 338k]
  ------------------
  456|    626|		return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|    626|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  457|       |
  458|   338k|	buf[0] = '\0';
  459|   338k|	if (path->aid.len)   {
  ------------------
  |  Branch (459:6): [True: 127k, False: 211k]
  ------------------
  460|  1.02M|		for (i = 0; i < path->aid.len; i++)
  ------------------
  |  Branch (460:15): [True: 897k, False: 127k]
  ------------------
  461|   897k|			snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->aid.value[i]);
  462|   127k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  463|   127k|	}
  464|       |
  465|  1.35M|	for (i = 0; i < path->len; i++)
  ------------------
  |  Branch (465:14): [True: 1.01M, False: 338k]
  ------------------
  466|  1.01M|		snprintf(buf + strlen(buf), buflen - strlen(buf), "%02x", path->value[i]);
  467|   338k|	if (!path->aid.len && path->type == SC_PATH_TYPE_DF_NAME)
  ------------------
  |  |  118|   211k|#define SC_PATH_TYPE_DF_NAME		1
  ------------------
  |  Branch (467:6): [True: 211k, False: 127k]
  |  Branch (467:24): [True: 30.1k, False: 181k]
  ------------------
  468|  30.1k|		snprintf(buf + strlen(buf), buflen - strlen(buf), "::");
  469|       |
  470|   338k|	return SC_SUCCESS;
  ------------------
  |  |   28|   338k|#define SC_SUCCESS				0
  ------------------
  471|   339k|}
sc_compare_path:
  474|  18.9k|{
  475|  18.9k|	return path1->len == path2->len
  ------------------
  |  Branch (475:9): [True: 15.7k, False: 3.16k]
  ------------------
  476|  15.7k|		&& !memcmp(path1->value, path2->value, path1->len);
  ------------------
  |  Branch (476:6): [True: 114, False: 15.6k]
  ------------------
  477|  18.9k|}
sc_compare_path_prefix:
  480|  16.6k|{
  481|  16.6k|	sc_path_t tpath;
  482|       |
  483|  16.6k|	if (prefix->len > path->len)
  ------------------
  |  Branch (483:6): [True: 2.90k, False: 13.7k]
  ------------------
  484|  2.90k|		return 0;
  485|       |
  486|  13.7k|	tpath     = *path;
  487|  13.7k|	tpath.len = prefix->len;
  488|       |
  489|  13.7k|	return sc_compare_path(&tpath, prefix);
  490|  16.6k|}
sc_get_mf_path:
  493|  20.4k|{
  494|  20.4k|	static const sc_path_t mf_path = {
  495|  20.4k|		{0x3f, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 2,
  496|  20.4k|		0,
  497|  20.4k|		0,
  498|  20.4k|		SC_PATH_TYPE_PATH,
  ------------------
  |  |  119|  20.4k|#define SC_PATH_TYPE_PATH		2
  ------------------
  499|  20.4k|		{{0},0}
  500|  20.4k|	};
  501|  20.4k|	return &mf_path;
  502|  20.4k|}
sc_file_add_acl_entry:
  506|   170k|{
  507|   170k|	sc_acl_entry_t *p, *_new;
  508|       |
  509|   170k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   170k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (509:6): [True: 0, False: 170k]
  |  Branch (509:22): [True: 0, False: 170k]
  ------------------
  510|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  511|      0|	}
  512|       |
  513|   170k|	switch (method) {
  514|  46.6k|	case SC_AC_NEVER:
  ------------------
  |  |  163|  46.6k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
  |  Branch (514:2): [True: 46.6k, False: 123k]
  ------------------
  515|  46.6k|		sc_file_clear_acl_entries(file, operation);
  516|  46.6k|		file->acl[operation] = (sc_acl_entry_t *) 1;
  517|  46.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  46.6k|#define SC_SUCCESS				0
  ------------------
  518|  7.98k|	case SC_AC_NONE:
  ------------------
  |  |  150|  7.98k|#define SC_AC_NONE			0x00000000
  ------------------
  |  Branch (518:2): [True: 7.98k, False: 162k]
  ------------------
  519|  7.98k|		sc_file_clear_acl_entries(file, operation);
  520|  7.98k|		file->acl[operation] = (sc_acl_entry_t *) 2;
  521|  7.98k|		return SC_SUCCESS;
  ------------------
  |  |   28|  7.98k|#define SC_SUCCESS				0
  ------------------
  522|  2.32k|	case SC_AC_UNKNOWN:
  ------------------
  |  |  162|  2.32k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
  |  Branch (522:2): [True: 2.32k, False: 168k]
  ------------------
  523|  2.32k|		sc_file_clear_acl_entries(file, operation);
  524|  2.32k|		file->acl[operation] = (sc_acl_entry_t *) 3;
  525|  2.32k|		return SC_SUCCESS;
  ------------------
  |  |   28|  2.32k|#define SC_SUCCESS				0
  ------------------
  526|   113k|	default:
  ------------------
  |  Branch (526:2): [True: 113k, False: 56.9k]
  ------------------
  527|       |		/* NONE and UNKNOWN get zapped when a new AC is added.
  528|       |		 * If the ACL is NEVER, additional entries will be
  529|       |		 * dropped silently. */
  530|   113k|		if (file->acl[operation] == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (530:7): [True: 14, False: 113k]
  ------------------
  531|     14|			return SC_SUCCESS;
  ------------------
  |  |   28|     14|#define SC_SUCCESS				0
  ------------------
  532|   113k|		if (file->acl[operation] == (sc_acl_entry_t *) 2
  ------------------
  |  Branch (532:7): [True: 1.24k, False: 112k]
  ------------------
  533|   112k|		 || file->acl[operation] == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (533:7): [True: 11, False: 112k]
  ------------------
  534|  1.25k|			file->acl[operation] = NULL;
  535|   170k|	}
  536|       |
  537|       |	/* If the entry is already present (e.g. due to the mapping)
  538|       |	 * of the card's AC with OpenSC's), don't add it again. */
  539|   148k|	for (p = file->acl[operation]; p != NULL; p = p->next) {
  ------------------
  |  Branch (539:33): [True: 37.3k, False: 110k]
  ------------------
  540|  37.3k|		if ((p->method == method) && (p->key_ref == key_ref))
  ------------------
  |  Branch (540:7): [True: 34.7k, False: 2.60k]
  |  Branch (540:32): [True: 2.57k, False: 32.1k]
  ------------------
  541|  2.57k|			return SC_SUCCESS;
  ------------------
  |  |   28|  2.57k|#define SC_SUCCESS				0
  ------------------
  542|  37.3k|	}
  543|       |
  544|   110k|	_new = malloc(sizeof(sc_acl_entry_t));
  545|   110k|	if (_new == NULL)
  ------------------
  |  Branch (545:6): [True: 0, False: 110k]
  ------------------
  546|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  547|   110k|	_new->method = method;
  548|   110k|	_new->key_ref = (unsigned)key_ref;
  549|   110k|	_new->next = NULL;
  550|       |
  551|   110k|	p = file->acl[operation];
  552|   110k|	if (p == NULL) {
  ------------------
  |  Branch (552:6): [True: 103k, False: 7.38k]
  ------------------
  553|   103k|		file->acl[operation] = _new;
  554|   103k|		return SC_SUCCESS;
  ------------------
  |  |   28|   103k|#define SC_SUCCESS				0
  ------------------
  555|   103k|	}
  556|  32.9k|	while (p->next != NULL)
  ------------------
  |  Branch (556:9): [True: 25.5k, False: 7.38k]
  ------------------
  557|  25.5k|		p = p->next;
  558|  7.38k|	p->next = _new;
  559|       |
  560|  7.38k|	return SC_SUCCESS;
  ------------------
  |  |   28|  7.38k|#define SC_SUCCESS				0
  ------------------
  561|   110k|}
sc_file_get_acl_entry:
  565|   491k|{
  566|   491k|	sc_acl_entry_t *p;
  567|   491k|	static const sc_acl_entry_t e_never = {
  568|   491k|		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  163|   491k|#define SC_AC_NEVER			0xFFFFFFFF
  ------------------
              		SC_AC_NEVER, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   491k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  569|   491k|	};
  570|   491k|	static const sc_acl_entry_t e_none = {
  571|   491k|		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  150|   491k|#define SC_AC_NONE			0x00000000
  ------------------
              		SC_AC_NONE, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   491k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  572|   491k|	};
  573|   491k|	static const sc_acl_entry_t e_unknown = {
  574|   491k|		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  162|   491k|#define SC_AC_UNKNOWN			0xFFFFFFFE
  ------------------
              		SC_AC_UNKNOWN, SC_AC_KEY_REF_NONE, NULL
  ------------------
  |  |  204|   491k|#define SC_AC_KEY_REF_NONE	0xFFFFFFFF
  ------------------
  575|   491k|	};
  576|       |
  577|   491k|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|   491k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (577:6): [True: 0, False: 491k]
  |  Branch (577:22): [True: 0, False: 491k]
  ------------------
  578|      0|		return NULL;
  579|      0|	}
  580|       |
  581|   491k|	p = file->acl[operation];
  582|   491k|	if (p == (sc_acl_entry_t *) 1)
  ------------------
  |  Branch (582:6): [True: 930, False: 490k]
  ------------------
  583|    930|		return &e_never;
  584|   490k|	if (p == (sc_acl_entry_t *) 2)
  ------------------
  |  Branch (584:6): [True: 1.03k, False: 489k]
  ------------------
  585|  1.03k|		return &e_none;
  586|   489k|	if (p == (sc_acl_entry_t *) 3)
  ------------------
  |  Branch (586:6): [True: 901, False: 488k]
  ------------------
  587|    901|		return &e_unknown;
  588|       |
  589|   488k|	return file->acl[operation];
  590|   489k|}
sc_file_clear_acl_entries:
  593|  3.28M|{
  594|  3.28M|	sc_acl_entry_t *e;
  595|       |
  596|  3.28M|	if (file == NULL || operation >= SC_MAX_AC_OPS) {
  ------------------
  |  |  198|  3.28M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (596:6): [True: 0, False: 3.28M]
  |  Branch (596:22): [True: 0, False: 3.28M]
  ------------------
  597|      0|		return;
  598|      0|	}
  599|       |
  600|  3.28M|	e = file->acl[operation];
  601|  3.28M|	if (e == (sc_acl_entry_t *) 1 ||
  ------------------
  |  Branch (601:6): [True: 46.4k, False: 3.24M]
  ------------------
  602|  3.24M|	    e == (sc_acl_entry_t *) 2 ||
  ------------------
  |  Branch (602:6): [True: 6.60k, False: 3.23M]
  ------------------
  603|  3.23M|	    e == (sc_acl_entry_t *) 3) {
  ------------------
  |  Branch (603:6): [True: 2.30k, False: 3.23M]
  ------------------
  604|  55.3k|		file->acl[operation] = NULL;
  605|  55.3k|		return;
  606|  55.3k|	}
  607|       |
  608|  3.34M|	while (e != NULL) {
  ------------------
  |  Branch (608:9): [True: 110k, False: 3.23M]
  ------------------
  609|   110k|		sc_acl_entry_t *tmp = e->next;
  610|   110k|		free(e);
  611|   110k|		e = tmp;
  612|   110k|	}
  613|       |	file->acl[operation] = NULL;
  614|  3.23M|}
sc_file_new:
  617|   104k|{
  618|   104k|	sc_file_t *file = (sc_file_t *)calloc(1, sizeof(sc_file_t));
  619|   104k|	if (file == NULL)
  ------------------
  |  Branch (619:6): [True: 0, False: 104k]
  ------------------
  620|      0|		return NULL;
  621|       |
  622|   104k|	file->magic = SC_FILE_MAGIC;
  ------------------
  |  |   57|   104k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  623|   104k|	return file;
  624|   104k|}
sc_file_free:
  627|   272k|{
  628|   272k|	unsigned int i;
  629|   272k|	if (file == NULL || !sc_file_valid(file))
  ------------------
  |  Branch (629:6): [True: 167k, False: 104k]
  |  Branch (629:22): [True: 0, False: 104k]
  ------------------
  630|   167k|		return;
  631|   104k|	file->magic = 0;
  632|  3.33M|	for (i = 0; i < SC_MAX_AC_OPS; i++)
  ------------------
  |  |  198|  3.33M|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (632:14): [True: 3.22M, False: 104k]
  ------------------
  633|  3.22M|		sc_file_clear_acl_entries(file, i);
  634|   104k|	if (file->sec_attr)
  ------------------
  |  Branch (634:6): [True: 1.05k, False: 103k]
  ------------------
  635|  1.05k|		free(file->sec_attr);
  636|   104k|	if (file->prop_attr)
  ------------------
  |  Branch (636:6): [True: 756, False: 103k]
  ------------------
  637|    756|		free(file->prop_attr);
  638|   104k|	if (file->type_attr)
  ------------------
  |  Branch (638:6): [True: 2.23k, False: 101k]
  ------------------
  639|  2.23k|		free(file->type_attr);
  640|   104k|	if (file->encoded_content)
  ------------------
  |  Branch (640:6): [True: 0, False: 104k]
  ------------------
  641|      0|		free(file->encoded_content);
  642|   104k|	free(file);
  643|   104k|}
sc_file_dup:
  646|  15.8k|{
  647|  15.8k|	sc_file_t *newf;
  648|  15.8k|	const sc_acl_entry_t *e;
  649|  15.8k|	unsigned int op;
  650|       |
  651|  15.8k|	*dest = NULL;
  652|  15.8k|	if (!sc_file_valid(src))
  ------------------
  |  Branch (652:6): [True: 0, False: 15.8k]
  ------------------
  653|      0|		return;
  654|  15.8k|	newf = sc_file_new();
  655|  15.8k|	if (newf == NULL)
  ------------------
  |  Branch (655:6): [True: 0, False: 15.8k]
  ------------------
  656|      0|		return;
  657|  15.8k|	*dest = newf;
  658|       |
  659|  15.8k|	memcpy(&newf->path, &src->path, sizeof(struct sc_path));
  660|  15.8k|	memcpy(&newf->name, &src->name, sizeof(src->name));
  661|  15.8k|	newf->namelen = src->namelen;
  662|  15.8k|	newf->type    = src->type;
  663|  15.8k|	newf->shareable    = src->shareable;
  664|  15.8k|	newf->ef_structure = src->ef_structure;
  665|  15.8k|	newf->size    = src->size;
  666|  15.8k|	newf->id      = src->id;
  667|  15.8k|	newf->status  = src->status;
  668|   507k|	for (op = 0; op < SC_MAX_AC_OPS; op++) {
  ------------------
  |  |  198|   507k|#define SC_MAX_AC_OPS			31
  ------------------
  |  Branch (668:15): [True: 491k, False: 15.8k]
  ------------------
  669|   491k|		newf->acl[op] = NULL;
  670|   491k|		e = sc_file_get_acl_entry(src, op);
  671|   491k|		if (e != NULL) {
  ------------------
  |  Branch (671:7): [True: 12.4k, False: 479k]
  ------------------
  672|  12.4k|			if (sc_file_add_acl_entry(newf, op, e->method, e->key_ref) < 0)
  ------------------
  |  Branch (672:8): [True: 0, False: 12.4k]
  ------------------
  673|      0|				goto err;
  674|  12.4k|		}
  675|   491k|	}
  676|  15.8k|	newf->record_length = src->record_length;
  677|  15.8k|	newf->record_count  = src->record_count;
  678|       |
  679|  15.8k|	if (sc_file_set_sec_attr(newf, src->sec_attr, src->sec_attr_len) < 0)
  ------------------
  |  Branch (679:6): [True: 0, False: 15.8k]
  ------------------
  680|      0|		goto err;
  681|  15.8k|	if (sc_file_set_prop_attr(newf, src->prop_attr, src->prop_attr_len) < 0)
  ------------------
  |  Branch (681:6): [True: 0, False: 15.8k]
  ------------------
  682|      0|		goto err;
  683|  15.8k|	if (sc_file_set_type_attr(newf, src->type_attr, src->type_attr_len) < 0)
  ------------------
  |  Branch (683:6): [True: 0, False: 15.8k]
  ------------------
  684|      0|		goto err;
  685|  15.8k|	if (sc_file_set_content(newf, src->encoded_content, src->encoded_content_len) < 0)
  ------------------
  |  Branch (685:6): [True: 0, False: 15.8k]
  ------------------
  686|      0|		goto err;
  687|  15.8k|	return;
  688|  15.8k|err:
  689|      0|	sc_file_free(newf);
  690|       |	*dest = NULL;
  691|      0|}
sc_file_set_sec_attr:
  695|  17.2k|{
  696|  17.2k|	u8 *tmp;
  697|  17.2k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (697:6): [True: 0, False: 17.2k]
  ------------------
  698|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  699|      0|	}
  700|       |
  701|  17.2k|	if (sec_attr == NULL || sec_attr_len == 0) {
  ------------------
  |  Branch (701:6): [True: 15.8k, False: 1.44k]
  |  Branch (701:26): [True: 271, False: 1.17k]
  ------------------
  702|  16.1k|		if (file->sec_attr != NULL)
  ------------------
  |  Branch (702:7): [True: 66, False: 16.0k]
  ------------------
  703|     66|			free(file->sec_attr);
  704|  16.1k|		file->sec_attr = NULL;
  705|  16.1k|		file->sec_attr_len = 0;
  706|  16.1k|		return 0;
  707|  16.1k|	 }
  708|  1.17k|	tmp = (u8 *) realloc(file->sec_attr, sec_attr_len);
  709|  1.17k|	if (!tmp) {
  ------------------
  |  Branch (709:6): [True: 0, False: 1.17k]
  ------------------
  710|      0|		if (file->sec_attr)
  ------------------
  |  Branch (710:7): [True: 0, False: 0]
  ------------------
  711|      0|			free(file->sec_attr);
  712|      0|		file->sec_attr     = NULL;
  713|      0|		file->sec_attr_len = 0;
  714|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  715|      0|	}
  716|  1.17k|	file->sec_attr = tmp;
  717|  1.17k|	memcpy(file->sec_attr, sec_attr, sec_attr_len);
  718|  1.17k|	file->sec_attr_len = sec_attr_len;
  719|       |
  720|  1.17k|	return 0;
  721|  1.17k|}
sc_file_set_prop_attr:
  725|  17.2k|{
  726|  17.2k|	u8 *tmp;
  727|  17.2k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (727:6): [True: 0, False: 17.2k]
  ------------------
  728|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  729|      0|	}
  730|       |
  731|  17.2k|	if (prop_attr == NULL || prop_attr_len == 0) {
  ------------------
  |  Branch (731:6): [True: 15.8k, False: 1.38k]
  |  Branch (731:27): [True: 485, False: 900]
  ------------------
  732|  16.3k|		if (file->prop_attr != NULL)
  ------------------
  |  Branch (732:7): [True: 72, False: 16.2k]
  ------------------
  733|     72|			free(file->prop_attr);
  734|  16.3k|		file->prop_attr = NULL;
  735|  16.3k|		file->prop_attr_len = 0;
  736|  16.3k|		return SC_SUCCESS;
  ------------------
  |  |   28|  16.3k|#define SC_SUCCESS				0
  ------------------
  737|  16.3k|	 }
  738|    900|	tmp = (u8 *) realloc(file->prop_attr, prop_attr_len);
  739|    900|	if (!tmp) {
  ------------------
  |  Branch (739:6): [True: 0, False: 900]
  ------------------
  740|      0|		if (file->prop_attr)
  ------------------
  |  Branch (740:7): [True: 0, False: 0]
  ------------------
  741|      0|			free(file->prop_attr);
  742|      0|		file->prop_attr = NULL;
  743|      0|		file->prop_attr_len = 0;
  744|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  745|      0|	}
  746|    900|	file->prop_attr = tmp;
  747|    900|	memcpy(file->prop_attr, prop_attr, prop_attr_len);
  748|    900|	file->prop_attr_len = prop_attr_len;
  749|       |
  750|    900|	return SC_SUCCESS;
  ------------------
  |  |   28|    900|#define SC_SUCCESS				0
  ------------------
  751|    900|}
sc_file_set_type_attr:
  755|  17.8k|{
  756|  17.8k|	u8 *tmp;
  757|  17.8k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (757:6): [True: 0, False: 17.8k]
  ------------------
  758|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  759|      0|	}
  760|       |
  761|  17.8k|	if (type_attr == NULL || type_attr_len == 0) {
  ------------------
  |  Branch (761:6): [True: 15.1k, False: 2.72k]
  |  Branch (761:27): [True: 0, False: 2.72k]
  ------------------
  762|  15.1k|		if (file->type_attr != NULL)
  ------------------
  |  Branch (762:7): [True: 0, False: 15.1k]
  ------------------
  763|      0|			free(file->type_attr);
  764|  15.1k|		file->type_attr = NULL;
  765|  15.1k|		file->type_attr_len = 0;
  766|  15.1k|		return SC_SUCCESS;
  ------------------
  |  |   28|  15.1k|#define SC_SUCCESS				0
  ------------------
  767|  15.1k|	 }
  768|  2.72k|	tmp = (u8 *) realloc(file->type_attr, type_attr_len);
  769|  2.72k|	if (!tmp) {
  ------------------
  |  Branch (769:6): [True: 0, False: 2.72k]
  ------------------
  770|      0|		if (file->type_attr)
  ------------------
  |  Branch (770:7): [True: 0, False: 0]
  ------------------
  771|      0|			free(file->type_attr);
  772|      0|		file->type_attr = NULL;
  773|      0|		file->type_attr_len = 0;
  774|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  775|      0|	}
  776|  2.72k|	file->type_attr = tmp;
  777|  2.72k|	memcpy(file->type_attr, type_attr, type_attr_len);
  778|  2.72k|	file->type_attr_len = type_attr_len;
  779|       |
  780|  2.72k|	return SC_SUCCESS;
  ------------------
  |  |   28|  2.72k|#define SC_SUCCESS				0
  ------------------
  781|  2.72k|}
sc_file_set_content:
  786|  15.8k|{
  787|  15.8k|	u8 *tmp;
  788|  15.8k|	if (!sc_file_valid(file)) {
  ------------------
  |  Branch (788:6): [True: 0, False: 15.8k]
  ------------------
  789|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  790|      0|	}
  791|       |
  792|  15.8k|	if (content == NULL || content_len == 0) {
  ------------------
  |  Branch (792:6): [True: 15.8k, False: 0]
  |  Branch (792:25): [True: 0, False: 0]
  ------------------
  793|  15.8k|		if (file->encoded_content != NULL)
  ------------------
  |  Branch (793:7): [True: 0, False: 15.8k]
  ------------------
  794|      0|			free(file->encoded_content);
  795|  15.8k|		file->encoded_content = NULL;
  796|  15.8k|		file->encoded_content_len = 0;
  797|  15.8k|		return SC_SUCCESS;
  ------------------
  |  |   28|  15.8k|#define SC_SUCCESS				0
  ------------------
  798|  15.8k|	}
  799|       |
  800|      0|	tmp = (u8 *) realloc(file->encoded_content, content_len);
  801|      0|	if (!tmp) {
  ------------------
  |  Branch (801:6): [True: 0, False: 0]
  ------------------
  802|      0|		if (file->encoded_content)
  ------------------
  |  Branch (802:7): [True: 0, False: 0]
  ------------------
  803|      0|			free(file->encoded_content);
  804|      0|		file->encoded_content = NULL;
  805|      0|		file->encoded_content_len = 0;
  806|      0|		return SC_ERROR_OUT_OF_MEMORY;
  ------------------
  |  |   85|      0|#define SC_ERROR_OUT_OF_MEMORY			-1404
  ------------------
  807|      0|	}
  808|       |
  809|      0|	file->encoded_content = tmp;
  810|      0|	memcpy(file->encoded_content, content, content_len);
  811|      0|	file->encoded_content_len = content_len;
  812|       |
  813|      0|	return SC_SUCCESS;
  ------------------
  |  |   28|      0|#define SC_SUCCESS				0
  ------------------
  814|      0|}
sc_file_valid:
  817|   188k|int sc_file_valid(const sc_file_t *file) {
  818|   188k|	if (file == NULL)
  ------------------
  |  Branch (818:6): [True: 0, False: 188k]
  ------------------
  819|      0|		return 0;
  820|   188k|	return file->magic == SC_FILE_MAGIC;
  ------------------
  |  |   57|   188k|#define SC_FILE_MAGIC			0x14426950
  ------------------
  821|   188k|}
_sc_parse_atr:
  824|  15.3k|{
  825|  15.3k|	u8 *p = reader->atr.value;
  826|  15.3k|	int atr_len = (int) reader->atr.len;
  827|  15.3k|	int n_hist, x;
  828|  15.3k|	int tx[4] = {-1, -1, -1, -1};
  829|  15.3k|	int i, FI, DI;
  830|  15.3k|	const int Fi_table[] = {
  831|  15.3k|		372, 372, 558, 744, 1116, 1488, 1860, -1,
  832|  15.3k|		-1, 512, 768, 1024, 1536, 2048, -1, -1 };
  833|  15.3k|	const int f_table[] = {
  834|  15.3k|		40, 50, 60, 80, 120, 160, 200, -1,
  835|  15.3k|		-1, 50, 75, 100, 150, 200, -1, -1 };
  836|  15.3k|	const int Di_table[] = {
  837|  15.3k|		-1, 1, 2, 4, 8, 16, 32, -1,
  838|  15.3k|		12, 20, -1, -1, -1, -1, -1, -1 };
  839|       |
  840|  15.3k|	reader->atr_info.hist_bytes_len = 0;
  841|  15.3k|	reader->atr_info.hist_bytes = NULL;
  842|       |
  843|  15.3k|	if (atr_len == 0) {
  ------------------
  |  Branch (843:6): [True: 2.56k, False: 12.7k]
  ------------------
  844|  2.56k|		sc_log(reader->ctx, "empty ATR - card not present?\n");
  ------------------
  |  |   71|  2.56k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  845|  2.56k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  2.56k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  846|  2.56k|	}
  847|       |
  848|  12.7k|	if (p[0] != 0x3B && p[0] != 0x3F) {
  ------------------
  |  Branch (848:6): [True: 1.28k, False: 11.4k]
  |  Branch (848:22): [True: 1.22k, False: 62]
  ------------------
  849|  1.22k|		sc_log(reader->ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
  ------------------
  |  |   71|  1.22k|#define sc_log(ctx, format, args...)   sc_do_log(ctx, SC_LOG_DEBUG_NORMAL, FILENAME, __LINE__, __FUNCTION__, format , ## args)
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  ------------------
  850|  1.22k|		return SC_ERROR_INTERNAL;
  ------------------
  |  |   81|  1.22k|#define SC_ERROR_INTERNAL			-1400
  ------------------
  851|  1.22k|	}
  852|  11.5k|	n_hist = p[1] & 0x0F;
  853|  11.5k|	x = p[1] >> 4;
  854|  11.5k|	p += 2;
  855|  11.5k|	atr_len -= 2;
  856|  57.6k|	for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (856:14): [True: 46.1k, False: 11.5k]
  |  Branch (856:23): [True: 46.0k, False: 53]
  ------------------
  857|  46.0k|                if (x & (1 << i)) {
  ------------------
  |  Branch (857:21): [True: 31.4k, False: 14.6k]
  ------------------
  858|  31.4k|                        tx[i] = *p;
  859|  31.4k|                        p++;
  860|  31.4k|                        atr_len--;
  861|  31.4k|                } else
  862|  14.6k|                        tx[i] = -1;
  863|  46.0k|        }
  864|  11.5k|	if (tx[0] >= 0) {
  ------------------
  |  Branch (864:6): [True: 9.85k, False: 1.70k]
  ------------------
  865|  9.85k|		reader->atr_info.FI = FI = tx[0] >> 4;
  866|  9.85k|		reader->atr_info.DI = DI = tx[0] & 0x0F;
  867|  9.85k|		reader->atr_info.Fi = Fi_table[FI];
  868|  9.85k|		reader->atr_info.f = f_table[FI];
  869|  9.85k|		reader->atr_info.Di = Di_table[DI];
  870|  9.85k|	} else {
  871|  1.70k|		reader->atr_info.Fi = -1;
  872|  1.70k|		reader->atr_info.f = -1;
  873|  1.70k|		reader->atr_info.Di = -1;
  874|  1.70k|	}
  875|  11.5k|	if (tx[2] >= 0)
  ------------------
  |  Branch (875:6): [True: 7.85k, False: 3.70k]
  ------------------
  876|  7.85k|		reader->atr_info.N = tx[3];
  877|  3.70k|	else
  878|  3.70k|		reader->atr_info.N = -1;
  879|  26.5k|	while (tx[3] > 0 && tx[3] & 0xF0 && atr_len > 0) {
  ------------------
  |  Branch (879:9): [True: 15.4k, False: 11.1k]
  |  Branch (879:22): [True: 15.0k, False: 406]
  |  Branch (879:38): [True: 15.0k, False: 47]
  ------------------
  880|  15.0k|		x = tx[3] >> 4;
  881|  75.0k|		for (i = 0; i < 4 && atr_len > 0; i++) {
  ------------------
  |  Branch (881:15): [True: 60.0k, False: 14.9k]
  |  Branch (881:24): [True: 60.0k, False: 23]
  ------------------
  882|  60.0k|	                if (x & (1 << i)) {
  ------------------
  |  Branch (882:22): [True: 23.0k, False: 37.0k]
  ------------------
  883|  23.0k|	                        tx[i] = *p;
  884|  23.0k|	                        p++;
  885|  23.0k|	                        atr_len--;
  886|  23.0k|	                } else
  887|  37.0k|	                        tx[i] = -1;
  888|  60.0k|		}
  889|  15.0k|	}
  890|  11.5k|	if (atr_len <= 0)
  ------------------
  |  Branch (890:6): [True: 107, False: 11.4k]
  ------------------
  891|    107|		return SC_SUCCESS;
  ------------------
  |  |   28|    107|#define SC_SUCCESS				0
  ------------------
  892|  11.4k|	if (n_hist > atr_len)
  ------------------
  |  Branch (892:6): [True: 780, False: 10.6k]
  ------------------
  893|    780|		n_hist = atr_len;
  894|  11.4k|	reader->atr_info.hist_bytes_len = n_hist;
  895|  11.4k|	reader->atr_info.hist_bytes = p;
  896|  11.4k|	return SC_SUCCESS;
  ------------------
  |  |   28|  11.4k|#define SC_SUCCESS				0
  ------------------
  897|  11.5k|}
sc_mem_secure_alloc:
  900|  46.2k|{
  901|  46.2k|	void *p;
  902|       |
  903|       |#ifdef _WIN32
  904|       |	p = VirtualAlloc(NULL, len, MEM_COMMIT, PAGE_READWRITE);
  905|       |	if (p != NULL) {
  906|       |		VirtualLock(p, len);
  907|       |	}
  908|       |#else
  909|  46.2k|	p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  910|  46.2k|	if (p != NULL) {
  ------------------
  |  Branch (910:6): [True: 46.2k, False: 0]
  ------------------
  911|  46.2k|		mlock(p, len);
  912|  46.2k|	}
  913|  46.2k|#endif
  914|       |
  915|  46.2k|	return p;
  916|  46.2k|}
sc_mem_secure_free:
  919|  46.2k|{
  920|       |#ifdef _WIN32
  921|       |	VirtualUnlock(ptr, len);
  922|       |	VirtualFree(ptr, 0, MEM_RELEASE);
  923|       |#else
  924|  46.2k|	munlock(ptr, len);
  925|  46.2k|	munmap(ptr, len);
  926|  46.2k|#endif
  927|  46.2k|}
sc_mem_clear:
  930|  97.3k|{
  931|  97.3k|	if (len > 0)   {
  ------------------
  |  Branch (931:6): [True: 96.8k, False: 486]
  ------------------
  932|       |#ifdef HAVE_MEMSET_S
  933|       |		memset_s(ptr, len, 0, len);
  934|       |#elif _WIN32
  935|       |		SecureZeroMemory(ptr, len);
  936|       |#elif HAVE_EXPLICIT_BZERO
  937|       |		explicit_bzero(ptr, len);
  938|       |#elif ENABLE_OPENSSL
  939|       |		OPENSSL_cleanse(ptr, len);
  940|       |#else
  941|       |		memset(ptr, 0, len);
  942|       |#endif
  943|  96.8k|	}
  944|  97.3k|}
sc_compacttlv_find_tag:
 1058|  1.32k|{
 1059|  1.32k|	if (buf != NULL) {
  ------------------
  |  Branch (1059:6): [True: 1.32k, False: 0]
  ------------------
 1060|  1.32k|		size_t idx;
 1061|  1.32k|		u8 plain_tag = tag & 0xF0;
 1062|  1.32k|		size_t expected_len = tag & 0x0F;
 1063|       |
 1064|  22.0k|		for (idx = 0; idx < len; idx++) {
  ------------------
  |  Branch (1064:17): [True: 21.1k, False: 969]
  ------------------
 1065|  21.1k|			u8 ctag = buf[idx] & 0xF0;
 1066|  21.1k|			size_t ctag_len = buf[idx] & 0x0F;
 1067|  21.1k|			if (ctag == plain_tag && idx + ctag_len < len &&
  ------------------
  |  Branch (1067:8): [True: 1.50k, False: 19.6k]
  |  Branch (1067:29): [True: 1.49k, False: 12]
  ------------------
 1068|  1.49k|					(expected_len == 0 || expected_len == ctag_len)) {
  ------------------
  |  Branch (1068:7): [True: 191, False: 1.30k]
  |  Branch (1068:28): [True: 161, False: 1.13k]
  ------------------
 1069|    352|				if (outlen != NULL)
  ------------------
  |  Branch (1069:9): [True: 191, False: 161]
  ------------------
 1070|    191|					*outlen = ctag_len;
 1071|    352|				return buf + (idx + 1);
 1072|    352|			}
 1073|  20.7k|			idx += ctag_len;
 1074|  20.7k|		}
 1075|  1.32k|	}
 1076|    969|	return NULL;
 1077|  1.32k|}
sc_mutex_create:
 1082|  30.6k|{
 1083|  30.6k|	if (ctx == NULL)
  ------------------
  |  Branch (1083:6): [True: 0, False: 30.6k]
  ------------------
 1084|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1085|  30.6k|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->create_mutex != NULL)
  ------------------
  |  Branch (1085:6): [True: 0, False: 30.6k]
  |  Branch (1085:33): [True: 0, False: 0]
  ------------------
 1086|      0|		return ctx->thread_ctx->create_mutex(mutex);
 1087|  30.6k|	else
 1088|  30.6k|		return SC_SUCCESS;
  ------------------
  |  |   28|  30.6k|#define SC_SUCCESS				0
  ------------------
 1089|  30.6k|}
sc_mutex_lock:
 1092|  1.29M|{
 1093|  1.29M|	if (ctx == NULL)
  ------------------
  |  Branch (1093:6): [True: 0, False: 1.29M]
  ------------------
 1094|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1095|  1.29M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->lock_mutex != NULL)
  ------------------
  |  Branch (1095:6): [True: 0, False: 1.29M]
  |  Branch (1095:33): [True: 0, False: 0]
  ------------------
 1096|      0|		return ctx->thread_ctx->lock_mutex(mutex);
 1097|  1.29M|	else
 1098|  1.29M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.29M|#define SC_SUCCESS				0
  ------------------
 1099|  1.29M|}
sc_mutex_unlock:
 1102|  1.29M|{
 1103|  1.29M|	if (ctx == NULL)
  ------------------
  |  Branch (1103:6): [True: 0, False: 1.29M]
  ------------------
 1104|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
 1105|  1.29M|	if (ctx->thread_ctx != NULL && ctx->thread_ctx->unlock_mutex != NULL)
  ------------------
  |  Branch (1105:6): [True: 0, False: 1.29M]
  |  Branch (1105:33): [True: 0, False: 0]
  ------------------
 1106|      0|		return ctx->thread_ctx->unlock_mutex(mutex);
 1107|  1.29M|	else
 1108|  1.29M|		return SC_SUCCESS;
  ------------------
  |  |   28|  1.29M|#define SC_SUCCESS				0
  ------------------
 1109|  1.29M|}

sc_decipher:
   37|  2.30k|{
   38|  2.30k|	int r;
   39|       |
   40|  2.30k|	if (card == NULL) {
  ------------------
  |  Branch (40:6): [True: 0, False: 2.30k]
  ------------------
   41|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   42|      0|	}
   43|  2.30k|	if (crgram == NULL || out == NULL) {
  ------------------
  |  Branch (43:6): [True: 227, False: 2.07k]
  |  Branch (43:24): [True: 0, False: 2.07k]
  ------------------
   44|    227|		LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
  ------------------
  |  |  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]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   45|    227|	}
   46|  2.07k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  2.07k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  2.07k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  2.07k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  2.07k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 2.07k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   47|  2.07k|	if (card->ops->decipher == NULL)
  ------------------
  |  Branch (47:6): [True: 0, False: 2.07k]
  ------------------
   48|      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]
  |  |  ------------------
  ------------------
   49|  2.07k|	r = card->ops->decipher(card, crgram, crgram_len, out, outlen);
   50|  2.07k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  2.07k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  2.07k|	int _ret = r; \
  |  |  155|  2.07k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 1.76k, False: 305]
  |  |  ------------------
  |  |  156|  1.76k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  1.62k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 1.62k, False: 143]
  |  |  ------------------
  |  |  157|  1.76k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  1.76k|	} else { \
  |  |  159|    305|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    305|			"returning with: %d\n", _ret); \
  |  |  161|    305|	} \
  |  |  162|  2.07k|	return _ret; \
  |  |  163|  2.07k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   51|  2.07k|}
sc_compute_signature:
   56|  5.46k|{
   57|  5.46k|	int r;
   58|       |
   59|  5.46k|	if (card == NULL) {
  ------------------
  |  Branch (59:6): [True: 0, False: 5.46k]
  ------------------
   60|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
   61|      0|	}
   62|  5.46k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  5.46k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  5.46k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  5.46k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  5.46k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 5.46k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   63|  5.46k|	if (card->ops->compute_signature == NULL)
  ------------------
  |  Branch (63:6): [True: 0, False: 5.46k]
  ------------------
   64|      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]
  |  |  ------------------
  ------------------
   65|  5.46k|	r = card->ops->compute_signature(card, data, datalen, out, outlen);
   66|  5.46k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  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.08k, False: 377]
  |  |  ------------------
  |  |  156|  5.08k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  4.85k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.85k, False: 226]
  |  |  ------------------
  |  |  157|  5.08k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  5.08k|	} else { \
  |  |  159|    377|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|    377|			"returning with: %d\n", _ret); \
  |  |  161|    377|	} \
  |  |  162|  5.46k|	return _ret; \
  |  |  163|  5.46k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
   67|  5.46k|}
sc_set_security_env:
  102|  11.8k|{
  103|  11.8k|	int r;
  104|       |
  105|  11.8k|	if (card == NULL) {
  ------------------
  |  Branch (105:6): [True: 0, False: 11.8k]
  ------------------
  106|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  107|      0|	}
  108|  11.8k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  11.8k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  11.8k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  11.8k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  11.8k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 11.8k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  109|  11.8k|	if (card->ops->set_security_env == NULL)
  ------------------
  |  Branch (109:6): [True: 0, False: 11.8k]
  ------------------
  110|      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]
  |  |  ------------------
  ------------------
  111|  11.8k|	r = card->ops->set_security_env(card, env, se_num);
  112|  11.8k|        SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  11.8k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  11.8k|	int _ret = r; \
  |  |  155|  11.8k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 11.8k, False: 0]
  |  |  ------------------
  |  |  156|  11.8k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  4.04k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 4.04k, False: 7.76k]
  |  |  ------------------
  |  |  157|  11.8k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  11.8k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  11.8k|	return _ret; \
  |  |  163|  11.8k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  113|  11.8k|}
sc_restore_security_env:
  116|     47|{
  117|     47|	int r;
  118|       |
  119|     47|	if (card == NULL) {
  ------------------
  |  Branch (119:6): [True: 0, False: 47]
  ------------------
  120|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  121|      0|	}
  122|     47|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|     47|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|     47|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|     47|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|     47|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 47]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  123|     47|	if (card->ops->restore_security_env == NULL)
  ------------------
  |  Branch (123:6): [True: 0, False: 47]
  ------------------
  124|      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]
  |  |  ------------------
  ------------------
  125|     47|	r = card->ops->restore_security_env(card, se_num);
  126|     47|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 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|     30|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 30, False: 17]
  |  |  ------------------
  |  |  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]
  |  |  ------------------
  ------------------
  127|     47|}
sc_verify:
  131|  1.10k|{
  132|  1.10k|	struct sc_pin_cmd_data data;
  133|       |
  134|  1.10k|	memset(&data, 0, sizeof(data));
  135|  1.10k|	data.cmd = SC_PIN_CMD_VERIFY;
  ------------------
  |  |  422|  1.10k|#define SC_PIN_CMD_VERIFY	0
  ------------------
  136|  1.10k|	data.pin_type = type;
  137|  1.10k|	data.pin_reference = ref;
  138|  1.10k|	data.pin1.data = pin;
  139|  1.10k|	data.pin1.len = pinlen;
  140|       |
  141|  1.10k|	return sc_pin_cmd(card, &data, tries_left);
  142|  1.10k|}
sc_pin_cmd:
  197|  9.88k|{
  198|  9.88k|	int r, debug;
  199|       |
  200|  9.88k|	if (card == NULL) {
  ------------------
  |  Branch (200:6): [True: 0, False: 9.88k]
  ------------------
  201|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  202|      0|	}
  203|  9.88k|	LOG_FUNC_CALLED(card->ctx);
  ------------------
  |  |  151|  9.88k|#define LOG_FUNC_CALLED(ctx) SC_FUNC_CALLED((ctx), SC_LOG_DEBUG_NORMAL)
  |  |  ------------------
  |  |  |  |  148|  9.88k|#define SC_FUNC_CALLED(ctx, level) do { \
  |  |  |  |  149|  9.88k|	 sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, "called\n"); \
  |  |  |  |  ------------------
  |  |  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  |  |  ------------------
  |  |  |  |  150|  9.88k|} while (0)
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (150:10): [Folded, False: 9.88k]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  204|       |
  205|  9.88k|	debug = card->ctx->debug;
  206|  9.88k|	if (data->cmd != SC_PIN_CMD_GET_INFO
  ------------------
  |  |  425|  19.7k|#define SC_PIN_CMD_GET_INFO	3
  ------------------
  |  Branch (206:6): [True: 2.77k, False: 7.11k]
  ------------------
  207|  2.77k|			&& card->ctx->debug < SC_LOG_DEBUG_PIN) {
  ------------------
  |  Branch (207:7): [True: 2.77k, False: 0]
  ------------------
  208|  2.77k|		card->ctx->debug = 0;
  209|  2.77k|	}
  210|       |
  211|  9.88k|	if (card->ops->pin_cmd) {
  ------------------
  |  Branch (211:6): [True: 9.88k, False: 0]
  ------------------
  212|  9.88k|		r = card->ops->pin_cmd(card, data, tries_left);
  213|  9.88k|	} else if (!(data->flags & SC_PIN_CMD_USE_PINPAD)) {
  ------------------
  |  |  428|      0|#define SC_PIN_CMD_USE_PINPAD		0x0001
  ------------------
  |  Branch (213:13): [True: 0, False: 0]
  ------------------
  214|       |		/* Card driver doesn't support new style pin_cmd, fall
  215|       |		 * back to old interface */
  216|       |
  217|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  218|      0|		switch (data->cmd) {
  ------------------
  |  Branch (218:11): [True: 0, False: 0]
  ------------------
  219|      0|		case SC_PIN_CMD_VERIFY:
  ------------------
  |  |  422|      0|#define SC_PIN_CMD_VERIFY	0
  ------------------
  |  Branch (219:3): [True: 0, False: 0]
  ------------------
  220|      0|			if (card->ops->verify != NULL)
  ------------------
  |  Branch (220:8): [True: 0, False: 0]
  ------------------
  221|      0|				r = card->ops->verify(card,
  222|      0|					data->pin_type,
  223|      0|					data->pin_reference,
  224|      0|					data->pin1.data,
  225|      0|					(size_t) data->pin1.len,
  226|      0|					tries_left);
  227|      0|			break;
  228|      0|		case SC_PIN_CMD_CHANGE:
  ------------------
  |  |  423|      0|#define SC_PIN_CMD_CHANGE	1
  ------------------
  |  Branch (228:3): [True: 0, False: 0]
  ------------------
  229|      0|			if (card->ops->change_reference_data != NULL)
  ------------------
  |  Branch (229:8): [True: 0, False: 0]
  ------------------
  230|      0|				r = card->ops->change_reference_data(card,
  231|      0|					data->pin_type,
  232|      0|					data->pin_reference,
  233|      0|					data->pin1.data,
  234|      0|					(size_t) data->pin1.len,
  235|      0|					data->pin2.data,
  236|      0|					(size_t) data->pin2.len,
  237|      0|					tries_left);
  238|      0|			break;
  239|      0|		case SC_PIN_CMD_UNBLOCK:
  ------------------
  |  |  424|      0|#define SC_PIN_CMD_UNBLOCK	2
  ------------------
  |  Branch (239:3): [True: 0, False: 0]
  ------------------
  240|      0|			if (card->ops->reset_retry_counter != NULL)
  ------------------
  |  Branch (240:8): [True: 0, False: 0]
  ------------------
  241|      0|				r = card->ops->reset_retry_counter(card,
  242|      0|					data->pin_type,
  243|      0|					data->pin_reference,
  244|      0|					data->pin1.data,
  245|      0|					(size_t) data->pin1.len,
  246|      0|					data->pin2.data,
  247|      0|					(size_t) data->pin2.len);
  248|      0|			break;
  249|      0|		}
  250|      0|		if (r == SC_ERROR_NOT_SUPPORTED)
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  |  Branch (250:7): [True: 0, False: 0]
  ------------------
  251|      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__
  |  |  ------------------
  ------------------
  252|      0|					data->cmd);
  253|      0|	} else {
  254|      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__
  |  |  ------------------
  ------------------
  255|      0|		r = SC_ERROR_NOT_SUPPORTED;
  ------------------
  |  |   89|      0|#define SC_ERROR_NOT_SUPPORTED			-1408
  ------------------
  256|      0|	}
  257|  9.88k|	card->ctx->debug = debug;
  258|       |
  259|  9.88k|	SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
  ------------------
  |  |  153|  9.88k|#define SC_FUNC_RETURN(ctx, level, r) do { \
  |  |  154|  9.88k|	int _ret = r; \
  |  |  155|  9.88k|	if (_ret <= 0) { \
  |  |  ------------------
  |  |  |  Branch (155:6): [True: 9.88k, False: 0]
  |  |  ------------------
  |  |  156|  9.88k|		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |               		sc_do_log_color(ctx, level, FILENAME, __LINE__, __FUNCTION__, _ret ? SC_COLOR_FG_RED : 0, \
  |  |  ------------------
  |  |  |  |   44|  6.14k|#define SC_COLOR_FG_RED			0x0001
  |  |  ------------------
  |  |  |  Branch (156:65): [True: 6.14k, False: 3.74k]
  |  |  ------------------
  |  |  157|  9.88k|			"returning with: %d (%s)\n", _ret, sc_strerror(_ret)); \
  |  |  158|  9.88k|	} else { \
  |  |  159|      0|		sc_do_log(ctx, level, FILENAME, __LINE__, __FUNCTION__, \
  |  |  ------------------
  |  |  |  |   64|       |#define FILENAME __FILE_NAME__
  |  |  ------------------
  |  |  160|      0|			"returning with: %d\n", _ret); \
  |  |  161|      0|	} \
  |  |  162|  9.88k|	return _ret; \
  |  |  163|  9.88k|} while(0)
  |  |  ------------------
  |  |  |  Branch (163:9): [Folded, False: 0]
  |  |  ------------------
  ------------------
  260|  9.88k|}
sc_build_pin:
  274|  2.05k|{
  275|  2.05k|	size_t i = 0, j, pin_len = pin->len;
  276|       |
  277|  2.05k|	if (pin->max_length && pin_len > pin->max_length)
  ------------------
  |  Branch (277:6): [True: 1.79k, False: 258]
  |  Branch (277:25): [True: 0, False: 1.79k]
  ------------------
  278|      0|		return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      0|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  279|       |
  280|  2.05k|	if (pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  434|  2.05k|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (280:6): [True: 46, False: 2.00k]
  ------------------
  281|    125|		while (pin_len > 0 && pin->data[pin_len - 1] == 0xFF)
  ------------------
  |  Branch (281:10): [True: 122, False: 3]
  |  Branch (281:25): [True: 79, False: 43]
  ------------------
  282|     79|			pin_len--;
  283|     46|		if (pin_len > 12)
  ------------------
  |  Branch (283:7): [True: 9, False: 37]
  ------------------
  284|      9|			return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|      9|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  285|     99|		for (i = 0; i < pin_len; i++) {
  ------------------
  |  Branch (285:15): [True: 83, False: 16]
  ------------------
  286|     83|			if (pin->data[i] < '0' || pin->data[i] > '9')
  ------------------
  |  Branch (286:8): [True: 12, False: 71]
  |  Branch (286:30): [True: 9, False: 62]
  ------------------
  287|     21|				return SC_ERROR_INVALID_ARGUMENTS;
  ------------------
  |  |   73|     21|#define SC_ERROR_INVALID_ARGUMENTS		-1300
  ------------------
  288|     83|		}
  289|     16|		buf[0] = 0x20 | (u8) pin_len;
  290|     16|		buf++;
  291|     16|		buflen--;
  292|     16|	}
  293|       |
  294|       |	/* PIN given by application, encode if required */
  295|  2.02k|	if (pin->encoding == SC_PIN_ENCODING_ASCII) {
  ------------------
  |  |  432|  2.02k|#define SC_PIN_ENCODING_ASCII	0
  ------------------
  |  Branch (295:6): [True: 1.97k, False: 47]
  ------------------
  296|  1.97k|		if (pin_len > buflen)
  ------------------
  |  Branch (296:7): [True: 32, False: 1.94k]
  ------------------
  297|     32|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|     32|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  298|  1.94k|		memcpy(buf, pin->data, pin_len);
  299|  1.94k|		i = pin_len;
  300|  1.94k|	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  433|     94|#define SC_PIN_ENCODING_BCD	1
  ------------------
              	} else if (pin->encoding == SC_PIN_ENCODING_BCD || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  434|     16|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (300:13): [True: 31, False: 16]
  |  Branch (300:53): [True: 16, False: 0]
  ------------------
  301|     47|		if (pin_len > 2 * buflen)
  ------------------
  |  Branch (301:7): [True: 0, False: 47]
  ------------------
  302|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  303|    316|		for (i = j = 0; j < pin_len; j++) {
  ------------------
  |  Branch (303:19): [True: 284, False: 32]
  ------------------
  304|    284|			if (!isdigit(pin->data[j])) {
  ------------------
  |  Branch (304:8): [True: 15, False: 269]
  ------------------
  305|     15|				return SC_ERROR_INVALID_DATA;
  ------------------
  |  |   78|     15|#define SC_ERROR_INVALID_DATA			-1305
  ------------------
  306|     15|			}
  307|    269|			buf[i] <<= 4;
  308|    269|			buf[i] |= pin->data[j] & 0xf;
  309|    269|			if (j & 1)
  ------------------
  |  Branch (309:8): [True: 126, False: 143]
  ------------------
  310|    126|				i++;
  311|    269|		}
  312|     32|		if (j & 1) {
  ------------------
  |  Branch (312:7): [True: 14, False: 18]
  ------------------
  313|     14|			buf[i] <<= 4;
  314|     14|			buf[i] |= pin->pad_char & 0xf;
  315|     14|			i++;
  316|     14|		}
  317|     32|	}
  318|       |
  319|       |	/* Pad to maximum PIN length if requested */
  320|  1.97k|	if (pad || pin->encoding == SC_PIN_ENCODING_GLP) {
  ------------------
  |  |  434|    984|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (320:6): [True: 992, False: 984]
  |  Branch (320:13): [True: 0, False: 984]
  ------------------
  321|    992|		size_t pad_length = pin->pad_length;
  322|    992|		u8     pad_char   = pin->encoding == SC_PIN_ENCODING_GLP ? 0xFF : pin->pad_char;
  ------------------
  |  |  434|    992|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (322:23): [True: 16, False: 976]
  ------------------
  323|       |
  324|    992|		if (pin->encoding == SC_PIN_ENCODING_BCD)
  ------------------
  |  |  433|    992|#define SC_PIN_ENCODING_BCD	1
  ------------------
  |  Branch (324:7): [True: 16, False: 976]
  ------------------
  325|     16|			pad_length >>= 1;
  326|    992|		if (pin->encoding == SC_PIN_ENCODING_GLP)
  ------------------
  |  |  434|    992|#define SC_PIN_ENCODING_GLP	2 /* Global Platform - Card Specification v2.0.1 */
  ------------------
  |  Branch (326:7): [True: 16, False: 976]
  ------------------
  327|     16|			pad_length = 8;
  328|       |
  329|    992|		if (pad_length > buflen)
  ------------------
  |  Branch (329:7): [True: 0, False: 992]
  ------------------
  330|      0|			return SC_ERROR_BUFFER_TOO_SMALL;
  ------------------
  |  |   76|      0|#define SC_ERROR_BUFFER_TOO_SMALL		-1303
  ------------------
  331|       |
  332|    992|		if (pad_length && i < pad_length) {
  ------------------
  |  Branch (332:7): [True: 890, False: 102]
  |  Branch (332:21): [True: 381, False: 509]
  ------------------
  333|    381|			memset(buf + i, pad_char, pad_length - i);
  334|    381|			i = pad_length;
  335|    381|		}
  336|    992|	}
  337|       |
  338|  1.97k|	return (int)i;
  339|  1.97k|}

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

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

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

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

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

LLVMFuzzerTestOneInput:
   31|  15.3k|{
   32|  15.3k|    struct sc_context *ctx = NULL;
   33|  15.3k|    struct sc_card *card = NULL;
   34|  15.3k|    struct sc_pkcs15_card *p15card = NULL;
   35|  15.3k|    struct sc_reader *reader = NULL;
   36|  15.3k|    struct sc_pkcs15_object *obj;
   37|       |
   38|  15.3k|    sc_establish_context(&ctx, "fuzz");
   39|  15.3k|    if (!ctx)
  ------------------
  |  Branch (39:9): [True: 0, False: 15.3k]
  ------------------
   40|      0|        return 0;
   41|       |
   42|  15.3k|    if (fuzz_connect_card(ctx, &card, &reader, Data, Size) != SC_SUCCESS)
  ------------------
  |  |   28|  15.3k|#define SC_SUCCESS				0
  ------------------
  |  Branch (42:9): [True: 2.79k, False: 12.5k]
  ------------------
   43|  2.79k|        goto err;
   44|       |
   45|  12.5k|    if (SC_SUCCESS == sc_pkcs15_bind(card, NULL, &p15card)
  ------------------
  |  |   28|  12.5k|#define SC_SUCCESS				0
  ------------------
  |  Branch (45:9): [True: 5.43k, False: 7.11k]
  ------------------
   46|  5.43k|        && p15card) {
  ------------------
  |  Branch (46:12): [True: 5.43k, False: 0]
  ------------------
   47|  5.43k|        const uint8_t *in, *param;
   48|  5.43k|        uint16_t in_len, param_len;
   49|  5.43k|        fuzz_get_chunk(reader, &in, &in_len);
   50|  5.43k|        fuzz_get_chunk(reader, &param, &param_len);
   51|  37.5k|        for (obj = p15card->obj_list; obj != NULL; obj = obj->next) {
  ------------------
  |  Branch (51:39): [True: 32.1k, False: 5.43k]
  ------------------
   52|  32.1k|            u8 buf[0xFFFF];
   53|  32.1k|            size_t i;
   54|       |
   55|  32.1k|            int decipher_flags[] = {SC_ALGORITHM_RSA_RAW,
  ------------------
  |  |  111|  32.1k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   56|  32.1k|                SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_02, SC_ALGORITHM_RSA_PAD_ANSI,
  ------------------
  |  |  119|  32.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,
  ------------------
  |  |  114|  32.1k|#define SC_ALGORITHM_RSA_PAD_ANSI	0x00000004
  ------------------
   57|  32.1k|                SC_ALGORITHM_RSA_PAD_ISO9796};
  ------------------
  |  |  115|  32.1k|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
   58|   160k|            for (i = 0; i < sizeof decipher_flags/sizeof *decipher_flags; i++) {
  ------------------
  |  Branch (58:25): [True: 128k, False: 32.1k]
  ------------------
   59|   128k|                sc_pkcs15_decipher(p15card, obj, decipher_flags[i],
   60|   128k|                        in, in_len, buf, sizeof buf, NULL);
   61|   128k|            }
   62|       |
   63|  32.1k|            i = sizeof buf;
   64|  32.1k|            sc_pkcs15_derive(p15card, obj, 0,
   65|  32.1k|                    in, in_len, buf, &i);
   66|       |
   67|  32.1k|            int wrap_flags[] = {0, SC_ALGORITHM_AES_ECB, SC_ALGORITHM_AES_CBC_PAD,
  ------------------
  |  |  215|  32.1k|#define SC_ALGORITHM_AES_ECB		 0x01000000
  ------------------
                          int wrap_flags[] = {0, SC_ALGORITHM_AES_ECB, SC_ALGORITHM_AES_CBC_PAD,
  ------------------
  |  |  217|  32.1k|#define SC_ALGORITHM_AES_CBC_PAD	 0x04000000
  ------------------
   68|  32.1k|                SC_ALGORITHM_AES_CBC};
  ------------------
  |  |  216|  32.1k|#define SC_ALGORITHM_AES_CBC		 0x02000000
  ------------------
   69|   160k|            for (i = 0; i < sizeof wrap_flags/sizeof *wrap_flags; i++) {
  ------------------
  |  Branch (69:25): [True: 128k, False: 32.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|   128k|                size_t l = sizeof buf;
   74|   128k|                struct sc_pkcs15_object target_key;
   75|   128k|                struct sc_pkcs15_skey_info skey_info;
   76|   128k|                uint16_t len;
   77|   128k|                memset(&target_key, 0, sizeof target_key);
   78|   128k|                memset(&skey_info, 0, sizeof skey_info);
   79|   128k|                target_key.type = SC_PKCS15_TYPE_SKEY;
  ------------------
  |  |  432|   128k|#define SC_PKCS15_TYPE_SKEY			0x300
  ------------------
   80|   128k|                target_key.flags = 2; /* TODO not sure what these mean */
   81|   128k|                target_key.session_object = 1;
   82|   128k|                target_key.data = &skey_info;
   83|   128k|                skey_info.usage = SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_WRAP
  ------------------
  |  |  310|   128k|#define SC_PKCS15_PRKEY_USAGE_UNWRAP		0x20
  ------------------
                              skey_info.usage = SC_PKCS15_PRKEY_USAGE_UNWRAP | SC_PKCS15_PRKEY_USAGE_WRAP
  ------------------
  |  |  309|   128k|#define SC_PKCS15_PRKEY_USAGE_WRAP		0x10
  ------------------
   84|   128k|                    | SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  305|   128k|#define SC_PKCS15_PRKEY_USAGE_ENCRYPT		0x01
  ------------------
                                  | SC_PKCS15_PRKEY_USAGE_ENCRYPT | SC_PKCS15_PRKEY_USAGE_DECRYPT;
  ------------------
  |  |  306|   128k|#define SC_PKCS15_PRKEY_USAGE_DECRYPT		0x02
  ------------------
   85|   128k|                skey_info.native = 0; /* card can not use this */
   86|   128k|                skey_info.access_flags = 0; /* looks like not needed */
   87|   128k|                skey_info.key_type = 0x1fUL; /* CKK_AES */
   88|   128k|                skey_info.value_len = 128;
   89|   128k|                fuzz_get_chunk(reader, (const u8 **) &skey_info.data.value, &len);
   90|   128k|                skey_info.data.len = len;
   91|       |
   92|   128k|                sc_pkcs15_unwrap(p15card, obj, &target_key, wrap_flags[i],
   93|   128k|                        in, in_len, param, param_len);
   94|   128k|                sc_pkcs15_wrap(p15card, obj, &target_key, wrap_flags[i],
   95|   128k|                        buf, &l, in, in_len);
   96|   128k|            }
   97|       |
   98|  32.1k|            int signature_flags[] = {SC_ALGORITHM_RSA_RAW,
  ------------------
  |  |  111|  32.1k|#define SC_ALGORITHM_RSA_RAW		0x00000001
  ------------------
   99|  32.1k|                SC_ALGORITHM_RSA_PAD_PKCS1_TYPE_01, SC_ALGORITHM_RSA_PAD_ANSI,
  ------------------
  |  |  118|  32.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,
  ------------------
  |  |  114|  32.1k|#define SC_ALGORITHM_RSA_PAD_ANSI	0x00000004
  ------------------
  100|  32.1k|                SC_ALGORITHM_RSA_PAD_ISO9796,
  ------------------
  |  |  115|  32.1k|#define SC_ALGORITHM_RSA_PAD_ISO9796	0x00000008
  ------------------
  101|  32.1k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA1,
  ------------------
  |  |  116|  32.1k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA1,
  ------------------
  |  |  154|  32.1k|#define SC_ALGORITHM_MGF1_SHA1		0x00100000
  ------------------
  102|  32.1k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA256,
  ------------------
  |  |  116|  32.1k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA256,
  ------------------
  |  |  155|  32.1k|#define SC_ALGORITHM_MGF1_SHA256	0x00200000
  ------------------
  103|  32.1k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA384,
  ------------------
  |  |  116|  32.1k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA384,
  ------------------
  |  |  156|  32.1k|#define SC_ALGORITHM_MGF1_SHA384	0x00400000
  ------------------
  104|  32.1k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA512,
  ------------------
  |  |  116|  32.1k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA512,
  ------------------
  |  |  157|  32.1k|#define SC_ALGORITHM_MGF1_SHA512	0x00800000
  ------------------
  105|  32.1k|                SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA224,
  ------------------
  |  |  116|  32.1k|#define SC_ALGORITHM_RSA_PAD_PSS	0x00000010 /* PKCS#1 v2.0 PSS */
  ------------------
                              SC_ALGORITHM_RSA_PAD_PSS|SC_ALGORITHM_MGF1_SHA224,
  ------------------
  |  |  158|  32.1k|#define SC_ALGORITHM_MGF1_SHA224	0x01000000
  ------------------
  106|  32.1k|                SC_ALGORITHM_ECDSA_RAW, SC_ALGORITHM_ECDSA_HASH_SHA1,
  ------------------
  |  |  183|  32.1k|#define SC_ALGORITHM_ECDSA_RAW		0x00100000
  ------------------
                              SC_ALGORITHM_ECDSA_RAW, SC_ALGORITHM_ECDSA_HASH_SHA1,
  ------------------
  |  |  185|  32.1k|#define SC_ALGORITHM_ECDSA_HASH_SHA1		SC_ALGORITHM_RSA_HASH_SHA1
  |  |  ------------------
  |  |  |  |  143|  32.1k|#define SC_ALGORITHM_RSA_HASH_SHA1	0x00000200
  |  |  ------------------
  ------------------
  107|  32.1k|                SC_ALGORITHM_ECDSA_HASH_SHA224, SC_ALGORITHM_ECDSA_HASH_SHA256,
  ------------------
  |  |  186|  32.1k|#define SC_ALGORITHM_ECDSA_HASH_SHA224		SC_ALGORITHM_RSA_HASH_SHA224
  |  |  ------------------
  |  |  |  |  150|  32.1k|#define SC_ALGORITHM_RSA_HASH_SHA224	0x00010000
  |  |  ------------------
  ------------------
                              SC_ALGORITHM_ECDSA_HASH_SHA224, SC_ALGORITHM_ECDSA_HASH_SHA256,
  ------------------
  |  |  187|  32.1k|#define SC_ALGORITHM_ECDSA_HASH_SHA256		SC_ALGORITHM_RSA_HASH_SHA256
  |  |  ------------------
  |  |  |  |  147|  32.1k|#define SC_ALGORITHM_RSA_HASH_SHA256	0x00002000
  |  |  ------------------
  ------------------
  108|  32.1k|                SC_ALGORITHM_ECDSA_HASH_SHA384, SC_ALGORITHM_ECDSA_HASH_SHA512,
  ------------------
  |  |  188|  32.1k|#define SC_ALGORITHM_ECDSA_HASH_SHA384		SC_ALGORITHM_RSA_HASH_SHA384
  |  |  ------------------
  |  |  |  |  148|  32.1k|#define SC_ALGORITHM_RSA_HASH_SHA384	0x00004000
  |  |  ------------------
  ------------------
                              SC_ALGORITHM_ECDSA_HASH_SHA384, SC_ALGORITHM_ECDSA_HASH_SHA512,
  ------------------
  |  |  189|  32.1k|#define SC_ALGORITHM_ECDSA_HASH_SHA512		SC_ALGORITHM_RSA_HASH_SHA512
  |  |  ------------------
  |  |  |  |  149|  32.1k|#define SC_ALGORITHM_RSA_HASH_SHA512	0x00008000
  |  |  ------------------
  ------------------
  109|  32.1k|                SC_ALGORITHM_GOSTR3410_RAW, SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411,
  ------------------
  |  |  165|  32.1k|#define SC_ALGORITHM_GOSTR3410_RAW		0x00020000
  ------------------
                              SC_ALGORITHM_GOSTR3410_RAW, SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411,
  ------------------
  |  |  167|  32.1k|#define SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411	0x00080000
  ------------------
  110|  32.1k|                SC_ALGORITHM_GOSTR3410_HASHES,
  ------------------
  |  |  168|  32.1k|#define SC_ALGORITHM_GOSTR3410_HASHES		0x000A0000
  ------------------
  111|  32.1k|            };
  112|   610k|            for (i = 0; i < sizeof signature_flags/sizeof *signature_flags; i++) {
  ------------------
  |  Branch (112:25): [True: 578k, False: 32.1k]
  ------------------
  113|   578k|                sc_pkcs15_compute_signature(p15card, obj, signature_flags[i],
  114|   578k|                        in, in_len, buf, sizeof buf, NULL);
  115|   578k|            }
  116|       |
  117|  32.1k|            if (obj->type == SC_PKCS15_TYPE_AUTH_PIN) {
  ------------------
  |  |  445|  32.1k|#define SC_PKCS15_TYPE_AUTH_PIN			0x601
  ------------------
  |  Branch (117:17): [True: 6.14k, False: 25.9k]
  ------------------
  118|  6.14k|                sc_pkcs15_verify_pin(p15card, obj, in, in_len);
  119|  6.14k|                sc_pkcs15_change_pin(p15card, obj, in, in_len, param, param_len);
  120|  6.14k|                sc_pkcs15_unblock_pin(p15card, obj, in, in_len, param, param_len);
  121|  6.14k|                sc_pkcs15_get_pin_info(p15card, obj);
  122|  6.14k|            }
  123|  32.1k|        }
  124|  5.43k|        sc_pkcs15_card_free(p15card);
  125|  5.43k|    }
  126|       |
  127|  15.3k|err:
  128|  15.3k|    sc_disconnect_card(card);
  129|  15.3k|    sc_release_context(ctx);
  130|       |
  131|  15.3k|    return 0;
  132|  12.5k|}

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

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

